Исправление загрузки треков с отсутствующим альбомом

This commit is contained in:
Lev Plyusnin 2024-11-26 20:32:33 +07:00
parent f9cb171fef
commit 1dee95a7c4
No known key found for this signature in database
GPG key ID: 21C6C2C9C0A4460D
2 changed files with 18 additions and 11 deletions

View file

@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "yandex-music-downloader" name = "yandex-music-downloader"
version = "3.2.1b3" version = "3.2.2b0"
description = "Загрузчик музыки с сервиса Яндекс.Музыка" description = "Загрузчик музыки с сервиса Яндекс.Музыка"
requires-python = ">=3.9" requires-python = ">=3.9"
readme = "README.md" readme = "README.md"

View file

@ -73,22 +73,29 @@ def prepare_base_path(
path_pattern: Path, track: Track, unsafe_path: bool = False path_pattern: Path, track: Track, unsafe_path: bool = False
) -> Path: ) -> Path:
path_str = str(path_pattern) path_str = str(path_pattern)
album = track.albums[0] album = None
artist = album.artists[0] artist = None
track_position = album.track_position 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]] = { repl_dict: dict[str, Union[str, int, None]] = {
"#number-padded": str(track_position.index).zfill(len(str(album.track_count))) "#number-padded": str(track_position.index).zfill(len(str(album.track_count)))
if track_position if track_position and album
else None, else None,
"#album-artist": album.artists[0].name, "#album-artist": artist.name if artist else None,
"#artist-id": artist.name, "#artist-id": artist.id if artist else None,
"#album-id": album.id, "#album-id": album.id if album else None,
"#track-id": track.id, "#track-id": track.id,
"#number": track_position.index if track_position else None, "#number": track_position.index if track_position else None,
"#artist": artist.name, "#artist": artist.name if artist else None,
"#title": full_title(track), "#title": full_title(track),
"#album": full_title(album), "#album": full_title(album) if album else None,
"#year": album.year, "#year": album.year if album else None,
} }
for placeholder, replacement in repl_dict.items(): for placeholder, replacement in repl_dict.items():
replacement = str(replacement) replacement = str(replacement)