From 1dee95a7c4dac48d01d553503e9a75a540de40b4 Mon Sep 17 00:00:00 2001 From: Lev Plyusnin Date: Tue, 26 Nov 2024 20:32:33 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=82=D1=80=D0=B5=D0=BA=D0=BE=D0=B2=20=D1=81=20?= =?UTF-8?q?=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D1=83=D1=8E?= =?UTF-8?q?=D1=89=D0=B8=D0=BC=20=D0=B0=D0=BB=D1=8C=D0=B1=D0=BE=D0=BC=D0=BE?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- ymd/core.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 91b1e50..8366d8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "yandex-music-downloader" -version = "3.2.1b3" +version = "3.2.2b0" description = "Загрузчик музыки с сервиса Яндекс.Музыка" requires-python = ">=3.9" readme = "README.md" diff --git a/ymd/core.py b/ymd/core.py index a7fb1de..f5f1761 100644 --- a/ymd/core.py +++ b/ymd/core.py @@ -73,22 +73,29 @@ def prepare_base_path( path_pattern: Path, track: Track, unsafe_path: bool = False ) -> Path: path_str = str(path_pattern) - album = track.albums[0] - artist = album.artists[0] - track_position = album.track_position + album = None + artist = None + track_position = None + if albums := track.albums: + album = albums[0] + track_position = album.track_position + if artists := album.artists: + artist = artists[0] + if artist is None and (artists := track.artists): + artist = artists[0] repl_dict: dict[str, Union[str, int, None]] = { "#number-padded": str(track_position.index).zfill(len(str(album.track_count))) - if track_position + if track_position and album else None, - "#album-artist": album.artists[0].name, - "#artist-id": artist.name, - "#album-id": album.id, + "#album-artist": artist.name if artist else None, + "#artist-id": artist.id if artist else None, + "#album-id": album.id if album else None, "#track-id": track.id, "#number": track_position.index if track_position else None, - "#artist": artist.name, + "#artist": artist.name if artist else None, "#title": full_title(track), - "#album": full_title(album), - "#year": album.year, + "#album": full_title(album) if album else None, + "#year": album.year if album else None, } for placeholder, replacement in repl_dict.items(): replacement = str(replacement)