2023年9月3日 星期日

以指令方式下載Google Drive上的檔案

 get_gd_file.sh程式碼:

#!/bin/sh

# 檔案 ID
file_id=$1

# 輸出檔案名稱
file_name=$2

# 下載檔案
wget --no-check-certificate "https://drive.google.com/uc?id=$file_id&export=download" -O $file_name

p.s.檔案會下載到get_gd_file.sh所在目錄

例如:

純下指令方式:

wget --no-check-certificate "https://drive.google.com/uc?id=14DwLbdDkgT2pCqE4fiM132_AUibzb_5D&export=download" -O Mojave-Dark.tar.xz


改用get_gd_file.sh,則變成:

./get_gd_file.sh 14DwLbdDkgT2pCqE4fiM132_AUibzb_5D  Mojave-Dark.tar.xz


較大的檔案,如果有安裝Python,則可以安裝gdown

pip install gdown

語法:

usage: gdown [-h] [-V] [-O OUTPUT] [-q] [--fuzzy] [--id] [--proxy PROXY] [--speed SPEED] [--no-cookies] [--no-check-certificate] [--continue]

             [--folder] [--remaining-ok] [--format FORMAT]

             url_or_id


positional arguments:

  url_or_id             url or file/folder id (with --id) to download from


options:

  -h, --help            show this help message and exit

  -V, --version         display version (default: None)

  -O OUTPUT, --output OUTPUT

                        output file name / path (default: None)

  -q, --quiet           suppress standard output (default: False)

  --fuzzy               (fild only) extract Google Drive's file ID (default: False)

  --id                  [DEPRECATED] flag to specify file/folder id instead of url (default: False)

  --proxy PROXY         <protocol://host:port> download using the specified proxy (default: None)

  --speed SPEED         download speed limit in second (e.g., '10MB' -> 10MB/s) (default: None)

  --no-cookies          don't use cookies in ~/.cache/gdown/cookies.json (default: False)

  --no-check-certificate

                        don't check the server's TLS certificate (default: False)

  --continue, -c        (file only) resume getting a partially-downloaded file (default: False)

  --folder              download entire folder instead of a single file (max 50 files per folder) (default: False)

  --remaining-ok        (folder only) asserts that is ok to download max 50 files per folder. (default: False)

  --format FORMAT       Format of Google Docs, Spreadsheets and Slides. Default is Google Docs: 'docx', Spreadsheet: 'xlsx', Slides: 'pptx'.

                        (default: None)

上面例子就可以更簡化成:
gdown https://drive.google.com/uc?id=14DwLbdDkgT2pCqE4fiM132_AUibzb_5D

相關文章 :

沒有留言: