-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3.py
30 lines (23 loc) · 783 Bytes
/
mp3.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
# importing packages
from pytube import YouTube
import os
while True:
# url input from user
yt = YouTube(
str(input("Enter the URL of the video you want to download: \n>> ")))
# extract only audio
video = yt.streams.filter(only_audio=True).first()
# check for destination to save file
print("Enter the destination (leave blank for current directory)")
destination = str(input(">> ")) or 'Downloads'
# download the file
out_file = video.download(output_path=destination)
# save the file
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
# result of success
print(yt.title + " has been successfully downloaded.")
continue_operation = input("Would you like to continue? y/n: ")
if continue_operation == "n":
break