Last active
April 8, 2020 17:39
-
-
Save itsjimbo/62226301b31bf2d7790b55267d856bdd to your computer and use it in GitHub Desktop.
Download public google drive file from jupyter notebook using curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "google-drive-download-public-link.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/itsjimbo/88e665b19f2da8ea10e85e8fc7d845fe/google-drive-download-public-link.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5jFtkUeT07O3", | |
"colab_type": "code", | |
"outputId": "", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 119 | |
} | |
}, | |
"source": [ | |
"import sys,os,os.path\n", | |
"\n", | |
"\n", | |
"# the FILE_ID is contained within the shareable link after the id url parameter https://drive.google.com/open?id={FILE_ID}\n", | |
"# the FILE_NAME is the filename you want to save it as\n", | |
"os.environ['FILE_ID']='1DoaXUj52EGK02My7TE'\n", | |
"os.environ['FILE_NAME']='images.zip'\n", | |
"!curl -L --cookie \"/tmp/cookies_$FILE_ID.txt\" \"https://docs.google.com/uc?export=download&confirm=$(curl --silent --cookie-jar /tmp/cookies_$FILE_ID.txt \"https://docs.google.com/uc?export=download&id=$FILE_ID\" | sed -En 's/^(.*)href=\\\"\\/uc\\?export=download&confirm=([0-9A-Za-z_]+)(.*)$/\\2/p'|tail -n 1)&id=$FILE_ID\" --output \"$FILE_NAME\" && rm -rf \"/tmp/cookies_$FILE_ID.txt\"\n" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
" % Total % Received % Xferd Average Speed Time Time Time Current\n", | |
" Dload Upload Total Spent Left Speed\n", | |
"100 408 0 408 0 0 122 0 --:--:-- 0:00:03 --:--:-- 122\n", | |
" 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0\n", | |
" 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0\n", | |
"100 1099k 100 1099k 0 0 293k 0 0:00:03 0:00:03 --:--:-- 162M\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "KASKdH0m1l7d", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment