• Stars
    star
    388
  • Rank 107,208 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is a CLI tool to download shared files and folders from Google Drive.

goodls

MIT License

Overview

This is a CLI tool to download shared files and folders from Google Drive. For large file, the resumable download can be also run.

Methods

1. Download shared files from the shared URL without the authorization.

We have already known that the shared files on Google Drive can be downloaded without the authorization. But when the size of file becomes large (about 40MB), it requires a little ingenuity to download the file. It requires to access 2 times to Google Drive. At 1st access, it retrieves a cookie and a code for downloading. At 2nd access, the file is downloaded using the cookie and code. I created this process as a CLI tool.

2. Download all shared files with the folder structure from the shared folder.

This method uses API key.

There are sometimes the situation for downloading files in a shared folder. But I couldn't find the CLI applications for downloading files in the shared folder. So I implemented this. But when in order to retrieve the file list from the shared file, Drive API is required to be used. In order to use Drive API, it is required to use OAuth2, Service account and API key. So I selected to use API key which is the simplest way. This CLI tool can retrieve the file list in the shared folder using API key and download all files in the shared folder. From version 1.2.2, you can retrieve only files with the specific mimeType from the folder.

3. Run resumable download for large files.

This method uses API key.

At a recent proposal, I knew the requirement of the resumable download of shared file. So I implemented this.

How to Install

Download an executable file of goodls from the release page and import to a directory with path.

or

Use go get.

$ go install github.com/tanaikech/goodls@latest
  • GO111MODULE=on

Usage

1. Download shared files

The image used for this demonstration was created by k3-studio

You can use this just after you download or install goodls. You are not required to do like OAuth2 process.

$ goodls -u [URL of shared file on Google Drive]
  • Help
    • $ goodls --help
  • Options
    • -e
      • Extension of output file. This is for only Google Docs (Spreadsheet, Document, Presentation). Default is pdf. When ms is used, the shared Google Docs can be downloaded as Microsoft Docs.
      • Sample :
        • $ goodls -u https://docs.google.com/document/d/#####/edit?usp=sharing -e txt
    • -f
      • Filename of file which is output. When this was not used, the original filename on Google Drive is used.
      • Sample :
        • $ goodls -u https://docs.google.com/document/d/#####/edit?usp=sharing -e txt -f sample.txt
  • URL is like below.
    • In the case of Google Docs (Spreadsheet, Document, Slides)
      • https://docs.google.com/spreadsheets/d/#####/edit?usp=sharing
      • https://docs.google.com/document/d/#####/edit?usp=sharing
      • https://docs.google.com/presentation/d/#####/edit?usp=sharing
    • In the case of except for Google Docs
      • https://drive.google.com/file/d/#####/view?usp=sharing
    • In the case of webContentLink
      • https://drive.google.com/uc?export=download&id=###

File with several URLs

If you have a file including URLs, you can input the URL data using standard input and pipe as follows. If wrong URL is included, the URL is skipped.

$ cat sample.txt | goodls

or

$ goodls < sample.txt

sample.txt

https://docs.google.com/spreadsheets/d/#####/edit?usp=sharing
https://docs.google.com/document/d/#####/edit?usp=sharing
https://docs.google.com/presentation/d/#####/edit?usp=sharing

When you download shared files from Google Drive, please confirm whether the files are shared.

2. Download all files from shared folder

When above structure is downloaded, the command is like below. At that time, the folder ID is the folder ID of "sampleFolder1".

Files are downloaded from the shared folder. In this demonstration, the fake folder ID and API key are used.

Retrieve API key

In order to use this, please retrieve API key as the following flow.

  1. Login to Google.

  2. Access to https://console.cloud.google.com/?hl=en.

  3. Click select project at the right side of "Google Cloud Platform" of upper left of window.

    • If you cannot see the project, please try to access to https://console.cloud.google.com/cloud-resource-manager?hl=en. You can also create new project at there. - When you created new project there, please click the left of "Google Cloud Platform". You can see it like 3 horizontal lines. By this, a side bar is opened. At there, please select "API & Services" -> "Library". After this, please check the following flow from Click "Library" at left side..
  4. Click "NEW PROJECT"

    1. Input "Project Name".
    2. Click "CREATE".
    3. Open the created project.
    4. Click "Enable APIs and get credentials like keys".
    5. Click "Library" at left side.
    6. Input "Drive API" in "Search for APIs & Services".
    7. Click "Google Drive API".
    8. Click "ENABLE".
    9. Back to https://console.cloud.google.com/?hl=en.
    10. Click "Enable APIs and get credentials like keys".
    11. Click "Credentials" at left side.
    12. Click "Create credentials" and select API key.
    13. Copy the API key. You can use this API key.
