Google drive download from linux (bash script)

11 Апр

gdown.sh — google drive download large files from linux bash

#!/bin/bash
# usage: gdown fileid /path/to/filename
 
fileid=$1
filename=$2
 
curl -sLc /tmp/gdcookie  "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -sLb /tmp/gdcookie  "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' /tmp/gdcookie`&id=${fileid}" --create-dirs -o ${filename}
rm -f /tmp/gdcookie

gdrive_download.sh

# gdrive_download FILEID FILENAME
# where FILEID is the id in get shareable link in gdrive
 
function gdrive_download () {
  CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$1" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
  wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2
  rm -rf /tmp/cookies.txt
}

download.sh

#!/bin/bash
# Script for downloading file from remote server.
# Usage: ./download.sh gdrive <FILE_ID> <FILENAME>
 
function gdrive()
{
  CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$1" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
  wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2
  rm -rf /tmp/cookies.txt
}
 
if [ $# -eq 0 ]; then
    echo "Usage: $(basename $0) {gdrive}"
    echo "\t./download.sh gdrive <FILE_ID> <FILENAME>"
    exit
fi
 
if [ "$1" == "gdrive" ]; then
    $1 $2 $3
    exit
fi
 
$1

Also see old post: https://tovld.com/archives/3570

Rating of article:
[Total: 1 Average: 5]

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

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

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