Created
October 20, 2024 02:37
-
-
Save toriato/fe237a1e402f6d89e37d9b6b3aa8fe1e to your computer and use it in GitHub Desktop.
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/python | |
from typing import List | |
from dataclasses import dataclass | |
from argparse import ArgumentParser | |
from pathlib import Path | |
from urllib.parse import urlparse, ParseResult | |
from requests import session | |
from subprocess import call | |
@dataclass | |
class ArgumentInterface: | |
urls: List[ParseResult] | |
out_dir: Path | |
parser = ArgumentParser() | |
parser.add_argument('urls', type=urlparse, nargs='+') | |
parser.add_argument('--out-dir', type=Path, default=Path.cwd()) | |
args = ArgumentInterface(**vars(parser.parse_args())) | |
api = session() | |
api.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; rv:131.0) Gecko/20100101 Firefox/131.0' | |
def fetchToken(): | |
res = api.post('https://api.gofile.io/accounts') | |
res.raise_for_status() | |
p = res.json() | |
if p['status'] != 'ok': | |
raise Exception('unable to fetch token') | |
return p['data']['token'] | |
def fetchContent(id: str, token: str): | |
res = api.get( | |
f'https://api.gofile.io/contents/{id}?wt=4fd6sg89d7s6', | |
headers={'Authorization': f'Bearer {token}'} | |
) | |
res.raise_for_status() | |
p = res.json() | |
if p['status'] != 'ok': | |
raise Exception('unable to fetch content') | |
return p['data'] | |
token = fetchToken() | |
for url in args.urls: | |
if url.hostname != 'gofile.io': | |
raise ValueError(f'unsupported hostname: {url}') | |
content = fetchContent(url.path.split('/').pop(), token) | |
for file in content['children'].values(): | |
if file['type'] != 'file': | |
continue | |
call([ | |
'aria2c', | |
'--continue', | |
'--max-connection-per-server', '1', | |
'--header', f'Cookie:accountToken={token}', | |
'--dir', str(args.out_dir), | |
file['link'] | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment