Skip to content

Commit 44f0f38

Browse files
installed ffmpy and ffmpeg packages and wrote function to download playlist MP3
1 parent c3d8b65 commit 44f0f38

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

download.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import shutil
99
import ffmpy
1010

11+
1112
# functions
1213

1314

@@ -21,23 +22,23 @@ def download_1file_MP4():
2122
# get user path
2223
get_link = link_field.get()
2324
# get selected path
24-
user_path = path_label.cget("text")
25+
download_directory = path_label.cget("text")
2526
# Download video
2627
screen.title('Downloading ...')
2728
mp4_video = YouTube(get_link).streams.get_highest_resolution().download()
2829
vid_clip = VideoFileClip(mp4_video)
2930
vid_clip.close()
30-
shutil.move(mp4_video, user_path)
31+
shutil.move(mp4_video, download_directory)
3132
screen.title('Download complete! Download another file ..?')
3233

3334

3435
# download whole playlist in MP3 audio
3536
def download_playlist_MP4():
3637
print('Downloading playlist MP4 ...')
37-
screen.title('started downloading playlist ...')
38+
screen.title('started downloading playlist in MP4 ...')
3839
playlist_link = link_field.get()
3940
# get user path
40-
user_directory = path_label.cget('text')
41+
download_directory = path_label.cget('text')
4142
playlist = Playlist(playlist_link)
4243
# looping through each video
4344
for video in playlist.videos:
@@ -47,12 +48,34 @@ def download_playlist_MP4():
4748
video.streams.\
4849
filter(only_audio=True).\
4950
first().\
50-
download(user_directory)
51+
download(download_directory)
5152
print('finished downloading!')
5253

5354

5455
def download_playlist_MP3():
55-
print('Downloading playlist MP3 ...')
56+
screen.title('started downloading playlist in MP3')
57+
playlist_link = link_field.get()
58+
59+
playlist = Playlist(playlist_link)
60+
download_directory = path_label.cget('text')
61+
62+
for video in playlist.videos:
63+
print('Downloading playlist MP3 ...')
64+
audio = video.streams.get_audio_only()
65+
audio.download(download_directory)
66+
67+
video_title = video.title
68+
69+
new_filename = video_title + '.mp3'
70+
default_filename = video_title + '.mp4'
71+
72+
print('from' + default_filename + 'to' + new_filename)
73+
ff = ffmpy.FFmpeg(
74+
inputs={default_filename: None},
75+
outputs={new_filename: None}
76+
)
77+
78+
ff.run()
5679

5780

5881
# styling

0 commit comments

Comments
 (0)