Skip to content

Instantly share code, notes, and snippets.

@Yegorov
Created January 13, 2018 16:08
Show Gist options
  • Save Yegorov/dc61c42aa4e89e139cd8248f59af6b3e to your computer and use it in GitHub Desktop.
Save Yegorov/dc61c42aa4e89e139cd8248f59af6b3e to your computer and use it in GitHub Desktop.
Download file from Yandex.Disk through share link
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# https://toster.ru/q/72866
# How to
# wget http://gist.github.com/...
# chmod +x ya.py
# ./ya.py download_url path/to/directory
import os, sys, json
import urllib.parse as ul
sys.argv.append('.') if len(sys.argv) == 2 else None
base_url = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
url = ul.quote_plus(sys.argv[1])
folder = sys.argv[2]
res = os.popen('wget -qO - {}{}'.format(base_url, url)).read()
json_res = json.loads(res)
filename = ul.parse_qs(ul.urlparse(json_res['href']).query)['filename'][0]
os.system("wget '{}' -P '{}' -O '{}'".format(json_res['href'], folder, filename))
# os.system("wget '{}'".format(json_res['href']))
@Yegorov
Copy link
Author

Yegorov commented Jan 13, 2018

How use

wget https://gist.githubusercontent.com/Yegorov/dc61c42aa4e89e139cd8248f59af6b3e/raw/20ac954e202fe6a038c2b4bb476703c02fe0df87/ya.py
chmod +x ya.py
./ya.py download_url path/to/directory
# or
python ya.py download_url path/to/directory

@mrPsycho
Copy link

mrPsycho commented Jan 2, 2019

is it possible to add recursive downloading?
im trying to download and get this:

HTTP request sent, awaiting response... 507 Insufficient Storage
2019-01-02 16:32:18 ERROR 507: Insufficient Storage.

it looks like it asks to townload zip file.

@wildcard
Copy link

wildcard commented Sep 29, 2021

Thanks for this script! It works for me while this one is not working https://github.com/Yegorov/yadisk

See my addition for large files download that's prone to long connection errors https://gist.github.com/wildcard/8c1cb5ac0bb5713a17ef1e4dd6e4780b#gistcomment-3909074

@wcoder
Copy link

wcoder commented Aug 1, 2023

Thanks for the script.
Link Node.js fork: https://gist.github.com/wcoder/bb62eac43a63bcc49847665f59697306

@pavlovma007
Copy link

is it possible to add recursive downloading? im trying to download and get this:

HTTP request sent, awaiting response... 507 Insufficient Storage
2019-01-02 16:32:18 ERROR 507: Insufficient Storage.

it looks like it asks to townload zip file.

+1 it download zip first . yandex can not make super big zip

@Ashaxer
Copy link

Ashaxer commented Oct 10, 2024

can you implant it with "axel" module?
it is a basic file downloader with threading support (IDK if yandex allows threading or not)
usage:
axel -a -n [threads_number] [link]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment