added total size
This commit is contained in:
parent
8e19c68e36
commit
90b0d0ae20
@ -50,4 +50,4 @@ def real_download():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
music_kraken.cli(genre=None)
|
music_kraken.cli(genre="test")
|
||||||
|
@ -51,6 +51,17 @@ class Target(DatabaseObject):
|
|||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.file_path.is_file()
|
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):
|
def create_path(self):
|
||||||
self._path.mkdir(parents=True, exist_ok=True)
|
self._path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
@ -539,6 +539,9 @@ class Page:
|
|||||||
if not r.is_fatal_error:
|
if not r.is_fatal_error:
|
||||||
cls._post_process_targets(song, temp_target)
|
cls._post_process_targets(song, temp_target)
|
||||||
|
|
||||||
|
for target in song.target_collection:
|
||||||
|
r.add_target(target)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -2,6 +2,7 @@ from dataclasses import dataclass, field
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from ...utils.shared import SHOW_DOWNLOAD_ERRORS_THRESHOLD, DOWNLOAD_LOGGER as LOGGER
|
from ...utils.shared import SHOW_DOWNLOAD_ERRORS_THRESHOLD, DOWNLOAD_LOGGER as LOGGER
|
||||||
|
from ...objects import Target
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -9,6 +10,7 @@ class DownloadResult:
|
|||||||
total: int = 0
|
total: int = 0
|
||||||
fail: int = 0
|
fail: int = 0
|
||||||
error_message: str = None
|
error_message: str = None
|
||||||
|
total_size = 0
|
||||||
|
|
||||||
_error_message_list: List[str] = field(default_factory=list)
|
_error_message_list: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
@ -39,6 +41,13 @@ class DownloadResult:
|
|||||||
|
|
||||||
return self.failure_percentage > SHOW_DOWNLOAD_ERRORS_THRESHOLD
|
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"):
|
def merge(self, other: "DownloadResult"):
|
||||||
if other.is_fatal_error:
|
if other.is_fatal_error:
|
||||||
LOGGER.debug(other.error_message)
|
LOGGER.debug(other.error_message)
|
||||||
@ -50,12 +59,15 @@ class DownloadResult:
|
|||||||
self.fail += other.fail
|
self.fail += other.fail
|
||||||
self._error_message_list.extend(other._error_message_list)
|
self._error_message_list.extend(other._error_message_list)
|
||||||
|
|
||||||
|
self.total_size += other.total_size
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.is_fatal_error:
|
if self.is_fatal_error:
|
||||||
return self.error_message
|
return self.error_message
|
||||||
head = f"{self.fail} from {self.total} downloads failed:\n" \
|
head = f"{self.fail} from {self.total} downloads failed:\n" \
|
||||||
f"successrate:\t{int(self.success_percentage*100)}%\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:
|
if not self.is_mild_failure:
|
||||||
return head
|
return head
|
||||||
|
Loading…
Reference in New Issue
Block a user