-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchMovieDowloader.py
More file actions
202 lines (185 loc) · 8.12 KB
/
batchMovieDowloader.py
File metadata and controls
202 lines (185 loc) · 8.12 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
try:
from bs4 import BeautifulSoup
import requests
import os
from tkinter import *
from tkinter import ttk, filedialog, messagebox
except:
os.system("pip install beautifulsoup4")
os.system("pip install requests")
os.system("pip install lxml")
headers = {'Accept-Language': 'en-US', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36'}
def getMovieNameYear(roughName):
name = roughName.replace(" ", "%20").lower()
tmdbUrl = f"https://www.themoviedb.org/search?query={name}"
request = requests.get(tmdbUrl, headers=headers)
soup = BeautifulSoup(request.content,"lxml")
searchResults = soup.find("h2")
if searchResults:
movieName = searchResults.get_text('h2')
# print(movieName)
searchResults = soup.find(class_="release_date")
movieYear = searchResults.get_text()
movieYear = movieYear[-4:]
if movieName.find("(") != -1:
n = movieName.find("(")
movieName = movieName[:n-3]
print(f"{movieName} Found On TMDB")
return [movieName, movieYear]
else:
name = roughName.replace("%20", " ").title()
if name.find("(") != -1:
n = name.find("(")
name = name[:n-4]
print(f"{name} Not Found On TMDB")
error.set(f"{name} Not Found On TMDB")
return [f"{name}", 0]
def getMovieTorrentLinks(name, date):
if " " in name:
name = name.replace(" ", "%20")
ytsSearchUrl = f"https://yts.mx/browse-movies/{name}/all/all/0/latest/{date}/all"
# print(ytsSearchUrl)
request = requests.get(ytsSearchUrl, headers=headers)
soup = BeautifulSoup(request.content, "lxml")
movieTitle = soup.find(class_="browse-movie-title")
if movieTitle:
movieLink = movieTitle.get("href")
requestTorrent = requests.get(movieLink, headers=headers)
torrentSoup = BeautifulSoup(requestTorrent.content, "lxml")
bottomInfo = torrentSoup.find(class_ = "bottom-info")
bottomInfo = bottomInfo.p
downloadLinks = bottomInfo.find_all("a")
downloadDict = {}
for results in downloadLinks:
quality = results.get_text()
link = results.get("href")
downloadDict[quality] = link
name = name.replace("%20", " ").title()
print(f"{name} Found On YTS, Torrent Added")
return downloadDict
else:
name = name.replace("%20", " ").title()
print(f"{name} Not Found On YTS" + f"|{ytsSearchUrl}")
error.set(f"{name} Not Found On YTS")
return {f"{name}": ytsSearchUrl}
def browseFiles():
filename = filedialog.askopenfilename(initialdir = "/", title = "Select the text file containing movie names",filetypes =[("Text Files", "*.txt")])
pathToFile_Entry.insert(0,filename)
def getMovieList(pathToFile, movieNames):
if not pathToFile:
movieNames = movieNames.replace(",", "\n")
contents = movieNames.strip()
movieList = []
movieList = contents.split("\n")
while "" in movieList:
movieList.remove("")
return movieList
else:
with open(pathToFile) as f:
contents = f.read()
movieNames = movieNames.replace(",", "")
contents = contents.strip() + "\n" + movieNames.strip()
movieList = []
movieList = contents.split("\n")
while "" in movieList:
movieList.remove("")
return movieList
def aria2Download(path, linkFile):
command = f'aria2c -d "{path}" -j 4 -i "{linkFile}" --seed-time=0 rpc-save-upload-metadata=false continue=true allow-overwrite=true bt-save-metadata=false seed-ratio=0'
os.system(command)
def execute():
pathFile = pathToFile.get()
if pathFile:
pathDir = os.path.dirname(pathFile)
else:
pathDir="."
movies = movieNames.get()
choice = choose.get()
if choice == "0":
error.set("Please Select Which Quality Torrent You Want")
elif (pathFile or movies) and choice != 0:
movieList = getMovieList(pathFile, movies)
linkList = []
failList =[]
namelist = []
for movie in movieList:
nameDate = getMovieNameYear(movie)
if nameDate[1] != 0:
quality = choice
links = getMovieTorrentLinks(nameDate[0],nameDate[1])
try:
if quality == "1080p":
try:
linkList.append(links[f"{quality}.BluRay"])
linkList.append("\n")
except KeyError:
linkList.append(links[f"{quality}.WEB"])
linkList.append("\n")
elif quality == "720p":
try:
linkList.append(links[f"{quality}.BluRay"])
linkList.append("\n")
except KeyError:
linkList.append(links[f"{quality}.WEB"])
linkList.append("\n")
except:
failList.append(f"#{links} No Download Link Found On YTS")
failList.append("\n")
else:
failList.append(f"#{nameDate[0]} Not Found On TMDb")
failList.append("\n")
path = writeToFile(linkList, pathDir, failList)
# if check.get() == 1:
# root.iconify()
# aria2Download(pathDir, path)
# pathDir = os.path.realpath(pathDir)
# done(f"\nMovies Downloaded to {pathDir}")
# elif check.get() == 2:
# getTorrents(linkList,namelist)
# pathDir = os.path.realpath(pathDir)
# done(f"\n Torrent Files Saved to {pathDir}")
# else:
# error.set("No Path Or Movie Name Found")
def writeToFile(linkList, pathToDir, failList):
with open(pathToDir+r"\Output.txt", "w") as f:
f.writelines(linkList)
f.writelines(failList)
return pathToDir+r"/Output.txt"
def getTorrents(linkList, nameList):
while "\n" in linkList:
linkList.remove("\n")
print(linkList)
for i in range(len(linkList)):
with open(f"{nameList[i]}.torrent", "wb") as f:
f.write(requests.get(linkList[i]).content)
def done(outputMessage):
return messagebox.showinfo(title=f"Done", detail=f'Your Task Has Been Completed.{outputMessage}', parent=mainframe)
root = Tk()
root.title("Batch Movie Downloader")
mainframe = ttk.Frame(root)
mainframe.grid(column=0, row=0)
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
movieNames = StringVar()
movieName_Label = ttk.Label(mainframe, text="Enter Movies Comma Seperated: ").grid(column=0, row=1, sticky=(N,S,E,W))
orLabel = ttk.Label(mainframe, text="Enter Path to File Or").grid(column=0, row=2, sticky=(N,S,E,W))
movieName_entry = ttk.Entry(mainframe, width=50, textvariable=movieNames)
movieName_entry.grid(column=3, row=1, sticky=(N,S,E,W))
movieName_entry.focus()
pathToFile = StringVar()
pathToFile_Entry = ttk.Entry(mainframe, width=50, textvariable=pathToFile)
pathToFile_Entry.grid(column=3, row=2 ,sticky=(N,S,E,W))
chooseFile = ttk.Button(mainframe, text="Choose File", command=browseFiles).grid(column=2, row=2, sticky=(N, S, W, E))
getLink = ttk.Button(mainframe, text="Execute", command=execute).grid(column=3, row=3,rowspan=2, sticky=(N, S, W, E))
error = StringVar()
errorPrompt = ttk.Label(mainframe,width=100, textvariable=error, foreground="red")
choose = StringVar(value="0")
seven20 = ttk.Radiobutton(mainframe, text="720p", variable=choose, value = "720p").grid(column=0, row=3, sticky=(W, E))
ten80 = ttk.Radiobutton(mainframe, text="1080p", variable=choose, value = "1080p").grid(column=0, row=4, sticky=(W, E))
check = IntVar()
AriaCheck = ttk.Checkbutton(mainframe, text="Aria2c In Environment Path", variable=check, onvalue=1).grid(column= 0, row=5, sticky=(W,E))
downloadTorrent = ttk.Checkbutton(mainframe, text="Download Torrent Files", variable=check, onvalue=2).grid(column= 0, row=6, sticky=(W,E))
check.set(0)
for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)
root.mainloop()