-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (35 loc) · 963 Bytes
/
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
# import the library
from pytube import YouTube # pip3 install pytube
import os
# loop for user to input the URL
user_in = True
list_url = [] # for collect the URL
url_count = 1
print("Enter the URL of the YouTube video you want to download :")
while user_in == True:
url = str(input(f" URL {url_count} :"))
url_count += 1
if url != "":
list_url.append(url)
elif url == "":
user_in = False
print()
print(f"preparing {len(list_url)} items")
# create a dir
try:
os.mkdir("mp3")
print()
except FileExistsError:
print()
# loop for download and save the file
for i in list_url:
yt = YouTube(i)
print("downloading")
video = yt.streams.filter(only_audio=True).first()
out_file = video.download("./mp3")
# save the file
base, ext = os.path.splitext(out_file)
new_file = base + ".mp3"
os.rename(out_file, new_file)
print(f"finish {list_url.index(i)+ 1} /{len(list_url)}")
print()