Registering API key to environment variable
  • When API key is registered to the environment variable. When GOODLS_APIKEY as the environment variable is set API key, goodls uses API key from the environment variable.
  • If API key is used with the option at the command line, the priority of option is higher than the environment variable.

For example, in the case of bash, please add a following code to .bashrc.

export GOODLS_APIKEY=### your API key ###

Download

When the URL of shared folder is https://drive.google.com/drive/folders/#####?usp=sharing, you can download all files in the folder by the following command.

$ goodls -u https://drive.google.com/drive/folders/#####?usp=sharing -key [APIkey]
  • Project files cannot be downloaded by API key. If you want to download the project files, you can download them by ggsrun, because ggsrun uses OAuth2.
  • This new function uses the Go library of go-getfilelist.
  • When the option of --NoProgres, -np is used, the progress information is not seen. This is a silent mode.
  • If the files which are tried to be downloaded are existing, an error occurs. But when you use the option --overwrite and --skip, the files are overwritten and skipped, respectively.
  • If you use the option -m, you can retrieve only files with the specific mimeType from the folder. For example, when you want to download PDF and PNG files, please run like below.
    • $ goodls -u [URL] -key [APIkey] -m "application/pdf,image/png"

Retrieve information of file and folder

When you want to retrieve the information of file and folder, you can do it as follows.

For file

$ goodls -u https://docs.google.com/spreadsheets/d/#####/edit?usp=sharing -key [APIkey] -i

For folder

$ goodls -u https://drive.google.com/drive/folders/#####?usp=sharing -key [APIkey] -i

3. Resumable download of shared file

When you use this option, at first, please retrieve API key. About how to retrieve API key, you can see at here.

When you want to download 100 MBytes of the shared file, you can use the following command.

$ goodls -u [URL of shared file on Google Drive] -key [APIkey] -r 100m
  • Please use the option -r. In this sample, 100m means to download 100 MBytes of the shared file.
    • If you want to download 1 GB, please use -r 1g.
    • If you use -r 1000000, 1 MByte of the file will be able to be downloaded.

You can see the actual running of this option at the following demonstration movie.

In this demonstration, the following command is run 3 times.

$ goodls -u https://drive.google.com/drive/folders/abcdefg?usp=sharing -key htjklmn -r 80m
  • At 1st run, the data of 0 - 80 MBytes is downloaded.
    • You can see New download at "Current status".
  • At 2nd run, the data of 80 - last is downloaded.
    • You can see Resumable download at "Current status".
  • At 3rd run, the download has already been done. So the checksum is shown.
    • You can see Download has already done. at "Current status".

Note

  • Reason that API key is used for this.
    • When it accesses to the shared file without the authorization, the file size and md5checksum cannot be retrieved. So in order to use Drive API, I adopted to use API key.
  • Reason that the download size is inputted every time.
    • When this option is run 1 time, 1 quota is used for Drive API. So I adopted this way.

Q&A

  • I want to download shared projects from user's Google Drive.

    • You can download shared projects using ggsrun.
    • ggsrun can also download shared files from other user's Google Drive using Drive API which needs the access token.
  • I want to download all files including the standalone projects from the shared folder and own folder.

    • You can achieve it using ggsrun.
  • I want to use this with "Dockerfile build".

    • In this case, it has already been mentioned by rahulpowar at #15. Please check it.

Licence

MIT

Author

Tanaike

If you have any questions and commissions for me, feel free to tell me.

