listdrive
A google drive listing tool
Features:
- Authentication to google api using Oauth2 or service account
- List shared drive
- List file in a google drive folder
- List recursively a google drive folder
- Use advanced filter and query to list google drive folder
- Download files from a google drive folder and export native google drive files to pdf (default)
- Download tool can upload directly the files on a S3 bucket.
Installation
npm i -g @novadiscovery/listdrive
npx @novadiscovery/listdrive --help
The download to s3 feature use classic environnement permission for aws (instance profile, local credential, environnement variable, etc.)
The read and download feature on google drive require a configuration file at a standard location (eg. .listdriverc
or ~/.config/listdrive/config
). See rc file documentation for more details.
Here a sample file (json with comment):
{
google: {
"clientId": "xxx",
"clientSecret": "xxx",
"tokens": {
},
"service_account": {
}
}
}
Usage
listdrive [command]
Commands:
listdrive auth Run authentication process
listdrive list <folderId> List files in a folder
listdrive shared-drives List shared drives
listdrive download <folderId> Download has PDF files in a folder
Options:
--help Show help [boolean]
--version Show version number [boolean]
--dry [boolean]
--recursive, -R [boolean] [default: false]
--match Filter with minimatch pattern [string]
--query Append to file list query (see google drive api
https://developers.google.com/drive/api/v3/search-files)
[string]
--force-query Force the search query (you will have to ensure folder
matching and filtering) [string]
~/Git/nopnop/listdrive(branch:master*) »
listdrive auth
Run authentication process (to use the Oauth strategy):
listdrive auth
Please, visite this url and update config: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.readonly&response_type=code&client_id=xxx
✔ Provide code: … xxxxxxxxxxx
{
access_token: 'xxxxx',
refresh_token: 'xxxxx',
scope: 'https://www.googleapis.com/auth/drive.readonly',
token_type: 'Bearer',
expiry_date: 0
}
listdrive list
listdrive list <folder_id>
listdrive list <folder_id> --drive <shared_drive_id>
listdrive list <folder_id> --recursive
listdrive list <folder_id> --drive <shared_drive_id> --recursive --indent | jq -r '.name'
listdrive list <folder_id> --drive <shared_drive_id> | spreadstream --json --id <spreadsheet_id> --sheet index --replace
listdrive list <folder_id> --drive <folder_id> --match 'Welco*'
listdrive list <folder_id> --query "fullText contains 'hello'"
listdrive list <folder_id_but_not_used> --force-query "trashed = true and folder in xxxx and ..."
listdrive download
Download and export files
listdrive download <folder_id> --output data
listdrive download <folder_id> --output data --match "JOB*" --query "mimeType = application/pdf"
listdrive download <folder_id> --output s3://nova-sandbox-bucket/test/foo/bar
listdrive download <folder_id> --output data --force
listdrive download <folder_id> --output data --name-it '@novadiscovery/listdrive/src/name-it-mtime-slugify'
listdrive shared-drives
List shared drive:
listdrive shared-drives
{"kind":"drive#drive","id":"xxxx","name":"Open Share"}
{"kind":"drive#drive","id":"yyyy","name":"Another shared drive"}