From b4cc0955fde3cb773ba0c907e9384a3a65f73222 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:05:54 +0200 Subject: [PATCH] fix: fitted to file system --- src/music_kraken/objects/target.py | 13 +++++++------ src/music_kraken/utils/string_processing.py | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index 94cb2d8..ab405a4 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -7,6 +7,7 @@ from tqdm import tqdm from .parents import DatabaseObject from ..utils.config import main_settings, logging_settings +from ..utils.string_processing import fit_to_file_system LOGGER = logging.getLogger("target") @@ -35,8 +36,8 @@ class Target(DatabaseObject): relative_to_music_dir: bool = False ) -> None: super().__init__(dynamic=dynamic) - self._file: Path = Path(file) - self._path: Path = Path(main_settings["music_directory"], path) if relative_to_music_dir else Path(path) + self._file: Path = Path(fit_to_file_system(file)) + self._path: Path = fit_to_file_system(Path(main_settings["music_directory"], path) if relative_to_music_dir else Path(path)) self.is_relative_to_music_dir: bool = relative_to_music_dir @@ -58,8 +59,8 @@ class Target(DatabaseObject): @property def size(self) -> int: """ - returns the size the downloaded autio takes up in bytes - returns 0 if the file doesn't exsit + returns the size the downloaded audio takes up in bytes + returns 0 if the file doesn't exist """ if not self.exists: return 0 @@ -74,7 +75,7 @@ class Target(DatabaseObject): LOGGER.warning(f"No file exists at: {self.file_path}") return - with open(self.file_path, "rb") as read_from: + with self.open("rb") as read_from: copy_to.create_path() with open(copy_to.file_path, "wb") as write_to: write_to.write(read_from.read()) @@ -87,7 +88,7 @@ class Target(DatabaseObject): total_size = int(r.headers.get('content-length')) - with open(self.file_path, 'wb') as f: + with self.open('wb') as f: try: """ https://en.wikipedia.org/wiki/Kilobyte diff --git a/src/music_kraken/utils/string_processing.py b/src/music_kraken/utils/string_processing.py index e5dbb93..48f5f6d 100644 --- a/src/music_kraken/utils/string_processing.py +++ b/src/music_kraken/utils/string_processing.py @@ -27,12 +27,15 @@ def unify(string: str) -> str: def fit_to_file_system(string: str) -> str: string = string.strip() + string = string.strip(".") + """ while string[0] == ".": if len(string) == 0: return string string = string[1:] + """ string = string.replace("/", "_").replace("\\", "_")