From f970950aeaf7491949252cc02309912ffec57bf2 Mon Sep 17 00:00:00 2001 From: Hellow Date: Tue, 4 Apr 2023 17:59:08 +0200 Subject: [PATCH] added a description and removed redundant output of progressbar --- src/music_kraken/objects/target.py | 9 ++++----- src/music_kraken/pages/abstract.py | 4 ++-- src/music_kraken/pages/musify.py | 6 +++--- src/music_kraken/utils/shared.py | 3 +++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index a7e13aa..33a16d8 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -63,14 +63,12 @@ class Target(DatabaseObject): with open(copy_to.file_path, "wb") as write_to: write_to.write(read_from.read()) - def stream_into(self, r: requests.Response) -> bool: + def stream_into(self, r: requests.Response, desc: str = None) -> bool: if r is None: return False self.create_path() - chunk_size = 1024 - total_size = int(r.headers.get('content-length')) with open(self.file_path, 'wb') as f: @@ -79,8 +77,9 @@ class Target(DatabaseObject): https://en.wikipedia.org/wiki/Kilobyte > The internationally recommended unit symbol for the kilobyte is kB. """ - with tqdm(total=total_size, unit='B', unit_scale=True, unit_divisor=1024) as t: - for chunk in r.iter_content(chunk_size=chunk_size): + with tqdm(total=total_size, unit='B', unit_scale=True, unit_divisor=1024, desc=desc) as t: + + for chunk in r.iter_content(chunk_size=shared.CHUNK_SIZE): size = f.write(chunk) t.update(size) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 329aae0..7cb2d22 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -476,7 +476,7 @@ class Page: success = True - if not cls._download_song_to_targets(source=sources[0], target=temp_target): + if not cls._download_song_to_targets(source=sources[0], target=temp_target, desc=song.title): success = False if not cls._post_process_targets(song, temp_target): @@ -513,5 +513,5 @@ class Page: return None @classmethod - def _download_song_to_targets(cls, source: Source, target: Target) -> bool: + def _download_song_to_targets(cls, source: Source, target: Target, desc: str = None) -> bool: return False diff --git a/src/music_kraken/pages/musify.py b/src/music_kraken/pages/musify.py index df63a74..b61bc57 100644 --- a/src/music_kraken/pages/musify.py +++ b/src/music_kraken/pages/musify.py @@ -964,7 +964,7 @@ class Musify(Page): return None @classmethod - def _download_song_to_targets(cls, source: Source, target: Target) -> bool: + def _download_song_to_targets(cls, source: Source, target: Target, desc: str = None) -> bool: """ https://musify.club/track/im-in-a-coffin-life-never-was-waste-of-skin-16360302 https://musify.club/track/dl/16360302/im-in-a-coffin-life-never-was-waste-of-skin.mp3 @@ -975,5 +975,5 @@ class Musify(Page): return False endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3" - print(endpoint) - return target.stream_into(cls.get_request(endpoint, stream=True)) + + return target.stream_into(cls.get_request(endpoint, stream=True), desc=desc) diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index fd96492..f42778f 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -85,3 +85,6 @@ DEFAULT_VALUES = { "song": "Various Song", "album_type": "Other" } + +# size of the chunks that are streamed +CHUNK_SIZE = 1024