-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
131 lines (107 loc) · 3.56 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
120
121
122
123
124
125
126
127
128
129
130
131
from pytube import YouTube
import moviepy.editor as mp
import os
import pyfiglet
# Define variables
author_name = "Muhamad Iqbal Nurmanditya"
github_url = "https://github.com/iqbalmind"
linkedin_url = "https://www.linkedin.com/in/iqbalmind/"
text = "YTDLpython"
ascii_art = pyfiglet.figlet_format(text)
def main_menu():
print(ascii_art)
print("Welcome to the Python YouTube downloader!")
print("Please select an option:")
print("1. Download video")
print("2. Convert video to mp3")
print("3. Information")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
download_video()
main_menu() # Repeat the process
elif choice == "2":
convert_to_mp3()
main_menu() # Repeat the process
elif choice == "3":
info()
main_menu() # Repeat the process
elif choice == "4":
print("Goodbye!")
exit()
else:
print("Invalid choice.")
main_menu()
def download_video():
# Enter the YouTube video URL
url = input("Enter the YouTube video URL: ")
# Create a YouTube object
yt = YouTube(url)
# Display video information
print("Title:", yt.title)
print("Views:", yt.views)
# Select video resolution
print("Please select the video resolution:")
print("1. 360p")
print("2. 720p")
print("3. 1080p")
print("4. 2160p")
res_choice = input("Enter your choice (1-4): ")
# Get the video with the selected resolution
if res_choice == "1":
video = yt.streams.filter(res="360p").first()
elif res_choice == "2":
video = yt.streams.filter(res="720p").first()
elif res_choice == "3":
video = yt.streams.filter(res="1080p").first()
elif res_choice == "4":
video = yt.streams.filter(res="2160p").first()
else:
print("Invalid choice.")
return
# Download the video
print(f"Downloading {yt.title}...")
video.download()
pass
def convert_to_mp3():
# Convert the video to mp3
# Enter the YouTube video URL
url = input("Enter the YouTube video URL: ")
# Create a YouTube object
yt = YouTube(url)
# Display video information
print("Title:", yt.title)
print("Views:", yt.views)
print("Channel:", yt.author)
print("Published on:", yt.publish_date)
# Select video resolution
print("Please select the video resolution:")
print("1. 360p")
print("2. 720p")
print("3. 1080p")
print("4. 2160p")
res_choice = input("Enter your choice (1-4): ")
# Get the video with the selected resolution
if res_choice == "1":
video = yt.streams.filter(res="360p").first()
elif res_choice == "2":
video = yt.streams.filter(res="720p").first()
elif res_choice == "3":
video = yt.streams.filter(res="1080p").first()
elif res_choice == "4":
video = yt.streams.filter(res="2160p").first()
else:
print("Invalid choice.")
return
print("Converting video to mp3...")
clip = mp.VideoFileClip(video.default_filename)
clip.audio.write_audiofile(video.default_filename[:-4] + ".mp3")
pass
def info():
print("Author Name:", author_name)
print("GitHub URL:", github_url)
print("LinkedIn URL:", linkedin_url)
print("YTDLpython is a Python package that provides a simple way to download YouTube videos using the YouTube Data API. It uses the Pytube library under the hood to download videos and provides a command-line interface (CLI) for ease of use.")
input("Press Enter to continue...")
if __name__ == "__main__":
main_menu()