From f56c133273d8bf2dff234b88b3075b0e2e76ec0d Mon Sep 17 00:00:00 2001 From: DraftKinner <196864209+DraftKinner@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:32:39 -0400 Subject: [PATCH] Fixed issue #18 --- zotify/app.py | 1 + zotify/file.py | 8 ++++++-- zotify/utils.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/zotify/app.py b/zotify/app.py index aacc26d..0cf1da1 100644 --- a/zotify/app.py +++ b/zotify/app.py @@ -384,6 +384,7 @@ class App: with Loader("Converting audio..."): file.transcode( self.__config.audio_format, + self.__config.download_quality, self.__config.transcode_bitrate, True, self.__config.ffmpeg_path, diff --git a/zotify/file.py b/zotify/file.py index e0f58c9..f40b47b 100644 --- a/zotify/file.py +++ b/zotify/file.py @@ -5,7 +5,7 @@ from subprocess import PIPE, Popen from music_tag import load_file from mutagen.oggvorbis import OggVorbisHeaderError -from zotify.utils import AudioFormat, MetadataEntry +from zotify.utils import AudioFormat, MetadataEntry, Quality class TranscodingError(RuntimeError): ... @@ -25,6 +25,7 @@ class LocalFile: def transcode( self, audio_format: AudioFormat | None = None, + download_quality: Quality | None = None, bitrate: int = -1, replace: bool = False, ffmpeg: str = "", @@ -63,7 +64,10 @@ class LocalFile: f"Cannot overwrite source, target file {path} already exists." ) - cmd.extend(["-b:a", str(bitrate) + "k"]) if bitrate > 0 else None + if bitrate > 0: + cmd.extend(["-b:a", str(bitrate) + "k"]) + else: + cmd.extend(["-b:a", str(Quality.get_bitrate(download_quality)) + "k"]) cmd.extend(["-c:a", audio_format.value.name]) if audio_format else None cmd.extend(opt_args) cmd.append(str(path)) diff --git a/zotify/utils.py b/zotify/utils.py index 3e27590..b263f54 100644 --- a/zotify/utils.py +++ b/zotify/utils.py @@ -59,6 +59,20 @@ class Quality(Enum): except Exception: return s + @staticmethod + def get_bitrate(quality): + match quality: + case Quality.NORMAL: + bitrate = 96 + case Quality.HIGH: + bitrate = 160 + case Quality.VERY_HIGH: + bitrate = 320 + case Quality.AUTO: + bitrate = 160 + + return bitrate + class ImageSize(IntEnum): SMALL = 0 # 64px