77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
import os
|
|
from urllib.parse import urlparse
|
|
from common import sanitize_filename, download_with_aria2c, download_file_with_progress, aria2c_exists
|
|
|
|
def show_movie_categories(movie_dict):
|
|
print("\nMovie Categories\n" + "*" * 30)
|
|
categories = sorted(movie_dict.keys())
|
|
for i, cat in enumerate(categories, 1):
|
|
print(f"{i}. {cat}")
|
|
try:
|
|
cat_index = int(input("\nSelect a category number: ").strip())
|
|
if 1 <= cat_index <= len(categories):
|
|
selected_category = categories[cat_index - 1]
|
|
movie_category_menu(movie_dict, selected_category)
|
|
except ValueError:
|
|
print("Invalid input.")
|
|
|
|
def movie_category_menu(movie_dict, category):
|
|
print(f"\nMovie Category: {category}\n{'*' * 30}")
|
|
movies = movie_dict[category]
|
|
for i, m in enumerate(movies, 1):
|
|
print(f"{i}. {m['title']}")
|
|
while True:
|
|
print("\nMovie Category Menu\n" + "*" * 30)
|
|
print(f"1. Download selected Movies from {category}")
|
|
print(f"2. Download ALL Movies from {category}")
|
|
print("3. Go back to Main Menu")
|
|
print("4. Exit")
|
|
choice = input("Select: ").strip()
|
|
if choice == '1':
|
|
selected = input_range("Enter movie numbers (e.g., 1,2,4-6): ", len(movies))
|
|
for idx in selected:
|
|
movie = movies[idx - 1]
|
|
download_movie(category, movie)
|
|
elif choice == '2':
|
|
for movie in movies:
|
|
download_movie(category, movie)
|
|
elif choice == '3':
|
|
return
|
|
elif choice == '4':
|
|
exit()
|
|
else:
|
|
print("Invalid choice.")
|
|
|
|
def input_range(prompt, max_val):
|
|
inp = input(prompt)
|
|
selected = set()
|
|
for part in inp.split(','):
|
|
if '-' in part:
|
|
start, end = map(int, part.split('-'))
|
|
selected.update(range(start, end + 1))
|
|
else:
|
|
selected.add(int(part))
|
|
return [i for i in selected if 1 <= i <= max_val]
|
|
|
|
def download_movie(category, movie):
|
|
title = sanitize_filename(movie['title'])
|
|
group = sanitize_filename(category)
|
|
base_dir = os.path.join("Movies", group, title)
|
|
os.makedirs(base_dir, exist_ok=True)
|
|
media_ext = os.path.splitext(movie['media_url'])[1]
|
|
media_path = os.path.join(base_dir, f"{title}{media_ext}")
|
|
if not os.path.exists(media_path) or os.path.getsize(media_path) < 5 * 1024 * 1024:
|
|
if aria2c_exists():
|
|
download_with_aria2c(movie['media_url'], media_path)
|
|
else:
|
|
download_file_with_progress(movie['media_url'], media_path, title)
|
|
else:
|
|
print(f"✔ Already downloaded: {title}")
|
|
if movie['logo_url']:
|
|
logo_filename = os.path.basename(urlparse(movie['logo_url']).path)
|
|
logo_path = os.path.join(base_dir, logo_filename)
|
|
if not os.path.exists(logo_path):
|
|
download_file_with_progress(movie['logo_url'], logo_path, f"{title} (logo)")
|
|
else:
|
|
print(f"✔ Logo exists for {title}")
|