wget large files from linux command (google drive)

21 Май

Download large files from a Google drive

wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt

google drive .sh script

#!/bin/bash
 
url=$1
filename=$2
 
[ -z "$url" ] && echo A URL or ID is required first argument && exit 1
 
fileid=""
declare -a patterns=("s/.*\/file\/d\/\(.*\)\/.*/\1/p" "s/.*id\=\(.*\)/\1/p" "s/\(.*\)/\1/p")
for i in "${patterns[@]}"
do
   fileid=$(echo $url | sed -n $i)
   [ ! -z "$fileid" ] && break
done
 
[ -z "$fileid" ] && echo Could not find Google ID && exit 1
 
echo File ID: $fileid 
 
tmp_file="$filename.$$.file"
tmp_cookies="$filename.$$.cookies"
tmp_headers="$filename.$$.headers"
 
url='https://docs.google.com/uc?export=download&id='$fileid
echo Downloading: "$url > $tmp_file"
wget --save-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file"
 
if [[ ! $(find "$tmp_file" -type f -size +10000c 2>/dev/null) ]]; then
   confirm=$(cat "$tmp_file" | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p')
fi
 
if [ ! -z "$confirm" ]; then
   url='https://docs.google.com/uc?export=download&id='$fileid'&confirm='$confirm
   echo Downloading: "$url > $tmp_file"
   wget --load-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file"
fi
 
[ -z "$filename" ] && filename=$(cat "$tmp_headers" | sed -rn 's/.*filename=\"(.*)\".*/\1/p')
[ -z "$filename" ] && filename="google_drive.file"
 
echo Moving: "$tmp_file > $filename"
 
mv "$tmp_file" "$filename"
 
rm -f "$tmp_cookies" "$tmp_headers"
 
echo Saved: "$filename"
echo DONE!
 
exit 0
Rating of article:
[Total: 0 Average: 0]

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.