From 7c9d503bc69a58631026fde9b995eac24a4abd68 Mon Sep 17 00:00:00 2001 From: Lev Plyusnin Date: Tue, 17 Jun 2025 13:15:27 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D1=87=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=BF=D1=83=D1=89=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D1=82=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D0=BE=D0=B2=20=D0=B2=20=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- ymd/cli.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 07eaa73..ec0fd0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "yandex-music-downloader" -version = "3.5.3" +version = "3.5.4" description = "Загрузчик музыки с сервиса Яндекс.Музыка" requires-python = ">=3.9" readme = "README.md" diff --git a/ymd/cli.py b/ymd/cli.py index a134327..01dd1df 100644 --- a/ymd/cli.py +++ b/ymd/cli.py @@ -260,23 +260,30 @@ def main(): return True return False - def albums_gen() -> Generator[Album]: + def albums_id_gen() -> Generator[int]: has_next = True page = 0 while has_next: - if albums := client.artists_direct_albums(args.artist_id, page): - yield from albums.albums + if albums_info := client.artists_direct_albums(args.artist_id, page): + for album in albums_info.albums: + if filter_album(album): + assert album.id + yield album.id + else: + nonlocal total_track_count + if ( + track_count := album.track_count + ) and total_track_count is not None: + total_track_count -= track_count else: break - if pager := albums.pager: + if pager := albums_info.pager: page = pager.page + 1 has_next = pager.per_page * page < pager.total else: break - result_tracks = album_tracks_gen( - a.id for a in albums_gen() if filter_album(a) and a.id is not None - ) + result_tracks = album_tracks_gen(albums_id_gen()) artist = client.artists(args.artist_id)[0] if counts := artist.counts: total_track_count = counts.tracks