Update History

  • v1.0.0 (January 10, 2018)

    1. Initial release.
  • v1.0.1 (January 11, 2018)

    1. In order to download several files, a datafile including URLs using Standard Input and Pipe have gotten to be able to be inputted.
  • v1.0.2 (May 10, 2018)

    1. Files with large size has gotten to be able to be used.
      • In order to download files with large size (several gigabytes), files are saved by chunks.
  • v1.0.3 (September 4, 2018)

    1. When the files are downloaded, the progress of downloading got to be able to be displayed.
      • This demonstration can be seen at Demo.
      • If the new option of --np is used, the progress is not displayed.
  • v1.1.0 (November 4, 2018)

    1. By using API key, files from the shared folder got to be able to be downloaded while keeping the folder structure.
      • This demonstration can be seen at Demo.
    2. By using API key, the information of shared file and folder can be also retrieved.
    3. About the option of --extension and -e, when -e ms is used, Google Docs (Document, Spreadsheet, Slides) are converted to Microsoft Docs (Word, Excel, Powerpoint), respectively.
  • v1.1.1 (November 13, 2018)

    	1. Version of [go-getfilelist](https://github.com/tanaikech/go-getfilelist) was updated. Because the structure of ``drive.File`` got to be able to be used, I also updated this application.
    

  • v1.2.0 (November 24, 2018)

    1. By using API key, the shared large files can be run the resumable download.
      • This demonstration can be seen at Demo.

  • v1.2.1 (November 25, 2018)

    1. API key got to be able to be used by an environment variable. When GOODLS_APIKEY as the environment variable is set API key, goodls uses API key from the environment variable.

  • v1.2.2 (December 12, 2018)

    1. When files are downloaded from a specific folder, it got to be able to select mimeType. By this, files with the specific mimeType in the specific folder can be retrieved. For this, I updated the go library go-getfilelist.
      • $ goodls -u [URL] -key [APIkey] -m "application/pdf,image/png"

  • v1.2.3 (October 31, 2019)

    1. An option for inputting the directory to save the downloaded files was added. When this option is not used, the files are saved to the current working directory.
      • $ goodls -u [URL] -d [directory]

  • v1.2.4 (January 3, 2020)

    1. It seems that the specification of github.com/urfave/cli was changed by the update of https://github.com/urfave/cli. By this, when go get -u github.com/tanaikech/goodls is run, an error occurred. So this error was removed.

  • v1.2.5 (January 29, 2020)

    1. An option for selecting whether the top directory is created was added.
      • $ goodls -u [URL] --notcreatetopdirectory or $ goodls -u [URL] -ntd
      • When this option is NOT used (default situation), when a folder including sub-folders is downloaded, the top folder which is downloaded is created as the top directory under the working directory. When this option is used, the top directory is not created and all files and sub-folders under the top folder are downloaded under the working directory.
      • This feature request was implemented.

  • v1.2.6 (February 23, 2020)

    1. When the files are downloaded from the shared folder, if an error occurs, the download was stopped. In this thread, a request for skipping this error was proposed. This request was implemented at v1.2.6. Please try the option of --skiperror like below.
      • $ goodls -u https://drive.google.com/drive/folders/###?usp=sharing --skiperror

  • v1.2.7 (August 21, 2020)

    1. As the URL for downloading the files, webContentLink was added. So from this version, the URL of https://drive.google.com/uc?export=download&id=### got to be able to be used. This is the request from this thread.

  • v1.2.8 (February 17, 2022)

    1. Recently, it seems that the specification the process for downloading the shared file on Google Drive has been changed. So I updated goodls for reflecting this. The usage of goodls is not changed.

  • v2.0.0 (February 25, 2022)

    1. By changing the specification of methods, drive.New() and transport.APIKey were deprecated. By this, I updated go-getfilelist. In this version, I used this updated library to goodls. And also, drive.NewService() is used instead of drive.New().

  • v2.0.1 (February 26, 2022)

    1. A bug for the resumable download was removed.

  • v2.0.2 (February 24, 2023)

    1. Modified go.mod and go.sum.
  • v2.0.3 (April 5, 2023)

    1. Forgot to update the version number and modified it. And, built the sources with the latest version. Ref

TOP

More Repositories

1

taking-advantage-of-google-apps-script

Here, CLI tools, libraries, Add-ons, Reports, Benchmarks and Sample Scripts for taking advantage of Google Apps Script which are publishing in my blog, Gists and GitHub are summarized.
272
star
2

taking-advantage-of-Web-Apps-with-google-apps-script

This is a report to take advantage of Web Apps with Google Apps Script (GAS).
201
star
3

ggsrun

This is a CLI tool to execute Google Apps Script (GAS) at own terminal on local PC. Also this CLI tool can be used for managing files in Google Drive for OAuth2 and Service Account.
Go
117
star
4

ImgApp

This is a library of image tools for Google Apps Script.
CoffeeScript
110
star
5

ResumableUploadForGoogleDrive_js

This is a Javascript library to achieve the resumable upload for Google Drive.
JavaScript
71
star
6

goris

This is a CLI tool to search for images with Google Reverse Image Search (goris).
Go
68
star
7

Google-Apps-Script-Library-Database

This is for the Google Apps Script Library Database and a web application for searching the libraries..
HTML
57
star
8

RunAll

This is a library for running the concurrent processing using only native Google Apps Script (GAS).
CoffeeScript
55
star
9

FilesApp

FilesApp is a GAS library for retrieving file and folder list in Google Drive using Google Apps Script (GAS). Also this can create a tree from all files and folders in Google Drive.
JavaScript
42
star
10

Resumable_Upload_For_WebApps

This is a sample script for uploading files with large size (> 50 MB) at Web Apps using Google Apps Script (GAS). The resumable upload method is used for uploading files. This script can be also applied to the script using gapi of javascript.
HTML
39
star
11

DownloadLargeFilesByUrl

DownloadLargeFilesByUrl is a GAS library for downloading large files from URL to Google Drive using Google Apps Script (GAS).
JavaScript
38
star
12

GPhotoApp

This is a GAS library for retrieving and creating the albums and media items using Google Photo API using Google Apps Script (GAS).
JavaScript
38
star
13

DocsServiceApp

This is a Google Apps Script library for supporting Document service, Docs API, Spreadsheet service, Sheets API, Slides service and Slides API. The aim of this library is to compensate the processes that they services cannot achieve.
JavaScript
36
star
14

FetchApp

This is a GAS library for creating and requesting the type of multipart/form-data using Google Apps Script. This library enhances Class UelFetchApp of Google Apps Script.
JavaScript
36
star
15

CopyFolder

This is Google Apps Script library for copying folder on Google Drive.
JavaScript
31
star
16

BatchRequest

This is a library for running Batch Requests using Google Apps Script (GAS).
JavaScript
29
star
17

RichTextApp

This is a GAS library for copying the rich text with the text styles from Google Document to Google Spreadsheet or from Google Spreadsheet to Google Document using Google Apps Script (GAS). And, also the rich texts in the cells can be converted to HTML format.
JavaScript
29
star
18

OnedriveApp

This is a library of Google Apps Script for using Microsoft OneDrive.
HTML
25
star
19

HtmlFormApp

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.
JavaScript
25
star
20

AsynchronousResumableUploadForGoogleDrive

This is a sample script for uploading multiple files with large size (> 50 MB) at the sidebar, dialog of Google Docs and Web Apps using the resumable upload of the asynchronous process with Javascript and Google Apps Script (GAS).
HTML
24
star
21

RangeListApp

RangeListApp is a GAS library for retrieving, putting and replacing values for Spreadsheet by a range list with a1Notation using Google Apps Script (GAS).
JavaScript
22
star
22

ManifestsApp

This is a Manifests library for Google Apps Scripts.
JavaScript
22
star
23

gdoctableapppy

This is a python library to manage the tables on Google Document using Google Docs API.
Python
21
star
24

ProjectApp2

This is a GAS project library for Google Apps Script (GAS). This library can be used for the projects of both standalone script type and container-bound script type.
JavaScript
18
star
25

getfilelistpy

This is a python library to retrieve the file list with the folder tree from the specific folder of Google Drive.
Python
18
star
26

go-getfilelist

This is a Golang library to retrieve the file list with the folder tree from the specific folder of Google Drive.
Go
16
star
27

FieldsBuilderForGoogleAPIs

FieldsBuilderForGoogleAPIs is a Web Application for building the fields value for using Google APIs. This is mainly used for developing the scripts for using Google APIs.
JavaScript
12
star
28

UnzipGs

This is a GAS library for unzipping a Zip file protected by a password using Google Apps Script.
JavaScript
12
star
29

GetEditType

GetEditType is a GAS library for retrieving the edit types of the OnEdit event trigger of Spreadsheet using Google Apps Script (GAS).
JavaScript
12
star
30

RearrangeScripts

This is a GAS application for rearranging Google Apps Scripts (GAS) in a project which can be seen at the script editor.
HTML
11
star
31

GetFileList_js

This is a Javascript library to retrieve the file list with the folder tree from the specific folder (publicly shared folders and own folders) of Google Drive.
JavaScript
10
star
32

Creating-PNG-Image-with-Alpha-Channel-using-Google-Apps-Script

This is a sample script for creating a PNG image with the alpha channel using Google Apps Script.
10
star
33

Enhanced-Custom-Function-for-Google-Spreadsheet-using-Web-Apps-as-Wrapper

This is a proposal of the enhanced custom function for Google Spreadsheet using Web Apps as the wrapper.
JavaScript
10
star
34

syncGoogleScriptRun

This is a Javascript library to use "google.script.run" with the synchronous process.
JavaScript
10
star
35

ZipFolder

This is a library for zipping a folder using Google Apps Scripts.
JavaScript
10
star
36

tanaikech.github.io

Blog (my memorandums)
HTML
9
star
37

GmailToList

This is a library for exporting all messages of Gmail as a list using Google Apps Script (GAS).
JavaScript
9
star
38

SOUWA_GAS

GAS library for summing string elements in an array at the high speed
JavaScript
9
star
39

OwnershipTransfer

This is a Google Apps Script library for achieving the ownership-transfer of the specific folder including the files and sub-folders using Drive API.
JavaScript
9
star
40

ProcessApp

This is a library for retrieving the process and information of Google Apps Script. For example, one of methods retrieves the total execution time of all functions executed by the time-driven trigger at owner's account.
JavaScript
9
star
41

One_Time_Download_for_Google_Drive

This is a sample script for downloading files from Google Drive by the one time download method.
JavaScript
8
star
42

DateFinder

DateFinder is a GAS library for searching the date objects from the cell range on the sheet in the Spreadsheet and retrieving the searched range as the RangeList object using Google Apps Script (GAS).
JavaScript
8
star
43

Linking-Google-Cloud-Platform-Project-to-Google-Apps-Script-Project-for-New-IDE

This is the document for linking Google Cloud Platform Project to Google Apps Script Project for New IDE. And also, several sample scripts using Google Apps Script API and Google Photos API are introduced.
8
star
44

node-getfilelist

This is a Node.js module to retrieve the file list with the folder tree from the specific folder of Google Drive.
JavaScript
7
star
45

ShapeApp

This is an add-on application for manipulating shapes on Google Slide. It can create and update shapes by inputting parameters, and can arrange shapes. This is made of Google Apps Scripts (GAS).
HTML
7
star
46

DocNamedRangeApp

This is a Google Apps Script library for managing the named range on Google Documents.
JavaScript
7
star
47

FileTransfer

How to transfer files for Google Drive without authorization.
JavaScript
7
star
48

Managing-A-Lot-Of-Google-Calendar-Events-using-Batch-Requests-with-Google-Apps-Script

These are the sample scripts for managing a lot of Google Calendar Events using the batch requests with Google Apps Script.
JavaScript
7
star
49

Safe-Uploading-for-Google-Drive-by-HTML-in-External-Server-using-Google-Apps-Script

This is a report for safe-uploading files to Google Drive by HTML put in the external server using Google Apps Script.
JavaScript
7
star
50

HtmlFormObjectParserForGoogleAppsScript_js

This is a Javascript library for sending the HTML form object to Google Apps Script using google.script.run.
JavaScript
7
star
51

Batch-Requests-for-Drive-API-using-Google-Apps-Script

These are the sample scripts of the batch requests for Drive API using Google Apps Script.
JavaScript
7
star
52

go-gdoctableapp

This is a Golang library for managing tables on Google Document using Google Docs API.
Go
6
star
53

File_Picker_using_Google_Apps_Script_and_Javascript_without_3rd_party

This is a sample script for the file picker using Google Apps Script and Javascript without 3rd party.
JavaScript
6
star
54

ProjectApp

This is a project library for Google Apps Script (GAS).
JavaScript
6
star
55

GASProjectApp

This is a Google Apps Script library for creating, updating and exporting Google Apps Script project of the standalone type using Drive API. In this case, Apps Script API is not used.
JavaScript
6
star
56

PDFApp

This is a Google Apps Script library for managing PDFs.
JavaScript
5
star
57

SimplePhotoGalleryUsingGoogleAppsScript

This is a sample script for achieving a simple photo gallery created by Google Slides and Web Apps using Google Apps Script.
HTML
5
star
58

FileUploadBydoPost_GAS

GAS and HTML for file Upload From HTML Form on local PC Using doPost()
HTML
5
star
59

getSpreadsheetByRange

This is a simple way for retrieving Spreadsheet ID from a range. As an application, we introduce the enhanced copyTo() which can copy from a range to other Spreadsheet.
5
star
60

GetAccessTokenFromServiceAccount_js

This is a Javascript library to retrieve the access token from the Google Service Account.
JavaScript
4
star
61

UtlApp

This is a Google Apps Script library including useful scripts for supporting to development of applications by Google Apps Script.
JavaScript
4
star
62

getcode

This is a Golang library to automatically get an authorization code for retrieving access token using OAuth2.
Go
4
star
63

RichTextAssistant

This is a GAS library for supporting editing RichText in Google Spreadsheet using Google Apps Script.
JavaScript
3
star
64

CropImageByBorder_js

This is a Javascript library for cropping images by the border.
JavaScript
3
star
65

tarUnarchiver-for-Google-Apps-Script

This is a script for extracting files from a tar file using Google Apps Script. This script was created by native Google Apps Script.
JavaScript
3
star
66

ArrangeStackingOrder

ArrangeStackingOrder is a GAS library for arranging the stacking order of page elements on Google Slides using Google Apps Script (GAS).
JavaScript
3
star
67

CreateImg

This Google Apps Script (GAS) library creates an image file from coordinate data.
JavaScript
2
star
68

gislacks

This is a plugin of Sublime Text 3 for submitting files to both Gist and Slack.
Python
2
star
69

Notifying-Comments-at-Stackoverflow-by-Email

This is a script for sending an email when users got comments at Stackoverflow.
JavaScript
2
star
70

BatchRequest_js

This is a library for running Batch Requests for Google APIs using Javascript.
JavaScript
2
star
71

go-gettokenbyserviceaccount

This is a Golang library to retrieve access token from Service Account of Google without using Google's OAuth2 package.
Go
2
star
72

node-gdoctableapp

This is a Node.js module to manage the tables on Google Document using Google Docs API.
JavaScript
2
star
73

node-gbatchrequests

This is a Node.js module to run the batch requests of Google APIs.
JavaScript
2
star
74

GistChecker

This is a GAS library for notifying the change of number of comments, stars and forks of own Gists as an email using Google Apps Script.
JavaScript
2
star
75

image-storage

HTML
2
star
76

gogauth

This is a CLI tool to easily retrieve access token for using APIs on Google.
Go
2
star
77

ConvertNFDtoNFC

This is a script for converting strings from NFD (Normalization Form Decomposition) to NFC (Normalization Form Composition) using Google Apps Script.
JavaScript
2
star
78

souwapy

Python library for summing string elements in an array at the high speed
Python
1
star
79

cui4netatmo

DOS batch file and UNIX shell script and one liner curl code for retrieving data from Netatmo
Batchfile
1
star
80

go-rearrange

This is a Golang library to interactively rearrange a text data on a terminal.
Go
1
star
81

gislack

This is a CLI tool to submit files to both Gist and Slack.
Go
1
star
82

gorearrange

This is a CLI tool to interactively rearrange a text data on a terminal.
Go
1
star
83

gonetatmo

This is a CLI tool to retrieve data from a personal weather station of Netatmo.
Go
1
star
84

Processing-Various-Types-of-Invoices-using-Gemini-1.5-API-with-Google-Apps-Script

This repository is for Parsing Invoices using Gemini 1.5 API with Google Apps Script.
JavaScript
1
star
85

TemplateApp

This is a Google Apps Script library for easily managing the template of Google Documents and Google Slides using Google Spreadsheet as a database using Google Apps Script.
JavaScript
1
star