added total size
This commit is contained in:
parent
8e19c68e36
commit
90b0d0ae20
@ -50,4 +50,4 @@ def real_download():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
music_kraken.cli(genre=None)
|
||||
music_kraken.cli(genre="test")
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user