Skip to content

Instantly share code, notes, and snippets.

@allenyllee
Forked from ppetraki/fetch_gdrive_file.sh
Last active November 10, 2017 08:03

Revisions

  1. allenyllee revised this gist Nov 10, 2017. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions fetch_gdrive_file.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ if [ "${SOURCE}" == "" ]; then
    exit 1
    fi

    #DEST="$2"
    DEST="$2"
    #if [ "${DEST}" == "" ]; then
    # echo "Must specify a destination filename"
    # exit 1
    @@ -20,7 +20,12 @@ CODE=$(wget --save-cookies $COOKIES --keep-session-cookies --no-check-certificat
    # cleanup the code, format is 'Code: XXXX'
    CODE=$(echo $CODE | rev | cut -d: -f1 | rev | xargs)

    # option --content-disposition to auto fetch filename
    wget --content-disposition --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" #-O $DEST
    # if no $DEST, auto fetch filename, otherwise use $DEST as filename
    if [ -z "$DEST" ]; then
    # option --content-disposition to auto fetch filename
    wget --content-disposition --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}"
    else
    wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST
    fi

    rm -f $COOKIES
  2. allenyllee revised this gist Nov 10, 2017. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions fetch_gdrive_file.sh
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,11 @@ if [ "${SOURCE}" == "" ]; then
    exit 1
    fi

    DEST="$2"
    if [ "${DEST}" == "" ]; then
    echo "Must specify a destination filename"
    exit 1
    fi
    #DEST="$2"
    #if [ "${DEST}" == "" ]; then
    # echo "Must specify a destination filename"
    # exit 1
    #fi

    FILEID=$(echo $SOURCE | rev | cut -d= -f1 | rev)
    COOKIES=$(mktemp)
    @@ -20,6 +20,7 @@ CODE=$(wget --save-cookies $COOKIES --keep-session-cookies --no-check-certificat
    # cleanup the code, format is 'Code: XXXX'
    CODE=$(echo $CODE | rev | cut -d: -f1 | rev | xargs)

    wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST
    # option --content-disposition to auto fetch filename
    wget --content-disposition --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" #-O $DEST

    rm -f $COOKIES
  3. @ppetraki ppetraki created this gist Nov 8, 2017.
    25 changes: 25 additions & 0 deletions fetch_gdrive_file.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    SOURCE="$1"
    if [ "${SOURCE}" == "" ]; then
    echo "Must specify a source url"
    exit 1
    fi

    DEST="$2"
    if [ "${DEST}" == "" ]; then
    echo "Must specify a destination filename"
    exit 1
    fi

    FILEID=$(echo $SOURCE | rev | cut -d= -f1 | rev)
    COOKIES=$(mktemp)

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

    # cleanup the code, format is 'Code: XXXX'
    CODE=$(echo $CODE | rev | cut -d: -f1 | rev | xargs)

    wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST

    rm -f $COOKIES