Skip to content

Commit

Permalink
Updated to v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Nov 25, 2018
1 parent 3f2f235 commit 34d7cc8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ In order to use this, please retrieve API key as the following flow.
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.

~~~bash
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.

Expand Down Expand Up @@ -249,5 +259,11 @@ If you have any questions and commissions for me, feel free to tell me.
1. By using API key, the shared large files can be run [**the resumable download**](#resumabledownloadoffile).
- This demonstration can be seen at [Demo](#demo4).

<a name="v121"></a>

* 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.


[TOP](#TOP)
13 changes: 12 additions & 1 deletion goodls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

const (
appname = "goodls"
envval = "GOODLS_APIKEY"
anyurl = "https://drive.google.com/uc?export=download"
docutl = "https://docs.google.com/"
)
Expand Down Expand Up @@ -138,6 +139,13 @@ func (p *para) getFilename(s *http.Response) error {
// downloadLargeFile : When a large size of file is downloaded, this method is used.
func (p *para) downloadLargeFile() error {
fmt.Println("Now downloading.")
if p.APIKey != "" {
dlfile, err := p.getFileInfFromP()
if err != nil {
return err
}
p.Size = dlfile.Size
}
res, err := p.fetch(p.URL + "&confirm=" + p.Code)
if err != nil {
return err
Expand Down Expand Up @@ -298,6 +306,9 @@ func handler(c *cli.Context) {
WorkDir: workdir,
DlFolder: false,
}
if envv := os.Getenv(envval); c.String("apikey") == "" && envv != "" {
p.APIKey = strings.TrimSpace(envv)
}
if terminal.IsTerminal(int(syscall.Stdin)) {
if c.String("url") == "" {
createHelp().Run(os.Args)
Expand Down Expand Up @@ -344,7 +355,7 @@ func createHelp() *cli.App {
a.Author = "tanaike [ https://github.com/tanaikech/" + appname + " ] "
a.Email = "[email protected]"
a.Usage = "Download shared files on Google Drive."
a.Version = "1.2.0"
a.Version = "1.2.1"
a.Flags = []cli.Flag{
cli.StringFlag{
Name: "url, u",
Expand Down
15 changes: 12 additions & 3 deletions resumabledownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,27 @@ type dlParams struct {
End int64
}

// showFileInf : Show file information.
func (p *para) showFileInf() error {
// getFileInfFromP : Retrieve file information from *para.
func (p *para) getFileInfFromP() (*drive.File, error) {
v := &valResumableDownload{
para: *p,
}
v.Client = &http.Client{
Transport: &transport.APIKey{Key: p.APIKey},
}
if err := v.getFileInf(); err != nil {
return nil, err
}
return v.DownloadFile, nil
}

// showFileInf : Show file information.
func (p *para) showFileInf() error {
dlfile, err := p.getFileInfFromP()
if err != nil {
return err
}
r, err := json.Marshal(v.DownloadFile)
r, err := json.Marshal(dlfile)
if err != nil {
return err
}
Expand Down

0 comments on commit 34d7cc8

Please sign in to comment.