From 31f0981a3573d25f0c477e6f8dda8b9714237635 Mon Sep 17 00:00:00 2001 From: Jasper Aelvoet Date: Mon, 17 Oct 2022 21:15:25 +0200 Subject: [PATCH] Added download progress. --- classes/song.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/classes/song.py b/classes/song.py index fc1c249..06226c9 100644 --- a/classes/song.py +++ b/classes/song.py @@ -24,7 +24,6 @@ def __init__(self, song_id, out_dir, audio_quality, access_token, do_audio_norma for artist in track['artists'][1:]: self.track_artist += " & " + artist['name'] - self.album_name = track['album']['name'] self.track_name = track['name'] self.album_artist = track['album']['artists'][0]['name'] @@ -64,6 +63,9 @@ def normalize_audio_level(self): normalized_sound = self.match_target_amplitude(sound, -20.0) normalized_sound.export("temp_song.mp3", format="mp3", bitrate=self.audio_quality + 'k') + def progress(self, d): + self.status = d['_default_template'] + def download_song(self): self.status = "checking if already installed" out_name = f'{self.album_artist} - {self.track_name}' @@ -99,6 +101,7 @@ def download_song(self): 'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': self.audio_quality}], 'outtmpl': 'temp_song', + 'progress_hooks': [self.progress], } with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([video_link]) @@ -163,3 +166,22 @@ def download_song(self): time.sleep(0.1) self.successfully_installed = True return + + +class MyLogger: + def debug(self, msg): + # For compatibility with youtube-dl, both debug and info are passed into debug + # You can distinguish them by the prefix '[debug] ' + if msg.startswith('[debug] '): + print(msg) + else: + self.info(msg) + + def info(self, msg): + print(msg) + + def warning(self, msg): + print(msg) + + def error(self, msg): + print(msg)