Отображение прогресса загрузки (#124)
--------- Co-authored-by: Lev Plyusnin <me@llistochek.ru>
This commit is contained in:
parent
5268b87e0d
commit
d9c40a394d
2 changed files with 21 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|||
|
||||
[project]
|
||||
name = "yandex-music-downloader"
|
||||
version = "3.5.2"
|
||||
version = "3.5.3"
|
||||
description = "Загрузчик музыки с сервиса Яндекс.Музыка"
|
||||
requires-python = ">=3.9"
|
||||
readme = "README.md"
|
||||
|
|
|
|||
23
ymd/cli.py
23
ymd/cli.py
|
|
@ -237,7 +237,7 @@ def main():
|
|||
max_try_count=args.tries,
|
||||
retry_delay=args.retry_delay,
|
||||
)
|
||||
result_tracks: Iterable[Track] = []
|
||||
result_tracks: Iterable[Track]
|
||||
|
||||
def album_tracks_gen(album_ids: Iterable[Union[int, str]]) -> Generator[Track]:
|
||||
for album_id in album_ids:
|
||||
|
|
@ -245,6 +245,7 @@ def main():
|
|||
if volumes := full_album.volumes:
|
||||
yield from itertools.chain.from_iterable(volumes)
|
||||
|
||||
total_track_count = None
|
||||
if args.artist_id is not None:
|
||||
|
||||
def filter_album(album: Album) -> bool:
|
||||
|
|
@ -276,14 +277,22 @@ def main():
|
|||
result_tracks = album_tracks_gen(
|
||||
a.id for a in albums_gen() if filter_album(a) and a.id is not None
|
||||
)
|
||||
artist = client.artists(args.artist_id)[0]
|
||||
if counts := artist.counts:
|
||||
total_track_count = counts.tracks
|
||||
|
||||
elif args.album_id is not None:
|
||||
result_tracks = album_tracks_gen((args.album_id,))
|
||||
if album := client.albums_with_tracks(args.album_id):
|
||||
total_track_count = album.track_count
|
||||
elif args.track_id is not None:
|
||||
track = client.tracks(args.track_id)
|
||||
result_tracks = track
|
||||
total_track_count = 1
|
||||
elif args.playlist_id is not None:
|
||||
user, kind = args.playlist_id.split("/")
|
||||
playlist = typing.cast(Playlist, client.users_playlists(kind, user))
|
||||
total_track_count = playlist.track_count
|
||||
|
||||
def playlist_tracks_gen() -> Generator[Track]:
|
||||
tracks = playlist.fetch_tracks()
|
||||
|
|
@ -293,11 +302,19 @@ def main():
|
|||
)
|
||||
|
||||
result_tracks = playlist_tracks_gen()
|
||||
else:
|
||||
raise ValueError("Invalid ID argument")
|
||||
|
||||
track_counter = 0
|
||||
progress_status = ""
|
||||
covers_cache = {}
|
||||
for track in result_tracks:
|
||||
if total_track_count:
|
||||
track_counter += 1
|
||||
progress_status = f"[{track_counter}/{total_track_count}] "
|
||||
|
||||
if not track.available:
|
||||
print(f"Трек {track.title} не доступен для скачивания")
|
||||
print(f"{progress_status}Трек {track.title} не доступен для скачивания")
|
||||
continue
|
||||
|
||||
save_path = args.dir / core.prepare_base_path(
|
||||
|
|
@ -321,7 +338,7 @@ def main():
|
|||
if bitrate > 0:
|
||||
format_info += f" {bitrate}kbps"
|
||||
format_info += "]"
|
||||
print(f"{format_info} Загружается {downloadable.path}")
|
||||
print(f"{progress_status}{format_info} Загружается {downloadable.path}")
|
||||
core.download_track(
|
||||
track_info=downloadable,
|
||||
lyrics_format=args.lyrics_format,
|
||||
|
|
|
|||
Loading…
Reference in a new issue