Skip to content

Instantly share code, notes, and snippets.

@yauhenipakala
Forked from wildcard/ya.py
Last active October 10, 2024 11:19
Show Gist options
  • Select an option

  • Save yauhenipakala/bb62eac43a63bcc49847665f59697306 to your computer and use it in GitHub Desktop.

Select an option

Save yauhenipakala/bb62eac43a63bcc49847665f59697306 to your computer and use it in GitHub Desktop.

Revisions

  1. yauhenipakala revised this gist Aug 1, 2023. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ya.js
    Original file line number Diff line number Diff line change
    @@ -31,10 +31,8 @@ https.get(apiUrlWithQuery, (res) => {
    '--tries=0',
    '--timeout=5',
    json_res.href,
    '-P',
    folder,
    '-O',
    filename,
    `${folder}${filename}`,
    ];

    const childProcess = spawn(command, args);
  2. yauhenipakala revised this gist Aug 1, 2023. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions ya.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,9 @@
    #!/usr/bin/env node
    # -*- coding: utf-8 -*-

    # How to
    # wget http://gist.github.com/...
    # chmod +x ya.js
    # ./ya.js download_url path/to/directory
    // How to
    // wget http://gist.github.com/...
    // chmod +x ya.js
    // ./ya.js download_url path/to/directory

    const https = require('https');
    const { URL } = require('url');
  3. yauhenipakala revised this gist Aug 1, 2023. 2 changed files with 65 additions and 22 deletions.
    65 changes: 65 additions & 0 deletions ya.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #!/usr/bin/env node
    # -*- coding: utf-8 -*-

    # How to
    # wget http://gist.github.com/...
    # chmod +x ya.js
    # ./ya.js download_url path/to/directory

    const https = require('https');
    const { URL } = require('url');
    const { spawn } = require('child_process');

    const base_url = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key=';
    const apiUrl = process.argv[2];
    const folder = process.argv[3] || '.';

    const encodedUrl = encodeURIComponent(apiUrl);
    const apiUrlWithQuery = base_url + encodedUrl;

    https.get(apiUrlWithQuery, (res) => {
    let data = '';
    res.on('data', (chunk) => {
    data += chunk;
    });
    res.on('end', () => {
    const json_res = JSON.parse(data);
    const filename = new URL(json_res.href).searchParams.get('filename');
    const command = 'wget';
    const args = [
    '-c',
    '--retry-connrefused',
    '--tries=0',
    '--timeout=5',
    json_res.href,
    '-P',
    folder,
    '-O',
    filename,
    ];

    const childProcess = spawn(command, args);

    childProcess.stdout.on('data', (data) => {
    console.log(data.toString());
    });

    childProcess.stderr.on('data', (data) => {
    console.error(data.toString());
    });

    childProcess.on('error', (err) => {
    console.error('Error:', err.message);
    });

    childProcess.on('exit', (code) => {
    if (code === 0) {
    console.log('File downloaded successfully!');
    } else {
    console.error(`Command execution failed with code ${code}`);
    }
    });
    });
    }).on('error', (err) => {
    console.error('Error:', err.message);
    });
    22 changes: 0 additions & 22 deletions ya.py
    Original file line number Diff line number Diff line change
    @@ -1,22 +0,0 @@
    #!/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']))
  4. @wildcard wildcard revised this gist Oct 1, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ya.py
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@
    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 -c --retry-connrefused --tries=0 --timeout=5 '{}' -P '{}' -O '{}'".format(json_res['href'], folder, filename))
    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']))
  5. @wildcard wildcard revised this gist Sep 29, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ya.py
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@
    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 -c --retry-connrefused --tries=0 --timeout=5 '{}' -P '{}' -O '{}'".format(json_res['href'], folder, filename))
    # os.system("wget '{}'".format(json_res['href']))
  6. @Yegorov Yegorov created this gist Jan 13, 2018.
    22 changes: 22 additions & 0 deletions ya.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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']))