From d88f349b6dd8e5f55ec8117ac7a339ae43b2ae83 Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Tue, 28 Sep 2021 18:09:55 -0700 Subject: [PATCH] WIP: Quality options for lossy conversion --- rip/config.toml | 4 ++-- streamrip/converter.py | 32 ++++++++++++++++++++++++++++++++ streamrip/utils.py | 1 - 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/rip/config.toml b/rip/config.toml index ca7451b..f649236 100644 --- a/rip/config.toml +++ b/rip/config.toml @@ -46,8 +46,6 @@ token_expiry = "" [deezer] # 0, 1, or 2 -# This only applies to paid Deezer subscriptions. Those using deezloader -# are automatically limited to quality = 1 quality = 2 # An authentication cookie that allows streamrip to use your Deezer account # See https://github.com/nathom/streamrip/wiki/Finding-Your-Deezer-ARL-Cookie @@ -97,6 +95,8 @@ sampling_rate = 48000 # Only 16 and 24 are available. It is only applied when the bit depth is higher # than this value. bit_depth = 24 +# Only applicable for lossy codecs +lossy_bitrate = 320 # Filter a Qobuz artist's discography. Set to 'true' to turn on a filter. [filters] diff --git a/streamrip/converter.py b/streamrip/converter.py index f390471..8aefbf4 100644 --- a/streamrip/converter.py +++ b/streamrip/converter.py @@ -172,11 +172,28 @@ class LAME(Converter): https://trac.ffmpeg.org/wiki/Encode/MP3 """ + __bitrate_map = { + 320: "-b:a 320k", + 245: "-q:a 0", + 225: "-q:a 1", + 190: "-q:a 2", + 175: "-q:a 3", + 165: "-q:a 4", + 130: "-q:a 5", + 115: "-q:a 6", + 100: "-q:a 7", + 85: "-q:a 8", + 65: "-q:a 9", + } + codec_name = "lame" codec_lib = "libmp3lame" container = "mp3" default_ffmpeg_arg = "-q:a 0" # V0 + def get_quality_arg(self, rate): + return self.__bitrate_map[rate] + class ALAC(Converter): """Class for ALAC converter.""" @@ -201,6 +218,15 @@ class Vorbis(Converter): container = "ogg" default_ffmpeg_arg = "-q:a 6" # 160, aka the "high" quality profile from Spotify + def get_quality_arg(self, rate: int) -> str: + arg = "qscale:a %d" + if rate <= 128: + return arg % (rate / 16 - 4) + if rate <= 256: + return arg % (rate / 32) + + return arg % (rate / 64 + 4) + class OPUS(Converter): """Class for libopus. @@ -216,6 +242,9 @@ class OPUS(Converter): container = "opus" default_ffmpeg_arg = "-b:a 128k" # Transparent + def get_quality_arg(self, rate: int) -> str: + pass + class AAC(Converter): """Class for libfdk_aac converter. @@ -230,3 +259,6 @@ class AAC(Converter): codec_lib = "libfdk_aac" container = "m4a" default_ffmpeg_arg = "-b:a 256k" + + def get_quality_arg(self, rate: int) -> str: + pass diff --git a/streamrip/utils.py b/streamrip/utils.py index 874b8ba..0ae90e3 100644 --- a/streamrip/utils.py +++ b/streamrip/utils.py @@ -349,7 +349,6 @@ def get_cover_urls(resp: dict, source: str) -> dict: resp_keys_fallback, ) } - print(cover_urls) if cover_urls["large"] is None and resp.get("cover_big") is not None: cover_urls["large"] = resp["cover_big"]