-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZTV_Downloader.py
148 lines (109 loc) · 3.55 KB
/
EZTV_Downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import requests
import pandas as pd
from datetime import datetime
import webbrowser
def convert_size(bytes):
bytes = int(bytes)
if bytes > 1*10**9:
num = bytes/(1024**3)
return f"{round(num,2)} GB"
else:
num = bytes*0.00000095367432
return f"{round(num,2)} MB"
search = input("What show should I check? ")
selected_page = 1
with open("API_key.txt") as file:
key = file.read()
imdb_full = requests.get("http://www.omdbapi.com",
headers={"Accept": "application/json"},
params={"t": search, "apikey": key}).json()["imdbID"]
imdb = imdb_full[2:]
response_json = requests.get("https://eztv.io/api/get-torrents",
headers={"Accept": "application/json"},
params={"page": selected_page, "limit": 100, "imdb_id": imdb}).json()
size = len(response_json["torrents"])
titles = []
seasons = []
episodes = []
dates = []
magnets = []
sizes = []
numbers = [i for i in range(1, size+1)]
for item in response_json["torrents"]:
titles.append(item["title"])
seasons.append(item["season"])
episodes.append(item["episode"])
dates.append(datetime.utcfromtimestamp(
item["date_released_unix"]).strftime('%H:%M %d/%m/%Y'))
sizes.append(convert_size(item["size_bytes"]))
magnets.append(item["magnet_url"])
d = {"Number": numbers, 'Titles': titles[0:size], 'Season': seasons[0:size],
'Episode': episodes[0:size], 'Sizes': sizes[0:size], "Dates": dates[0:size], 'Links': magnets[0:size]}
df = pd.DataFrame(data=d)
df.set_index("Number")
def get_latest():
count = 0
new_sizes = []
latest = max(episodes)
for ep in episodes:
if ep != latest:
continue
count += 1
for s in sizes[0:count]:
if "M" in s:
y = s.replace(" MB", "")
new_sizes.append(float(y))
if "G" in s:
y = s.replace(" GB", "")
new_sizes.append(float(y)*1000)
maxim = max(new_sizes)
index = new_sizes.index(maxim)
webbrowser.open(df.iloc[index, 6])
def get_ep_seas(y, x):
indexes = []
indexes_old = []
temp_sizes = []
temp_sizes_old = []
new_sizes = []
for index, season in enumerate(seasons):
if int(season) == y:
indexes_old.append(index)
temp_sizes_old.append(sizes[index])
episodes_new = []
for i, j in zip(indexes_old, episodes):
episodes_new.append(episodes[i])
for index, ep in zip(indexes_old, episodes_new):
if int(ep) == x:
indexes.append(index)
temp_sizes.append(sizes[index])
for s in temp_sizes:
if "M" in s:
y = s.replace(" MB", "")
new_sizes.append(float(y))
if "G" in s:
y = s.replace(" GB", "")
new_sizes.append(float(y)*1000)
maxim = max(new_sizes)
if maxim > 1000:
maxim = str((float(maxim)/1000))+" GB"
else:
maxim = str(maxim) + " MB"
chosen = sizes.index(maxim)
webbrowser.open(df.iloc[chosen, 6])
def download():
x = ""
y = ""
while "stop" not in x or "stop" not in y:
y = input("Which Season? ")
x = input("Which Episode should I download? ")
try:
# new or latest for latest episode
if "new" in x or "latest" in x:
get_latest()
elif "new" in x or "latest" in y:
get_latest()
else:
get_ep_seas(int(y), int(x))
except:
print("An error has occured")
download()