diff --git a/setup.cfg b/setup.cfg index aac58b462..387aec60d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -version = 3.9.1 +version = 3.9.2 name = spotdl url = https://github.com/spotDL/spotify-downloader diff --git a/spotdl/download/ffmpeg.py b/spotdl/download/ffmpeg.py index 01f74bfbb..a60748b61 100644 --- a/spotdl/download/ffmpeg.py +++ b/spotdl/download/ffmpeg.py @@ -69,16 +69,31 @@ async def convert( "flac": ["-codec:a", "flac"], "ogg": ["-codec:a", "libvorbis"], "opus": ["-vn", "-c:a", "copy"] - if downloaded_file_path.endswith(".opus") + if downloaded_file_path.endswith(".webm") else ["-c:a", "libopus"], "m4a": ["-codec:a", "aac", "-vn"], "wav": [], } + bitrates = { + "mp3": ["-q:a", "0"], + "flac": [], + "ogg": ["-q:a", "5"], + "opus": [] + if downloaded_file_path.endswith(".webm") + else ["-b:a", "160K"], + "m4a": [] + if downloaded_file_path.endswith(".m4a") + else ["-b:a", "160K"], + "wav": [], + } + if output_format is None: output_format_command = formats["mp3"] + output_bitrate = bitrates["mp3"] else: output_format_command = formats[output_format] + output_bitrate = bitrates[output_format] if ffmpeg_path is None: ffmpeg_path = "ffmpeg" @@ -89,8 +104,7 @@ async def convert( *output_format_command, "-abr", "true", - "-q:a", - "0", + *output_bitrate, "-v", "debug", converted_file_path, diff --git a/spotdl/search/song_gatherer.py b/spotdl/search/song_gatherer.py index b44b7f663..27437ea29 100644 --- a/spotdl/search/song_gatherer.py +++ b/spotdl/search/song_gatherer.py @@ -192,7 +192,10 @@ def get_tracks(track): ) if generate_m3u: - file_path = _parse_path_template(path_template, song, output_format) + if path_template: + file_path = _parse_path_template(path_template, song, output_format) + else: + file_path = _get_converted_file_path(song, output_format) return song, f"{file_path}\n" @@ -201,8 +204,11 @@ def get_tracks(track): return None, None except OSError: if generate_m3u: - song_obj = SongObject({*track}, album_response, {}, None, "", None) - file_path = _parse_path_template(path_template, song_obj, output_format) + song_obj = SongObject(track, album_response, {}, None, "", None) + if path_template: + file_path = _parse_path_template(path_template, song_obj, output_format) + else: + file_path = _get_converted_file_path(song_obj, output_format) return None, f"{file_path}\n" @@ -302,7 +308,10 @@ def get_song(track): ) if generate_m3u: - file_path = _parse_path_template(path_template, song, output_format) + if path_template: + file_path = _parse_path_template(path_template, song, output_format) + else: + file_path = _get_converted_file_path(song, output_format) return song, f"{file_path}\n" @@ -312,9 +321,12 @@ def get_song(track): except OSError: if generate_m3u: song_obj = SongObject( - {*track["track"]}, {}, {}, None, "", playlist_response + track["track"], {}, {}, None, "", playlist_response ) - file_path = _parse_path_template(path_template, song_obj, output_format) + if path_template: + file_path = _parse_path_template(path_template, song_obj, output_format) + else: + file_path = _get_converted_file_path(song_obj, output_format) return None, f"{file_path}\n"