fix: creation of target classes

This commit is contained in:
Hazel 2024-01-15 10:56:59 +01:00
parent f81720f01b
commit 99690068db
3 changed files with 19 additions and 15 deletions

View File

@ -63,6 +63,9 @@ class OuterProxy:
_default_factories: dict = {} _default_factories: dict = {}
_outer_attribute: Set[str] = {"options", "metadata", "indexing_values"} _outer_attribute: Set[str] = {"options", "metadata", "indexing_values"}
DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = tuple()
UPWARDS_COLLECTION_STRING_ATTRIBUTES = tuple()
def __init__(self, _id: int = None, dynamic: bool = False, **kwargs): def __init__(self, _id: int = None, dynamic: bool = False, **kwargs):
_automatic_id: bool = False _automatic_id: bool = False
@ -112,7 +115,7 @@ class OuterProxy:
:return: :return:
""" """
if __name.startswith("_") or __name in self._outer_attribute: if __name.startswith("_") or __name in self._outer_attribute or __name.isupper():
return object.__getattribute__(self, __name) return object.__getattribute__(self, __name)
_inner: InnerData = super().__getattribute__("_inner") _inner: InnerData = super().__getattribute__("_inner")

View File

@ -78,8 +78,6 @@ class Song(Base):
main_artist_list=main_artist_list, feature_artist_list=feature_artist_list, main_artist_list=main_artist_list, feature_artist_list=feature_artist_list,
album_list=album_list, **kwargs) album_list=album_list, **kwargs)
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("album_collection", "main_artist_collection", "feature_artist_collection") UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("album_collection", "main_artist_collection", "feature_artist_collection")
def __init_collections__(self) -> None: def __init_collections__(self) -> None:
@ -152,8 +150,6 @@ class Song(Base):
f"by Artist({OPTION_STRING_DELIMITER.join(artist.name for artist in self.main_artist_collection)}) " \ f"by Artist({OPTION_STRING_DELIMITER.join(artist.name for artist in self.main_artist_collection)}) " \
f"feat. Artist({OPTION_STRING_DELIMITER.join(artist.name for artist in self.feature_artist_collection)})" f"feat. Artist({OPTION_STRING_DELIMITER.join(artist.name for artist in self.feature_artist_collection)})"
@property @property
def options(self) -> List[P]: def options(self) -> List[P]:
options = self.main_artist_collection.shallow_list options = self.main_artist_collection.shallow_list
@ -225,7 +221,7 @@ class Album(Base):
source_list=source_list, artist_list=artist_list, song_list=song_list, label_list=label_list, source_list=source_list, artist_list=artist_list, song_list=song_list, label_list=label_list,
**kwargs) **kwargs)
DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("song_collection", ) DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("song_collection",)
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("artist_collection", "label_collection") UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("artist_collection", "label_collection")
def __init_collections__(self): def __init_collections__(self):
@ -425,7 +421,7 @@ class Artist(Base):
**kwargs) **kwargs)
DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("feature_song_collection", "main_album_collection") DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("feature_song_collection", "main_album_collection")
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", ) UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection",)
def __init_collections__(self): def __init_collections__(self):
self.feature_song_collection.append_object_to_attribute = { self.feature_song_collection.append_object_to_attribute = {
@ -585,7 +581,6 @@ Label
class Label(Base): class Label(Base):
COLLECTION_STRING_ATTRIBUTES = ("album_collection", "current_artist_collection") COLLECTION_STRING_ATTRIBUTES = ("album_collection", "current_artist_collection")
DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = COLLECTION_STRING_ATTRIBUTES DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = COLLECTION_STRING_ATTRIBUTES
name: str name: str

View File

@ -1,6 +1,7 @@
import logging import logging
import random import random
from copy import copy from copy import copy
from pathlib import Path
from typing import Optional, Union, Type, Dict, Set, List, Tuple from typing import Optional, Union, Type, Dict, Set, List, Tuple
from string import Formatter from string import Formatter
@ -363,8 +364,10 @@ class Page:
file_parts = Formatter().parse(main_settings["download_file"]) file_parts = Formatter().parse(main_settings["download_file"])
new_target = Target( new_target = Target(
relative_to_music_dir=True, relative_to_music_dir=True,
path=main_settings["download_path"].format(**{part[1]: naming_dict[part[1]] for part in path_parts}), file_path=Path(
file=main_settings["download_file"].format(**{part[1]: naming_dict[part[1]] for part in file_parts}) main_settings["download_path"].format(**{part[1]: naming_dict[part[1]] for part in path_parts}),
main_settings["download_file"].format(**{part[1]: naming_dict[part[1]] for part in file_parts})
)
) )
@ -376,8 +379,11 @@ class Page:
return DownloadResult(error_message=f"No source found for {song.title} as {self.__class__.__name__}.") return DownloadResult(error_message=f"No source found for {song.title} as {self.__class__.__name__}.")
temp_target: Target = Target( temp_target: Target = Target(
path=main_settings["temp_directory"], relative_to_music_dir=False,
file=str(random.randint(0, 999999)) file_path=Path(
main_settings["temp_directory"],
str(song.id)
)
) )
r = DownloadResult(1) r = DownloadResult(1)