Last active
July 29, 2023 19:54
-
-
Save pizzaboxer/bcdf9d9c4ad35a1b50229116acf38820 to your computer and use it in GitHub Desktop.
python script that downloads all files uploaded to your gyazo account, no pro subscription needed :D
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
| import base64 | |
| import filedate | |
| import json | |
| import os | |
| import requests | |
| session = requests.Session() | |
| cookie = input("enter gyazo session cookie: ") | |
| images = [] | |
| page = 1 | |
| while True: | |
| print(f"[{page}] fetching images...", flush=True, end="") | |
| request = session.get( | |
| f"https://gyazo.com/api/internal/images?page={page}&per=100", | |
| cookies={"Gyazo_session": cookie} | |
| ) | |
| print(f" done!", flush=True) | |
| if request.text == "[]": | |
| break | |
| images += request.json() | |
| page += 1 | |
| if not os.path.exists("downloads"): | |
| os.makedirs("downloads") | |
| count = 1 | |
| for image in images: | |
| print(f"downloading image {count} of {len(images)}...", flush=True, end="") | |
| jwt = image['alias_id'] | |
| url = image['non_cropped_thumb']['url'] | |
| metadata = image['metadata'] | |
| payload = json.loads(base64.b64decode(jwt.split('.')[1] + "==")) | |
| id = payload['img'] | |
| ext = url[-7:-4] | |
| attr = "" | |
| if "app" in metadata: | |
| attr = image['metadata']['app'] | |
| elif "title" in metadata: | |
| attr = image['metadata']['title'] | |
| for char in "\\/:*?\"<>|": | |
| attr = attr.replace(char, "-") | |
| filename = f"downloads/{attr}{id}.{ext}" | |
| if not os.path.exists(filename): | |
| request = session.get(f"https://thumb.gyazo.com/thumb/8192/{id}.{ext}") | |
| with open(filename, "wb") as file: | |
| file.write(request.content) | |
| timestamp = image['created_at'] | |
| filedate.File(filename).set( | |
| created = timestamp, | |
| modified = timestamp | |
| ) | |
| print(" done!", flush=True) | |
| count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment