Skip to content

Commit

Permalink
Added download progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperaelvoet committed Oct 17, 2022
1 parent 56865ef commit 31f0981
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion classes/song.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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}'
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)

0 comments on commit 31f0981

Please sign in to comment.