-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytdl.py
95 lines (77 loc) · 3.74 KB
/
ytdl.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
import subprocess
import os
import pyfiglet
from colorama import Fore, Back, Style, init
import time
# Initialize Colorama
init(autoreset=True)
def print_colored_logo():
# Generate ASCII art for the logo with a modern font
logo = pyfiglet.figlet_format("SRIEVi", font="slant")
# Center the logo in the terminal
terminal_width = os.get_terminal_size().columns
centered_logo = "\n".join(line.center(terminal_width) for line in logo.splitlines())
# Colors for the gradient effect (cyber-like appearance)
colors = [Fore.LIGHTCYAN_EX, Fore.CYAN, Fore.MAGENTA, Fore.LIGHTMAGENTA_EX, Fore.LIGHTGREEN_EX, Fore.LIGHTBLUE_EX]
# Apply a glowing effect to each character in the logo
print("\n") # Add spacing before the logo
for i, char in enumerate(centered_logo):
if char.strip(): # Apply color only to non-space characters
print(colors[i % len(colors)] + char, end='', flush=True)
time.sleep(0.03) # Slight delay to create a glowing effect
else:
print(char, end='', flush=True)
print("\n") # New line after the logo
def print_welcome():
# Call the function to print the colored logo
print_colored_logo()
# Welcome message
welcome_message = Fore.LIGHTGREEN_EX + "Welcome to the YouTube Playlist Downloader! \n"
terminal_width = os.get_terminal_size().columns
centered_message = welcome_message.center(terminal_width)
print(centered_message)
# Updated GitHub and social links
developer_info = Fore.LIGHTCYAN_EX + "Support us @eirsvi "
centered_developer = developer_info.center(terminal_width)
print(centered_developer)
social_links = Fore.LIGHTMAGENTA_EX + "GitHub | X | YouTube \n"
centered_social_links = social_links.center(terminal_width)
print(centered_social_links)
# Example URL without centering
example_url = Fore.LIGHTYELLOW_EX + "EXAMPLE PLAYLIST URL: https://www.youtube.com/playlist?list=PLXYZ123 \n"
print(example_url)
print() # Add an extra newline for spacing
def download_youtube_playlist():
# Call the welcome message function
print_welcome()
# Prompt user for the playlist URL
url = input(Fore.LIGHTCYAN_EX + "Enter the YouTube playlist URL: ")
# Prompt user to choose between video or audio download
choice = input(Fore.LIGHTMAGENTA_EX + "Do you want to download (v)ideo only or (a)udio only? (v/a): ").strip().lower()
# Define base output directory (e.g., ~/Downloads)
output_dir_base = os.path.expanduser('~/Downloads')
if choice == 'v':
# Create a folder to store only videos
output_dir = os.path.join(output_dir_base, 'YouTube_Videos')
os.makedirs(output_dir, exist_ok=True)
output_file = os.path.join(output_dir, '%(title)s.%(ext)s')
# Command to download the video playlist (only video)
command = ['yt-dlp', '-f', 'bestvideo+bestaudio/best', '-o', output_file, url]
elif choice == 'a':
# Create a folder to store only audios
output_dir = os.path.join(output_dir_base, 'YouTube_Audios')
os.makedirs(output_dir, exist_ok=True)
output_file = os.path.join(output_dir, '%(title)s.%(ext)s')
# Command to download the audio playlist (audio only as .mp3)
command = ['yt-dlp', '-x', '--audio-format', 'mp3', '-o', output_file, url]
else:
print(Fore.RED + "Invalid choice. Please select 'v' for video or 'a' for audio.")
return
try:
# Run the yt-dlp command
subprocess.run(command, check=True)
print(Fore.LIGHTGREEN_EX + f"Playlist downloaded successfully to: {output_dir}")
except subprocess.CalledProcessError as e:
print(Fore.RED + f"Error downloading playlist: {e}")
if __name__ == "__main__":
download_youtube_playlist()