annotate getlist.py @ 50:6661f088a504

Update README.md committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Sat, 31 Jul 2021 02:30:48 -0400
parents 37f231f85a67
children eac6dae753ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
1 import urllib.request
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
2 import json
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
3 import sys
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
5 # Initialize variables
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
6 # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
7 key = "f090bb54758cabf231fb605d3e3e0468"
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
8
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
9 # Ask for source
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
10 if not 2 >= len(sys.argv):
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
11 source = sys.argv[1]
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
12 if 'source' not in locals() or 'source' not in globals():
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
13 source = input(
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
14 "Which website would you like to pull titles from? [tmdb, mal]: ")
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
15 while source not in ["tmdb", "mal"]:
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
16 print("Not a valid source! Exiting.")
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
17 sys.exit()
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
18
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
19 # Ask for ID
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
20 if not 3 >= len(sys.argv):
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
21 source = sys.argv[2]
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
22 if 'id' not in locals() or 'id' not in globals():
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
23 id = input("What is the ID for your show?: ")
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 try:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 temp = int(id)
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
26 except Exception:
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
27 print("Not a valid ID! Exiting.")
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 sys.exit()
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
30 # Scrapers
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
31 if source == 'tmdb':
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
32 # required because api is... odd
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
33 season = input("Which season do you want?: ")
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
34 try:
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
35 temp = int(season)
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
36 except Exception:
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
37 print("Not a valid season! Exiting.")
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
38 sys.exit()
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
39 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode())
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
40 amount = data["number_of_episodes"]
31
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
41 f = open("list.txt", "w", encoding="utf-8")
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
42 f.write("")
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
43 f.close()
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
44 count = 1
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
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
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
47 data = json.loads(url.read().decode())
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
48 f = open("list.txt", "a", encoding="utf-8")
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
49 f.write(data["name"].replace("?", "?").replace(
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
50 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
51 count += 1
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
52 f.close()
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
53 if source == 'mal':
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
54 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url:
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
55 data = json.loads(url.read().decode())
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
56 count = 0
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
57 f = open("list.txt", "w", encoding="utf-8")
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
58 f.write("")
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 f.close()
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
60 for i in range(len(data["episodes"])):
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
61 f = open("list.txt", "a", encoding="utf-8")
40
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
62 f.write(data["episodes"][count]["title"].replace("?", "?").replace(
Paper <mrpapersonic@gmail.com>
parents: 32
diff changeset
63 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
32
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
64 count += 1
fdbafd3e86d9 add tmdb to getlist.py
Paper <mrpapersonic@gmail.com>
parents: 31
diff changeset
65 f.close()