Skip to content

Commit

Permalink
Updated to v2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Mar 10, 2024
1 parent 8d67ea9 commit 24b9f01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions getfilesfromfolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 13 additions & 3 deletions goodls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"log"
"mime"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -409,7 +419,7 @@ func createHelp() *cli.App {
{Name: "tanaike [ https://github.com/tanaikech/" + appname + " ] ", Email: "[email protected]"},
}
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",
Expand Down
5 changes: 2 additions & 3 deletions resumabledownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 24b9f01

Please sign in to comment.