WIP: Quality options for lossy conversion

This commit is contained in:
Nathan Thomas 2021-09-28 18:09:55 -07:00
parent 6bfa16076f
commit d88f349b6d
3 changed files with 34 additions and 3 deletions

View file

@ -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]

View file

@ -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

View file

@ -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"]