Advertisement
karim0209

gdrivedl

Dec 18th, 2021
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.41 KB | None | 0 0
  1. #!/data/data/com.termux/files/usr/bin/bash
  2.  
  3. url=$1
  4. filename=$2
  5.  
  6. [ -z "$url" ] && echo A URL or ID is required first argument && exit 1
  7.  
  8. fileid=""
  9. declare -a patterns=("s/.*\/file\/d\/\(.*\)\/.*/\1/p" "s/.*id\=\(.*\)/\1/p" "s/\(.*\)/\1/p")
  10. for i in "${patterns[@]}"
  11. do
  12.    fileid=$(echo $url | sed -n $i)
  13.    [ ! -z "$fileid" ] && break
  14. done
  15.  
  16. [ -z "$fileid" ] && echo Could not find Google ID && exit 1
  17.  
  18. echo File ID: $fileid
  19.  
  20. tmp_file="$filename.$$.file"
  21. tmp_cookies="$filename.$$.cookies"
  22. tmp_headers="$filename.$$.headers"
  23.  
  24. url='https://docs.google.com/uc?export=download&id='$fileid
  25. echo Downloading: "$url > $tmp_file"
  26. wget --save-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file"
  27.  
  28. if [[ ! $(find "$tmp_file" -type f -size +10000c 2>/dev/null) ]]; then
  29.    confirm=$(cat "$tmp_file" | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p')
  30. fi
  31.  
  32. if [ ! -z "$confirm" ]; then
  33.    url='https://docs.google.com/uc?export=download&id='$fileid'&confirm='$confirm
  34.    echo Downloading: "$url > $tmp_file"
  35.    wget --load-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file"
  36. fi
  37.  
  38. [ -z "$filename" ] && filename=$(cat "$tmp_headers" | sed -rn 's/.*filename=\"(.*)\".*/\1/p')
  39. [ -z "$filename" ] && filename="google_drive.file"
  40.  
  41. echo Moving: "$tmp_file > $filename"
  42.  
  43. mv "$tmp_file" "$filename"
  44.  
  45. rm -f "$tmp_cookies" "$tmp_headers"
  46.  
  47. echo Saved: "$filename"
  48. echo DONE!
  49.  
  50. exit 0
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement