added a description and removed redundant output of progressbar

This commit is contained in:
Hellow 2023-04-04 17:59:08 +02:00
parent afc3c859b0
commit f970950aea
4 changed files with 12 additions and 10 deletions

View File

@ -63,14 +63,12 @@ class Target(DatabaseObject):
with open(copy_to.file_path, "wb") as write_to: with open(copy_to.file_path, "wb") as write_to:
write_to.write(read_from.read()) 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: if r is None:
return False return False
self.create_path() self.create_path()
chunk_size = 1024
total_size = int(r.headers.get('content-length')) total_size = int(r.headers.get('content-length'))
with open(self.file_path, 'wb') as f: with open(self.file_path, 'wb') as f:
@ -79,8 +77,9 @@ class Target(DatabaseObject):
https://en.wikipedia.org/wiki/Kilobyte https://en.wikipedia.org/wiki/Kilobyte
> The internationally recommended unit symbol for the kilobyte is kB. > 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: 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=chunk_size):
for chunk in r.iter_content(chunk_size=shared.CHUNK_SIZE):
size = f.write(chunk) size = f.write(chunk)
t.update(size) t.update(size)

View File

@ -476,7 +476,7 @@ class Page:
success = True 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 success = False
if not cls._post_process_targets(song, temp_target): if not cls._post_process_targets(song, temp_target):
@ -513,5 +513,5 @@ class Page:
return None return None
@classmethod @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 return False

View File

@ -964,7 +964,7 @@ class Musify(Page):
return None return None
@classmethod @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/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 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 return False
endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3" 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)

View File

@ -85,3 +85,6 @@ DEFAULT_VALUES = {
"song": "Various Song", "song": "Various Song",
"album_type": "Other" "album_type": "Other"
} }
# size of the chunks that are streamed
CHUNK_SIZE = 1024