From 661e94ee77aaba89a15137ef8203de1d9a0de528 Mon Sep 17 00:00:00 2001 From: Lev Plyusnin Date: Sat, 3 May 2025 12:24:54 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B5=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- ymd/core.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dcce542..ad4436c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "yandex-music-downloader" -version = "3.4.5b1" +version = "3.4.6b0" description = "Загрузчик музыки с сервиса Яндекс.Музыка" requires-python = ">=3.9" readme = "README.md" diff --git a/ymd/core.py b/ymd/core.py index 8fcd46a..9a7d464 100644 --- a/ymd/core.py +++ b/ymd/core.py @@ -66,6 +66,13 @@ class LyricsFormat(LowercaseStrEnum): LRC = auto() +CONTAINER_MUTAGEN_MAPPING: dict[Container, type[mutagen.FileType]] = { # type: ignore + Container.MP3: MP3, + Container.FLAC: FLAC, + Container.MP4: MP4, +} + + @dataclass class DownloadableTrack: download_info: CustomDownloadInfo @@ -136,6 +143,7 @@ def prepare_base_path( def set_tags( path: Path, track: Track, + container: Container, lyrics: Optional[str], album_cover: Optional[AlbumCover], compatibility_level: int, @@ -143,7 +151,11 @@ def set_tags( album = track.albums[0] if track.albums else Album() track_artists = [a.name for a in track.artists if a.name] album_artists = [a.name for a in album.artists if a.name] - tag = mutagen.File(path, [MP3, MP4, FLAC]) # type: ignore + + file_type = CONTAINER_MUTAGEN_MAPPING.get(container) + if file_type is None: + raise ValueError(f"Unknown container: {container}") + tag = file_type(path) album_title = full_title(album) track_title = full_title(track) track_number = None @@ -313,7 +325,12 @@ def download_track( track_data, target_path, temporary_file_hook=lambda tmp_path: set_tags( - tmp_path, track, text_lyrics, cover, compatibility_level + tmp_path, + track, + download_info.file_format.container, + text_lyrics, + cover, + compatibility_level, ), )