diff --git a/README.md b/README.md index 98bcad3..35a2de2 100644 --- a/README.md +++ b/README.md @@ -409,4 +409,10 @@ If you have any questions and commissions for me, feel free to tell me. In this version, the URL obtained by this click is created, and the created URL is used for downloading it. +<a name="v205"></a> + +- v2.0.5 (March 10, 2023) + + 1. From this version, when the API key is used, the large file is downloaded by the API key. Because the specification for downloading the shared large file is sometimes changed. When the API key is not used, the shared large file is downloaded by the current specification (v2.0.4). If the shared large file cannot be downloaded by the change of the specification on Google's side, please use the API key and test it again. The usage of goodls has not changed. + [TOP](#top) diff --git a/getfilesfromfolder.go b/getfilesfromfolder.go index 9066a57..b62c4a6 100644 --- a/getfilesfromfolder.go +++ b/getfilesfromfolder.go @@ -6,7 +6,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -47,6 +47,7 @@ func (p *para) downloadFileByAPIKey(file *drive.File) error { q.Set("mimeType", file.WebViewLink) } else { q.Set("alt", "media") + q.Set("supportsAllDrives", "true") } u.RawQuery = q.Encode() bkWorkDir := p.WorkDir @@ -72,7 +73,7 @@ func (p *para) downloadFileByAPIKey(file *drive.File) error { return err } if res.StatusCode != 200 { - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) if err != nil { return err } @@ -271,7 +272,7 @@ func (p *para) dupChkFoldersFiles(fileList *getfilelist.FileListDl) { } } -// getFilesFromFolder: This method is the main method for downloading all files in a shread folder. +// getFilesFromFolder: This method is the main method for downloading all files in a shared folder. func (p *para) getFilesFromFolder() error { srv, err := drive.NewService(context.Background(), option.WithAPIKey(p.APIKey)) if err != nil { diff --git a/goodls.go b/goodls.go index 3dfc221..54ea79c 100644 --- a/goodls.go +++ b/goodls.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "log" "mime" "net/http" "net/http/cookiejar" @@ -74,7 +73,6 @@ func (p *para) getURLFromHTML(html *http.Response) error { form := doc.Find("form[id='download-form']") url, b := form.Attr("action") if b == false { - log.Print("Specification of the endpoint for downloading the file might have been changed.") return fmt.Errorf("Specification of the endpoint for downloading the file might have been changed.") } req, err := http.NewRequest("GET", url, nil) @@ -240,6 +238,18 @@ func (p *para) checkURL(s string) error { p.URL = docutl + p.Kind + "/d/" + p.ID + "/export?format=" + p.Ext } } + + if p.APIKey != "" && p.Kind == "file" { + fmt.Println("Now downloading with API key.") + p.URL = "https://www.googleapis.com/drive/v3/files/" + p.ID + "?alt=media&supportsAllDrives=true&key=" + p.APIKey + dlfile, err := p.getFileInfFromP() + if err != nil { + return err + } + p.Filename = dlfile.Name + p.Size = dlfile.Size + } + if p.APIKey != "" && p.ShowFileInf { if err := p.showFileInf(); err != nil { return err @@ -409,7 +419,7 @@ func createHelp() *cli.App { {Name: "tanaike [ https://github.com/tanaikech/" + appname + " ] ", Email: "tanaike@hotmail.com"}, } a.UsageText = "Download shared files on Google Drive." - a.Version = "2.0.4" + a.Version = "2.0.5" a.Flags = []cli.Flag{ &cli.StringFlag{ Name: "url, u", diff --git a/resumabledownload.go b/resumabledownload.go index 09a4226..a94c0e2 100644 --- a/resumabledownload.go +++ b/resumabledownload.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -138,7 +137,7 @@ func (v *valResumableDownload) resDownloadFileByAPIKey() (*http.Response, error) return nil, err } if res.StatusCode != 206 && res.StatusCode != 200 { - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) if err != nil { return nil, err } @@ -155,7 +154,7 @@ func (v *valResumableDownload) getFileInf() error { return err } fields := []googleapi.Field{"createdTime,id,md5Checksum,mimeType,modifiedTime,name,owners,parents,shared,size,webContentLink,webViewLink"} - res, err := srv.Files.Get(v.ID).Fields(fields...).Do() + res, err := srv.Files.Get(v.ID).Fields(fields...).SupportsAllDrives(true).Do() if err != nil { return err }