Created
September 4, 2025 13:13
-
-
Save veso266/5f9be2ed13a5a455e26b33ce18eedd20 to your computer and use it in GitHub Desktop.
A yet another script, to download from https://gofile.io, used extraxtor from yt-dlp
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
| #!/usr/bin/env python3 | |
| import re | |
| import sys | |
| import json | |
| import hashlib | |
| import requests | |
| import os | |
| API_ACCOUNT = "https://api.gofile.io/accounts" | |
| API_CONTENTS = "https://api.gofile.io/contents/{}" | |
| WEBSITE_TOKEN = "4fd6sg89d7s6" # from gofile.io/dist/js/alljs.js | |
| def get_guest_token(): | |
| r = requests.post(API_ACCOUNT, json={}) | |
| r.raise_for_status() | |
| data = r.json() | |
| if data.get("status") != "ok": | |
| raise RuntimeError("Failed to get guest account: {}".format(data)) | |
| return data["data"]["token"] | |
| def get_file_id(url): | |
| m = re.search(r"gofile\.io/d/([^/]+)", url) | |
| if not m: | |
| raise ValueError("Invalid GoFile URL: {}".format(url)) | |
| return m.group(1) | |
| def get_file_list(file_id, token, password=None): | |
| params = {"wt": WEBSITE_TOKEN} | |
| if password: | |
| sha256 = hashlib.sha256(password.encode("utf-8")).hexdigest() | |
| params["password"] = sha256 | |
| headers = {"Authorization": f"Bearer {token}"} | |
| url = API_CONTENTS.format(file_id) | |
| r = requests.get(url, params=params, headers=headers) | |
| r.raise_for_status() | |
| data = r.json() | |
| if data.get("status") == "error-passwordRequired": | |
| raise RuntimeError("This folder is password-protected. Use --password option.") | |
| if data.get("status") != "ok": | |
| raise RuntimeError("GoFile returned status: {}".format(data.get("status"))) | |
| return data["data"]["children"] | |
| def human_readable_size(num): | |
| """Convert bytes to human readable MB/GB string.""" | |
| for unit in ["B", "KB", "MB", "GB", "TB"]: | |
| if num < 1024: | |
| return f"{num:.2f} {unit}" | |
| num /= 1024 | |
| return f"{num:.2f} PB" | |
| from datetime import datetime | |
| def timestamp_to_date(timestamp): | |
| """ | |
| Convert a Linux timestamp to a human-readable date and time string. | |
| Args: | |
| timestamp (int or float): Unix/Linux timestamp in seconds. | |
| Returns: | |
| str: Date and time in format 'YYYY-MM-DD HH:MM:SS'. | |
| """ | |
| dt = datetime.fromtimestamp(timestamp) # Convert timestamp to datetime object | |
| return dt.strftime('%Y-%m-%d %H:%M:%S') # Format as string | |
| def download_file(url, filename, total_size, token): | |
| with requests.get( | |
| url, | |
| stream=True, | |
| headers={"Authorization": f"Bearer {token}"}, | |
| cookies={"accountToken": token} | |
| ) as r: | |
| r.raise_for_status() | |
| with open(filename, "wb") as f: | |
| downloaded = 0 | |
| for chunk in r.iter_content(chunk_size=1024*1024): | |
| if not chunk: | |
| continue | |
| f.write(chunk) | |
| downloaded += len(chunk) | |
| if total_size: | |
| percent = downloaded * 100 // total_size | |
| sys.stdout.write( | |
| f"\rDownloading {percent}% " | |
| f"({human_readable_size(downloaded)}/{human_readable_size(total_size)})" | |
| ) | |
| sys.stdout.flush() | |
| sys.stdout.write("\n") | |
| def main(): | |
| import argparse | |
| parser = argparse.ArgumentParser(description="Standalone GoFile extractor + downloader") | |
| parser.add_argument("url", help="GoFile URL (e.g. https://gofile.io/d/XXXXX)") | |
| parser.add_argument("--password", help="Password if required", default=None) | |
| args = parser.parse_args() | |
| file_id = get_file_id(args.url) | |
| token = get_guest_token() | |
| files = get_file_list(file_id, token, args.password) | |
| found = False | |
| for f in files.values(): | |
| found = True | |
| name = f["name"] | |
| size = int(f.get("size", 0)) | |
| url = f["link"] | |
| print("ID:", f["id"]) | |
| print("Name:", name) | |
| print("Size:", size) | |
| print("URL:", url) | |
| print(f"Created: {timestamp_to_date(f.get('createTime'))} ({f.get('createTime')})") | |
| print("-" * 40) | |
| # Start downloading | |
| download_file(url, name, size, token) | |
| print("Done: {}\n".format(name)) | |
| if not found: | |
| print("No files found at provided URL.") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment