-
-
Save wildcard/8c1cb5ac0bb5713a17ef1e4dd6e4780b to your computer and use it in GitHub Desktop.
Download file from Yandex.Disk through share link for large file + reconnect option on MacOS with caffeinate to prevent computer from sleep
This file contains 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
#!/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("caffeinate -s wget -c --retry-connrefused --tries=0 --timeout=5 '{}' -P '{}' -O '{}'".format(json_res['href'], folder, filename)) | |
# os.system("wget '{}'".format(json_res['href'])) |
At first I wanted to comment that it does not work for me, but, surprisingly, after the fifth attempt it managed to connect and actually started downloading. Thank you!
Thanks for the script.
Link Node.js fork: https://gist.github.com/wcoder/bb62eac43a63bcc49847665f59697306
It worked perfectly, thank you!
In case someone is trying to get this work for Ubuntu, you can remove caffeinate -s
from line 21.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've Added
-c --retry-connrefused --tries=0 --timeout=5
to the secondwget
commandBased on the following posts:
https://www.binarytides.com/wget-automatically-resume-broken-downloads/#:~:text=The%20retry%2Dconnrefused%20option%20tells,wget%20to%20keep%20trying%20infinitely.
https://unix.stackexchange.com/questions/165875/resume-failed-download-using-linux-command-line-tool