30
|
1 import urllib.request, json, re, sys
|
|
2
|
32
|
3 # Initialize variables
|
|
4 key = "f090bb54758cabf231fb605d3e3e0468" # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36
|
|
5
|
|
6 # Ask for source
|
|
7 if not 2 >= len(sys.argv): source = sys.argv[1]
|
|
8 if not 'source' in locals() or not 'source' in globals():
|
|
9 source = input("Which website would you like to pull titles from? [tmdb, mal]: ")
|
|
10 while source not in ["tmdb", "mal"]:
|
|
11 print("Not a valid source! Exiting.")
|
|
12 sys.exit()
|
|
13
|
|
14 # Ask for ID
|
|
15 if not 3 >= len(sys.argv): source = sys.argv[2]
|
31
|
16 if not 'id' in locals() or not 'id' in globals():
|
32
|
17 id = input("What is the ID for your show?: ")
|
30
|
18 try:
|
|
19 temp = int(id)
|
|
20 except:
|
32
|
21 print("Not a valid ID! Exiting.")
|
30
|
22 sys.exit()
|
|
23
|
32
|
24 # Scrapers
|
|
25 if source == 'tmdb':
|
|
26 season = input("Which season do you want?: ") # required because api is... odd
|
|
27 try:
|
|
28 temp = int(season)
|
|
29 except:
|
|
30 print("Not a valid season! Exiting.")
|
|
31 sys.exit()
|
|
32 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode())
|
|
33 amount = data["number_of_episodes"]
|
31
|
34 f = open("list.txt", "w", encoding="utf-8")
|
|
35 f.write("")
|
|
36 f.close()
|
32
|
37 count = 1
|
|
38 for i in range(amount): # this may count as spamming the api but i don't care lol
|
|
39 with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url:
|
|
40 data = json.loads(url.read().decode())
|
|
41 f = open("list.txt", "a", encoding="utf-8")
|
|
42 f.write(data["name"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
|
|
43 count += 1
|
|
44 f.close()
|
|
45 if source == 'mal':
|
|
46 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url:
|
|
47 data = json.loads(url.read().decode())
|
|
48 count = 0
|
|
49 f = open("list.txt", "w", encoding="utf-8")
|
|
50 f.write("")
|
30
|
51 f.close()
|
32
|
52 for i in range(len(data["episodes"])):
|
|
53 f = open("list.txt", "a", encoding="utf-8")
|
|
54 f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
|
|
55 count += 1
|
|
56 f.close()
|