Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Forked from tanaikech/submit.md
Created January 28, 2018 09:44
Show Gist options
  • Save gregorynicholas/31c13931487928300d9f347c8fb7bbf7 to your computer and use it in GitHub Desktop.
Save gregorynicholas/31c13931487928300d9f347c8fb7bbf7 to your computer and use it in GitHub Desktop.

Revisions

  1. @tanaikech tanaikech revised this gist Aug 5, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions submit.md
    Original file line number Diff line number Diff line change
    @@ -41,6 +41,7 @@ curl -b ./cookie.txt -L -o ${filename} "https://drive.google.com${query}"
    The value of ``confirm`` is changed every time. So when the value of ``confirm`` is retrieved, the cookie is saved using ``-c ./cookie.txt``, and when the file is downloaded, the cookie has to be read using ``-b ./cookie.txt``.
    By using this method, you can download files with the size of over 1 GB.
    Reference: [http://qiita.com/netwing/items/f2a595389f39206235e8](http://qiita.com/netwing/items/f2a595389f39206235e8)
  2. @tanaikech tanaikech created this gist Aug 5, 2017.
    46 changes: 46 additions & 0 deletions submit.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # Downloading Shared Files on Google Drive Using Curl

    When the shared files on Google Drive is downloaded, it is necessary to change the download method by the file size. The boundary of file size when the method is changed is about **40MB**.

    ### File size < 40MB
    #### CURL
    ~~~bash
    filename="### filename ###"
    fileid="### file ID ###"
    curl -L -o ${filename} "https://drive.google.com/uc?export=download&id=${fileid}"
    ~~~

    ### File size > 40MB
    When it tries to download the file with more than 40MB, Google says to download from following URL.

    ~~~html
    <a id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" href="/uc?export=download&amp;confirm=####&amp;id=### file ID ###">download</a>
    ~~~

    Query included ``confirm=####`` is important for downloading the files with large size. In order to retrieve the query from the HTML, it uses [``pup``](https://github.com/EricChiang/pup).

    ~~~bash
    pup 'a#uc-download-link attr{href}'
    ~~~

    And ``sed`` is used to remove ``amp;``.

    ~~~bash
    sed -e 's/amp;//g'`
    ~~~
    So curl command is as follows.
    #### CURL
    ~~~bash
    filename="### filename ###"
    fileid="### file ID ###"
    query=`curl -c ./cookie.txt -s -L "https://drive.google.com/uc?export=download&id=${fileid}" | pup 'a#uc-download-link attr{href}' | sed -e 's/amp;//g'`
    curl -b ./cookie.txt -L -o ${filename} "https://drive.google.com${query}"
    ~~~
    The value of ``confirm`` is changed every time. So when the value of ``confirm`` is retrieved, the cookie is saved using ``-c ./cookie.txt``, and when the file is downloaded, the cookie has to be read using ``-b ./cookie.txt``.
    Reference: [http://qiita.com/netwing/items/f2a595389f39206235e8](http://qiita.com/netwing/items/f2a595389f39206235e8)