From 557f65aeccc9b6410915395d7cba4133857304ff Mon Sep 17 00:00:00 2001 From: Sergei Vasechko Date: Tue, 18 Mar 2025 18:58:14 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20=D1=87?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=20=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=BE=D0=BC=D0=B0=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=D0=B1=20=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=B1=D0=BE=D0=BC=D0=B5=20=D0=BD=D0=B5=D1=82=20?= =?UTF-8?q?=D0=B2=20=D0=BC=D0=B5=D1=82=D0=B0=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D1=82=D1=80=D0=B5=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit solve #85 solve #100 --- ymd/core.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ymd/core.py b/ymd/core.py index a07af8a..f29910a 100644 --- a/ymd/core.py +++ b/ymd/core.py @@ -29,6 +29,7 @@ from yandex_music import ( Client, Track, YandexMusicModel, + Album, ) from ymd import api @@ -84,10 +85,10 @@ def init_client(token: str, timeout: int) -> Client: return client.init() -def full_title(obj: YandexMusicModel) -> Optional[str]: +def full_title(obj: YandexMusicModel) -> str: result = obj["title"] if result is None: - return + return "" if version := obj["version"]: result += f" ({version})" return result @@ -139,7 +140,7 @@ def set_tags( album_cover: Optional[AlbumCover], compatibility_level: int, ) -> None: - album = track.albums[0] + 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 @@ -264,7 +265,6 @@ def download_track( track = track_info.track client = typing.cast(Client, track.client) assert client - album = track.albums[0] text_lyrics = None if lyrics_format != LyricsFormat.NONE and (lyrics_info := track.lyrics_info): @@ -291,12 +291,12 @@ def download_track( raise RuntimeError("Unknown cover mime type") album_cover = AlbumCover(data=cover_bytes, mime_type=mime_type) if embed_cover: - album_id = album.id - if album_id and (cached_cover := covers_cache.get(album_id)): + album = track.albums[0] if track.albums else Album() + if album.id and (cached_cover := covers_cache.get(album.id)): cover = cached_cover else: - if album_id: - cover = covers_cache[album_id] = album_cover + if album.id: + cover = covers_cache[album.id] = album_cover else: mime_suffix_dict = {MimeType.JPEG: ".jpg", MimeType.PNG: ".png"} file_suffix = mime_suffix_dict.get(album_cover.mime_type)