Google/Drive

From Omnia
Jump to navigation Jump to search

Windows Missing Overlay Icons

See Windows/Missing Overlay Icons

Direct Download

If you want to share a direct link, simply change the format of the link from this: (works up to a 100MB file, larger than use gdown)

https://drive.google.com/file/d/[FILE_ID]/edit?usp=sharing

To this:

https://drive.google.com/uc?export=download&id=[FILE_ID]

Reference:

Direct Download Python

pip install gdown
# gdown --id [ID]  # why specify --id??
gdown [ID]
gdown https://drive.google.com/uc?id=<file_id>  # for files
gdown <file_id>                                 # alternative format
gdown --folder https://drive.google.com/drive/folders/<file_id>  # for folders
gdown --folder --id <file_id>                                   # this format works for folders too

ref: https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive/39225039#39225039

.

--- Old GDown Method ---

Python3 or Python2.

gdown.py:

import requests

def download_file_from_google_drive(id, destination):
    def get_confirm_token(response):
        for key, value in response.cookies.items():
            if key.startswith('download_warning'):
                return value

        return None

    def save_response_content(response, destination):
        CHUNK_SIZE = 32768

        with open(destination, "wb") as f:
            for chunk in response.iter_content(CHUNK_SIZE):
                if chunk: # filter out keep-alive new chunks
                    f.write(chunk)

    URL = "https://docs.google.com/uc?export=download"

    session = requests.Session()

    response = session.get(URL, params = { 'id' : id }, stream = True)
    token = get_confirm_token(response)

    if token:
        params = { 'id' : id, 'confirm' : token }
        response = session.get(URL, params = params, stream = True)

    save_response_content(response, destination)    


if __name__ == "__main__":
    import sys
    if len(sys.argv) != 3:
        print("Usage: python google_drive.py drive_file_id destination_file_path")
    else:
        # TAKE ID FROM SHAREABLE LINK
        file_id = sys.argv[1]
        # DESTINATION FILE ON YOUR DISK
        destination = sys.argv[2]
        download_file_from_google_drive(file_id, destination)

ref: [1]

Linux gdrive

gdrive:

https://github.com/prasmussen/gdrive/

Install:

wget "https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive_2.1.1_linux_amd64.tar.gz"
tar -zvxf gdrive_2.1.1_linux_amd64.tar.gz
sudo mv gdrive /usr/local/bin/

Fix musl Dependency: (If you don't you may get an error about "file not found")

sudo apt-get install musl-dev
sudo  ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1

Usage:

gdrive download 0B7_OwkDsUIgFWXA1B2FPQfV5S8H

Rate limiting example:

gdrive download --stdout 0B7_OwkDsUIgFWXA1B2FPQfV5S8H | \
   pv -br -L 90k | cat > file.ext

Issue: (caused by missing musl)

# gdrive
-bash: /usr/local/bin/gdrive: No such file or directory
# ldd /usr/local/bin/gdrive
        linux-vdso.so.1 (0x00007ffc29757000)
        libc.musl-x86_64.so.1 => not found

ref: https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive/39225039#39225039

ref: https://github.com/prasmussen/gdrive/releases/tag/2.1.1

ref: https://github.com/alexander-akhmetov/python-telegram/issues/3

keywords