-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
119 lines (97 loc) Β· 3.8 KB
/
main.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
from urllib.parse import urlparse
from tqdm import tqdm
from imdb import IMDb
import requests
import os
webhook_url = ""
def startup():
if not os.path.exists('./downloads'):
os.mkdir('./downloads')
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
def dc_webhook(movie):
if webhook_url != "":
data = {
"content": f"Movie {movie} Finished Downloading",
}
response = requests.post(webhook_url, json=data)
if response.status_code == 204:
return True
else:
return False
else:
return False
def format_filename(name):
windows_nono_list = ['\\', '/', ':', '*', '?', '"', '<', '>', '|']
for nono in windows_nono_list:
name = name.replace(nono, ' ')
return name
def get_format(url):
parsed_url = urlparse(url)
path = parsed_url.path
filename = os.path.basename(path)
file_extension = os.path.splitext(filename)[1]
file_extension = file_extension.lstrip('.')
return file_extension
def search(title):
ia = IMDb()
movies = ia.search_movie(title)
print("\n")
for i in range(min(5, len(movies))):
print(f"{i + 1} - {movies[i]['title']} ({movies[i].get('year', 'N/A')})")
inp = int(input("\nChoose a movie: "))
if 1 <= inp <= min(5, len(movies)):
selected_movie = movies[inp - 1]
ia.update(selected_movie)
movie_id = selected_movie.movieID
print(f"\nπΏ {selected_movie['title']}:")
print(f" Rating: {selected_movie.get('rating', 'N/A')}")
print(f" Runtime: {selected_movie.get('runtimes', ['N/A'])[0]} min")
print(f" IMDb Link: https://www.imdb.com/title/tt{movie_id}/")
data = {"name" : f"{selected_movie['title']}","id": f"tt{movie_id}","year" : f"{selected_movie['year']}",}
name = f"{data['name']} ({data['year']}) [imdbid-{data['id']}]"
return name
elif inp == 0:
name = input("\nEnter a movie: ")
return name
else:
print("Invalid selection. Please choose a number from the list.")
return False
def download_video(url, fl):
print("\nπ₯ Downloading video...\n")
try:
filename = f"./downloads/{format_filename(fl)}"
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
with open(filename, 'wb') as f, tqdm(total=total_size, unit='B', unit_scale=True, desc=filename, ascii=True) as pbar:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
pbar.update(len(chunk))
print("\nβ
Download complete!\n")
dc_webhook(fl)
input()
except Exception:
print("\nβ Video Download Failed \n")
input()
def main():
print("\nββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
print("β π₯ Movie Downloader π₯ β")
print("β By Zombiebattler β")
print("β https://github.com/Zombiebattler β")
print("ββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
url = input("Enter movie URL: ")
data = search(input("Search movie name: "))
if data:
download_video(url, (f"{data['name']} ({data['year']}) [imdbid-{data['id']}].{get_format(url)}"))
else:
print("Error: Movie not found.")
if __name__ == '__main__':
try:
startup()
while True:
main()
input()
clear()
except Exception as e:
print(f"Critical Error:\n{e}")