Mercurial > codedump
annotate getlist.py @ 68:a43ed076b28f
[channeldownloader.py] Implement HTTPError to circumvent Python 2 weirdness
kind of hacky because we're just giving it none for everything LOL
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Wed, 18 May 2022 20:05:47 -0400 |
parents | 37f231f85a67 |
children | eac6dae753ca |
rev | line source |
---|---|
40 | 1 import urllib.request |
2 import json | |
3 import sys | |
30 | 4 |
32 | 5 # Initialize variables |
40 | 6 # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 |
7 key = "f090bb54758cabf231fb605d3e3e0468" | |
32 | 8 |
9 # Ask for source | |
40 | 10 if not 2 >= len(sys.argv): |
11 source = sys.argv[1] | |
12 if 'source' not in locals() or 'source' not in globals(): | |
13 source = input( | |
14 "Which website would you like to pull titles from? [tmdb, mal]: ") | |
32 | 15 while source not in ["tmdb", "mal"]: |
16 print("Not a valid source! Exiting.") | |
17 sys.exit() | |
18 | |
19 # Ask for ID | |
40 | 20 if not 3 >= len(sys.argv): |
21 source = sys.argv[2] | |
22 if 'id' not in locals() or 'id' not in globals(): | |
32 | 23 id = input("What is the ID for your show?: ") |
30 | 24 try: |
25 temp = int(id) | |
40 | 26 except Exception: |
32 | 27 print("Not a valid ID! Exiting.") |
30 | 28 sys.exit() |
29 | |
32 | 30 # Scrapers |
31 if source == 'tmdb': | |
40 | 32 # required because api is... odd |
33 season = input("Which season do you want?: ") | |
32 | 34 try: |
35 temp = int(season) | |
40 | 36 except Exception: |
32 | 37 print("Not a valid season! Exiting.") |
38 sys.exit() | |
39 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode()) | |
40 amount = data["number_of_episodes"] | |
31 | 41 f = open("list.txt", "w", encoding="utf-8") |
42 f.write("") | |
43 f.close() | |
32 | 44 count = 1 |
40 | 45 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
|
46 with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: |
32 | 47 data = json.loads(url.read().decode()) |
48 f = open("list.txt", "a", encoding="utf-8") | |
40 | 49 f.write(data["name"].replace("?", "?").replace( |
50 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\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") | |
40 | 62 f.write(data["episodes"][count]["title"].replace("?", "?").replace( |
63 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | |
32 | 64 count += 1 |
65 f.close() |