Mercurial > codedump
annotate getlist.py @ 128:1a83948b7f80
gendesc: only use fulltitle if available
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sun, 19 Oct 2025 22:46:55 -0400 |
| parents | eac6dae753ca |
| children |
| rev | line source |
|---|---|
| 40 | 1 import urllib.request |
| 2 import json | |
| 3 import sys | |
|
118
eac6dae753ca
*: major cleanup
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
41
diff
changeset
|
4 from yt_dlp.utils import sanitize_filename |
| 30 | 5 |
| 32 | 6 # Initialize variables |
| 40 | 7 # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 |
| 8 key = "f090bb54758cabf231fb605d3e3e0468" | |
| 32 | 9 |
| 10 # Ask for source | |
| 40 | 11 if not 2 >= len(sys.argv): |
| 12 source = sys.argv[1] | |
| 13 if 'source' not in locals() or 'source' not in globals(): | |
| 14 source = input( | |
| 15 "Which website would you like to pull titles from? [tmdb, mal]: ") | |
| 32 | 16 while source not in ["tmdb", "mal"]: |
| 17 print("Not a valid source! Exiting.") | |
| 18 sys.exit() | |
| 19 | |
| 20 # Ask for ID | |
| 40 | 21 if not 3 >= len(sys.argv): |
| 22 source = sys.argv[2] | |
| 23 if 'id' not in locals() or 'id' not in globals(): | |
| 32 | 24 id = input("What is the ID for your show?: ") |
| 30 | 25 try: |
| 26 temp = int(id) | |
| 40 | 27 except Exception: |
| 32 | 28 print("Not a valid ID! Exiting.") |
| 30 | 29 sys.exit() |
| 30 | |
| 32 | 31 # Scrapers |
| 32 if source == 'tmdb': | |
| 40 | 33 # required because api is... odd |
| 34 season = input("Which season do you want?: ") | |
| 32 | 35 try: |
| 36 temp = int(season) | |
| 40 | 37 except Exception: |
| 32 | 38 print("Not a valid season! Exiting.") |
| 39 sys.exit() | |
| 40 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode()) | |
| 41 amount = data["number_of_episodes"] | |
| 31 | 42 f = open("list.txt", "w", encoding="utf-8") |
| 43 f.write("") | |
| 44 f.close() | |
| 32 | 45 count = 1 |
| 40 | 46 for i in range(amount): # this may count as spamming the api but i don't care lol |
|
41
37f231f85a67
add tabs to some c++ files and fix win95kg.cpp
Paper <mrpapersonic@gmail.com>
parents:
40
diff
changeset
|
47 with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: |
| 32 | 48 data = json.loads(url.read().decode()) |
| 49 f = open("list.txt", "a", encoding="utf-8") | |
|
118
eac6dae753ca
*: major cleanup
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
41
diff
changeset
|
50 f.write(sanitize_filename(data["name"], restricted=True) + "\n") |
| 32 | 51 count += 1 |
| 52 f.close() | |
| 53 if source == 'mal': | |
| 54 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url: | |
| 55 data = json.loads(url.read().decode()) | |
| 56 count = 0 | |
| 57 f = open("list.txt", "w", encoding="utf-8") | |
| 58 f.write("") | |
| 30 | 59 f.close() |
| 32 | 60 for i in range(len(data["episodes"])): |
| 61 f = open("list.txt", "a", encoding="utf-8") | |
|
118
eac6dae753ca
*: major cleanup
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
41
diff
changeset
|
62 f.write(sanitize_filename(data["episodes"][count]["title"], restricted=True) + "\n") |
| 32 | 63 count += 1 |
| 64 f.close() |
