-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc0nv3rt3r.py
65 lines (47 loc) · 3.31 KB
/
c0nv3rt3r.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
from pytube import YouTube
from termcolor import colored
import os
def print_greet():
greet_text = """
██████╗ ██████╗ ███╗ ██╗██╗ ██╗██████╗ ██████╗ ████████╗██████╗ ██████╗
██╔════╝██╔═████╗████╗ ██║██║ ██║╚════██╗██╔══██╗╚══██╔══╝╚════██╗██╔══██╗
██║ ██║██╔██║██╔██╗ ██║██║ ██║ █████╔╝██████╔╝ ██║ █████╔╝██████╔╝
██║ ████╔╝██║██║╚██╗██║╚██╗ ██╔╝ ╚═══██╗██╔══██╗ ██║ ╚═══██╗██╔══██╗
╚██████╗╚██████╔╝██║ ╚████║ ╚████╔╝ ██████╔╝██║ ██║ ██║ ██████╔╝██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
created by: g4m3f4c3
"""
print(colored(greet_text, 'red'))
def print_video_info(video, filename):
duration = f"{round(video.length // 60, 2)}.{video.length % 60}"
print(colored(f"\nDownloading {filename}", 'cyan'))
print(colored(f"Duration: {duration} minutes", 'dark_grey'))
print(colored(f"View Count: {video.views}", 'dark_grey'))
print(colored(f"Published Date: {video.publish_date}", 'dark_grey'))
print(colored(f"Author: {video.author}", 'dark_grey'))
print(colored(f"Thumbnail Image URL: {video.thumbnail_url}", 'dark_grey'))
def run():
try:
output_directory = input(colored("Where would you like to download the file? Please enter a path or leave blank to download to Desktop: ", 'yellow')).strip()
# Set the output directory to desktop by default
if not output_directory:
output_directory = os.path.expanduser("~/Desktop").replace("/", "\\")
print(colored(f"Download path is set to: {output_directory}", 'dark_grey'))
while True:
url = input(colored("Please enter a Youtube URL: ", 'yellow')).strip()
video = YouTube(url)
filename = f"{video.author} - {video.title}.mp3"
print_video_info(video, filename)
stream = video.streams.filter(only_audio=True).first()
stream.download(output_path = output_directory, filename = filename)
print(colored(f"\nDownloaded {filename} successfully!", 'green'))
continue_download = input(colored("\nContinue? (y/n): ", 'magenta')).strip()
if continue_download == 'y':
continue
else:
print(colored("\nThanks for using the Youtube to MP3 Converter!", 'blue'))
break
except:
print("Unable to fetch video information. Please check the video URL or your network connection.")
print_greet()
run()