Mercurial > codedump
comparison getlist.py @ 32:fdbafd3e86d9
add tmdb to getlist.py
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 13 Jun 2021 14:59:37 -0400 |
parents | b5cf08125fd5 |
children | 2aa9614cb39a |
comparison
equal
deleted
inserted
replaced
31:b5cf08125fd5 | 32:fdbafd3e86d9 |
---|---|
1 import urllib.request, json, re, sys | 1 import urllib.request, json, re, sys |
2 | 2 |
3 id = sys.argv[1] | 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] | |
4 if not 'id' in locals() or not 'id' in globals(): | 16 if not 'id' in locals() or not 'id' in globals(): |
5 id = input("What is the MyAnimeList ID for your anime?: ") | 17 id = input("What is the ID for your show?: ") |
6 try: | 18 try: |
7 temp = int(id) | 19 temp = int(id) |
8 except: | 20 except: |
9 print("Not a valid MyAnimeList ID! Exiting.") | 21 print("Not a valid ID! Exiting.") |
10 sys.exit() | 22 sys.exit() |
11 | 23 |
12 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url: | 24 # Scrapers |
13 data = json.loads(url.read().decode()) | 25 if source == 'tmdb': |
14 count = 0 | 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"] | |
15 f = open("list.txt", "w", encoding="utf-8") | 34 f = open("list.txt", "w", encoding="utf-8") |
16 f.write("") | 35 f.write("") |
17 f.close() | 36 f.close() |
18 for i in range(len(data["episodes"])): | 37 count = 1 |
19 f = open("list.txt", "a", encoding="utf-8") | 38 for i in range(amount): # this may count as spamming the api but i don't care lol |
20 """ | 39 with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: |
21 this is really hard to read at first glance so i'll break it down | 40 data = json.loads(url.read().decode()) |
22 it replaces "?" and ":" with legal counterparts so windows stops screaming | 41 f = open("list.txt", "a", encoding="utf-8") |
23 then strips among a dash (which usually shows different parts in an episode) | 42 f.write(data["name"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") |
24 it then removes the last part of the string cause most, if not of MAL's have spaces before slashes | 43 count += 1 |
25 """ | 44 f.close() |
26 f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | 45 if source == 'mal': |
27 count += 1 | 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("") | |
28 f.close() | 51 f.close() |
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() |