feat: implemented dynamic stuff OMG AAA
This commit is contained in:
parent
794732acee
commit
15841ee079
@ -52,7 +52,8 @@ only_smile = Artist(
|
|||||||
main_album_list=[
|
main_album_list=[
|
||||||
Album(
|
Album(
|
||||||
title="Few words...",
|
title="Few words...",
|
||||||
source_list=[Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/few-words")],
|
source_list=[
|
||||||
|
Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/few-words")],
|
||||||
song_list=[
|
song_list=[
|
||||||
Song(title="Everything will be fine"),
|
Song(title="Everything will be fine"),
|
||||||
Song(title="Only Smile"),
|
Song(title="Only Smile"),
|
||||||
@ -68,7 +69,8 @@ only_smile = Artist(
|
|||||||
),
|
),
|
||||||
Album(
|
Album(
|
||||||
title="Your best friend",
|
title="Your best friend",
|
||||||
source_list=[Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/your-best-friend")]
|
source_list=[
|
||||||
|
Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/your-best-friend")]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@ -78,7 +80,8 @@ only_smile = Artist(
|
|||||||
main_album_list=[
|
main_album_list=[
|
||||||
Album(
|
Album(
|
||||||
title="Few words...",
|
title="Few words...",
|
||||||
source_list=[Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/few-words")],
|
source_list=[
|
||||||
|
Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/few-words")],
|
||||||
song_list=[
|
song_list=[
|
||||||
Song(title="Everything will be fine"),
|
Song(title="Everything will be fine"),
|
||||||
Song(title="Only Smile"),
|
Song(title="Only Smile"),
|
||||||
@ -94,7 +97,8 @@ only_smile = Artist(
|
|||||||
),
|
),
|
||||||
Album(
|
Album(
|
||||||
title="Your best friend",
|
title="Your best friend",
|
||||||
source_list=[Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/your-best-friend")]
|
source_list=[
|
||||||
|
Source(SourcePages.BANDCAMP, "https://onlysmile.bandcamp.com/album/your-best-friend")]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -107,9 +111,9 @@ only_smile = Artist(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
objects_by_id = {}
|
objects_by_id = {}
|
||||||
|
|
||||||
|
|
||||||
def add_to_objects_dump(db_obj: DatabaseObject):
|
def add_to_objects_dump(db_obj: DatabaseObject):
|
||||||
objects_by_id[db_obj.id] = db_obj
|
objects_by_id[db_obj.id] = db_obj
|
||||||
|
|
||||||
@ -122,15 +126,10 @@ def add_to_objects_dump(db_obj: DatabaseObject):
|
|||||||
add_to_objects_dump(only_smile)
|
add_to_objects_dump(only_smile)
|
||||||
|
|
||||||
for _id, _object in objects_by_id.items():
|
for _id, _object in objects_by_id.items():
|
||||||
try:
|
print(_id, _object, sep=": ")
|
||||||
print(_id, _object.title, sep=": ")
|
|
||||||
except AttributeError:
|
|
||||||
try:
|
|
||||||
print(_id, _object.name, sep=": ")
|
|
||||||
except AttributeError:
|
|
||||||
print(_id, _object, sep=": ")
|
|
||||||
|
|
||||||
print(only_smile)
|
print(only_smile)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
c = Collection([Song(title="hi"), Song(title="hi2"), Song(title="hi3")])
|
c = Collection([Song(title="hi"), Song(title="hi2"), Song(title="hi3")])
|
||||||
c1 = Collection([Song(title="he"), Song(title="hi5")])
|
c1 = Collection([Song(title="he"), Song(title="hi5")])
|
||||||
|
@ -8,6 +8,8 @@ T = TypeVar('T', bound=OuterProxy)
|
|||||||
|
|
||||||
|
|
||||||
class Collection(Generic[T]):
|
class Collection(Generic[T]):
|
||||||
|
__is_collection__ = True
|
||||||
|
|
||||||
_data: List[T]
|
_data: List[T]
|
||||||
|
|
||||||
_indexed_values: Dict[str, set]
|
_indexed_values: Dict[str, set]
|
||||||
@ -54,7 +56,6 @@ class Collection(Generic[T]):
|
|||||||
self._indexed_values[name].add(value)
|
self._indexed_values[name].add(value)
|
||||||
self._indexed_to_objects[value].append(__object)
|
self._indexed_to_objects[value].append(__object)
|
||||||
|
|
||||||
print(from_map)
|
|
||||||
if not from_map:
|
if not from_map:
|
||||||
for attribute, new_object in self.contain_given_in_attribute.items():
|
for attribute, new_object in self.contain_given_in_attribute.items():
|
||||||
__object.__getattribute__(attribute).contain_collection_inside(new_object)
|
__object.__getattribute__(attribute).contain_collection_inside(new_object)
|
||||||
@ -181,14 +182,11 @@ class Collection(Generic[T]):
|
|||||||
self._data.append(__object)
|
self._data.append(__object)
|
||||||
|
|
||||||
def append(self, __object: Optional[T], already_is_parent: bool = False, from_map: bool = False):
|
def append(self, __object: Optional[T], already_is_parent: bool = False, from_map: bool = False):
|
||||||
if __object is None:
|
if __object is None or __object.id in self._contains_ids:
|
||||||
return
|
|
||||||
|
|
||||||
if __object.id in self._contains_ids:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
exists_in_collection = self._contained_in_sub(__object)
|
exists_in_collection = self._contained_in_sub(__object)
|
||||||
if len(exists_in_collection) and self is exists_in_collection[0]:
|
if len(exists_in_collection) > 0 and self is exists_in_collection[0]:
|
||||||
# assuming that the object already is contained in the correct collections
|
# assuming that the object already is contained in the correct collections
|
||||||
if not already_is_parent:
|
if not already_is_parent:
|
||||||
self.merge_into_self(__object, from_map=from_map)
|
self.merge_into_self(__object, from_map=from_map)
|
||||||
@ -259,5 +257,5 @@ class Collection(Generic[T]):
|
|||||||
return self.__len__() == 0
|
return self.__len__() == 0
|
||||||
|
|
||||||
def __iter__(self) -> Iterator[T]:
|
def __iter__(self) -> Iterator[T]:
|
||||||
for element in self._data:
|
for element in self.data:
|
||||||
yield element
|
yield element
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from collections import defaultdict
|
from functools import lru_cache
|
||||||
|
|
||||||
from typing import Optional, Dict, Tuple, List, Type, Generic, Any, TypeVar
|
from typing import Optional, Dict, Tuple, List, Type, Generic, Any, TypeVar
|
||||||
|
|
||||||
from .metadata import Metadata
|
from .metadata import Metadata
|
||||||
@ -87,12 +88,11 @@ class OuterProxy:
|
|||||||
if isinstance(data_list, list) and name.endswith("_list"):
|
if isinstance(data_list, list) and name.endswith("_list"):
|
||||||
collection_name = name.replace("_list", "_collection")
|
collection_name = name.replace("_list", "_collection")
|
||||||
|
|
||||||
if collection_name not in self.__dict__:
|
collection = self._inner.__getattribute__(collection_name)
|
||||||
continue
|
|
||||||
|
|
||||||
collection = self.__getattribute__(collection_name)
|
|
||||||
collection.extend(data_list)
|
collection.extend(data_list)
|
||||||
|
|
||||||
|
self._inner.__setattr__(collection_name, collection)
|
||||||
|
|
||||||
def __init_collections__(self):
|
def __init_collections__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -106,6 +106,9 @@ class OuterProxy:
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if __name.startswith("__"):
|
||||||
|
return super().__getattribute__(__name)
|
||||||
|
|
||||||
_inner: InnerData = super().__getattribute__("_inner")
|
_inner: InnerData = super().__getattribute__("_inner")
|
||||||
try:
|
try:
|
||||||
return _inner.__getattribute__(__name)
|
return _inner.__getattribute__(__name)
|
||||||
@ -174,3 +177,18 @@ class OuterProxy:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lru_cache()
|
||||||
|
def all_collections(self):
|
||||||
|
r = []
|
||||||
|
|
||||||
|
for key in self._default_factories:
|
||||||
|
val = self._inner.__getattribute__(key)
|
||||||
|
if hasattr(val, "__is_collection__"):
|
||||||
|
r.append(val)
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"{type(self).__name__}({', '.join(key + ': ' + str(val) for key, val in self.indexing_values)})"
|
||||||
|
@ -148,6 +148,7 @@ class Song(Base):
|
|||||||
return main_artists
|
return main_artists
|
||||||
return f"{main_artists} feat. {feature_artists}"
|
return f"{main_artists} feat. {feature_artists}"
|
||||||
|
|
||||||
|
"""
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
artist_credit_str = ""
|
artist_credit_str = ""
|
||||||
artist_credits = self.get_artist_credits()
|
artist_credits = self.get_artist_credits()
|
||||||
@ -155,6 +156,7 @@ class Song(Base):
|
|||||||
artist_credit_str = f" by {artist_credits}"
|
artist_credit_str = f" by {artist_credits}"
|
||||||
|
|
||||||
return f"\"{self.title}\"{artist_credit_str}"
|
return f"\"{self.title}\"{artist_credit_str}"
|
||||||
|
"""
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"Song(\"{self.title}\")"
|
return f"Song(\"{self.title}\")"
|
||||||
@ -519,6 +521,7 @@ class Artist(Base):
|
|||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
"""
|
||||||
def __str__(self, include_notes: bool = False):
|
def __str__(self, include_notes: bool = False):
|
||||||
string = self.name or ""
|
string = self.name or ""
|
||||||
if include_notes:
|
if include_notes:
|
||||||
@ -526,6 +529,7 @@ class Artist(Base):
|
|||||||
if plaintext_notes is not None:
|
if plaintext_notes is not None:
|
||||||
string += "\n" + plaintext_notes
|
string += "\n" + plaintext_notes
|
||||||
return string
|
return string
|
||||||
|
"""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Artist(\"{self.name}\")"
|
return f"Artist(\"{self.name}\")"
|
||||||
|
@ -33,11 +33,14 @@ class Source(OuterProxy):
|
|||||||
"audio_url": str,
|
"audio_url": str,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, page_enum: SourcePages, referer_page: SourcePages = None, **kwargs) -> None:
|
def __init__(self, page_enum: SourcePages, url: str, referer_page: SourcePages = None, audio_url: str = None, **kwargs) -> None:
|
||||||
if referer_page is None:
|
if referer_page is None:
|
||||||
referer_page = page_enum
|
referer_page = page_enum
|
||||||
|
|
||||||
super().__init__(page_enum=page_enum, referer_page=referer_page, **kwargs)
|
if audio_url is None:
|
||||||
|
audio_url = url
|
||||||
|
|
||||||
|
super().__init__(page_enum=page_enum, url=url, referer_page=referer_page, audio_url=audio_url, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def match_url(cls, url: str, referer_page: SourcePages) -> Optional["Source"]:
|
def match_url(cls, url: str, referer_page: SourcePages) -> Optional["Source"]:
|
||||||
|
Loading…
Reference in New Issue
Block a user