From 90b0d0ae20cdcb2951f71cd4fa3051007c0b39e2 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Wed, 5 Apr 2023 11:54:02 +0200 Subject: [PATCH] added total size --- src/actual_donwload.py | 2 +- src/music_kraken/objects/target.py | 11 +++++++++++ src/music_kraken/pages/abstract.py | 3 +++ .../pages/support_classes/download_result.py | 14 +++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/actual_donwload.py b/src/actual_donwload.py index 1b2fffe..610aa21 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -50,4 +50,4 @@ def real_download(): if __name__ == "__main__": - music_kraken.cli(genre=None) + music_kraken.cli(genre="test") diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index 319fd99..7fae49b 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -50,6 +50,17 @@ class Target(DatabaseObject): @property def exists(self) -> bool: return self.file_path.is_file() + + @property + def size(self) -> int: + """ + returns the size the downloaded autio takes up in bytes + returns 0 if the file doesn't exsit + """ + if not self.exists: + return 0 + + return self.file_path.stat().st_size def create_path(self): self._path.mkdir(parents=True, exist_ok=True) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 4cd7865..61e8269 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -539,6 +539,9 @@ class Page: if not r.is_fatal_error: cls._post_process_targets(song, temp_target) + for target in song.target_collection: + r.add_target(target) + return r @classmethod diff --git a/src/music_kraken/pages/support_classes/download_result.py b/src/music_kraken/pages/support_classes/download_result.py index a100aff..815b53a 100644 --- a/src/music_kraken/pages/support_classes/download_result.py +++ b/src/music_kraken/pages/support_classes/download_result.py @@ -2,6 +2,7 @@ from dataclasses import dataclass, field from typing import List from ...utils.shared import SHOW_DOWNLOAD_ERRORS_THRESHOLD, DOWNLOAD_LOGGER as LOGGER +from ...objects import Target @dataclass @@ -9,6 +10,7 @@ class DownloadResult: total: int = 0 fail: int = 0 error_message: str = None + total_size = 0 _error_message_list: List[str] = field(default_factory=list) @@ -38,6 +40,13 @@ class DownloadResult: return True return self.failure_percentage > SHOW_DOWNLOAD_ERRORS_THRESHOLD + + @property + def formated_size(self) -> str: + return f"{self.total_size}B" + + def add_target(self, target: Target): + self.total_size += target.size def merge(self, other: "DownloadResult"): if other.is_fatal_error: @@ -49,13 +58,16 @@ class DownloadResult: self.total += other.total self.fail += other.fail self._error_message_list.extend(other._error_message_list) + + self.total_size += other.total_size def __str__(self): if self.is_fatal_error: return self.error_message head = f"{self.fail} from {self.total} downloads failed:\n" \ f"successrate:\t{int(self.success_percentage*100)}%\n" \ - f"failrate:\t{int(self.failure_percentage*100)}%" + f"failrate:\t{int(self.failure_percentage*100)}%\n" \ + f"total size:\t{self.formated_size}" if not self.is_mild_failure: return head