Compare commits
3 Commits
adcf26b518
...
a70a24d93e
Author | SHA1 | Date | |
---|---|---|---|
a70a24d93e | |||
2c1ac0f12d | |||
897897dba2 |
@ -13,7 +13,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
song_2 = Song(
|
song_2 = Song(
|
||||||
title = "song",
|
title = "song",
|
||||||
main_artist_list=[other_artist]
|
artist_list=[other_artist]
|
||||||
)
|
)
|
||||||
|
|
||||||
other_artist.name = "main_artist"
|
other_artist.name = "main_artist"
|
||||||
|
@ -115,13 +115,7 @@ class Collection(Generic[T]):
|
|||||||
self._data.append(other)
|
self._data.append(other)
|
||||||
other._inner._is_in_collection.add(self)
|
other._inner._is_in_collection.add(self)
|
||||||
|
|
||||||
# all of the existing hooks to get the defined datastructures
|
"""
|
||||||
for collection_attribute, generator in self.extend_object_to_attribute.items():
|
|
||||||
other.__getattribute__(collection_attribute).extend(generator, **kwargs)
|
|
||||||
|
|
||||||
for attribute, new_object in self.append_object_to_attribute.items():
|
|
||||||
other.__getattribute__(attribute).append(new_object, **kwargs)
|
|
||||||
|
|
||||||
for attribute, a in self.sync_on_append.items():
|
for attribute, a in self.sync_on_append.items():
|
||||||
# syncing two collections by reference
|
# syncing two collections by reference
|
||||||
b = other.__getattribute__(attribute)
|
b = other.__getattribute__(attribute)
|
||||||
@ -140,6 +134,14 @@ class Collection(Generic[T]):
|
|||||||
a._collection_for[synced_with] = key
|
a._collection_for[synced_with] = key
|
||||||
|
|
||||||
a.extend(b_data, **kwargs)
|
a.extend(b_data, **kwargs)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# all of the existing hooks to get the defined datastructures
|
||||||
|
for collection_attribute, generator in self.extend_object_to_attribute.items():
|
||||||
|
other.__getattribute__(collection_attribute).extend(generator, **kwargs)
|
||||||
|
|
||||||
|
for attribute, new_object in self.append_object_to_attribute.items():
|
||||||
|
other.__getattribute__(attribute).append(new_object, **kwargs)
|
||||||
|
|
||||||
def append(self, other: Optional[T], **kwargs):
|
def append(self, other: Optional[T], **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -129,7 +129,7 @@ class Song(Base):
|
|||||||
source_list: List[Source] = None,
|
source_list: List[Source] = None,
|
||||||
target_list: List[Target] = None,
|
target_list: List[Target] = None,
|
||||||
lyrics_list: List[Lyrics] = None,
|
lyrics_list: List[Lyrics] = None,
|
||||||
main_artist_list: List[Artist] = None,
|
artist_list: List[Artist] = None,
|
||||||
feature_artist_list: List[Artist] = None,
|
feature_artist_list: List[Artist] = None,
|
||||||
album_list: List[Album] = None,
|
album_list: List[Album] = None,
|
||||||
tracksort: int = 0,
|
tracksort: int = 0,
|
||||||
@ -145,7 +145,10 @@ class Song(Base):
|
|||||||
TITEL = "title"
|
TITEL = "title"
|
||||||
|
|
||||||
def __init_collections__(self) -> None:
|
def __init_collections__(self) -> None:
|
||||||
self.album_collection.sync_on_append = {
|
self.feature_artist_collection.push_to = [self.artist_collection]
|
||||||
|
self.artist_collection.pull_from = [self.feature_artist_collection]
|
||||||
|
|
||||||
|
self.album_collection.extend_object_to_attribute = {
|
||||||
"artist_collection": self.artist_collection,
|
"artist_collection": self.artist_collection,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,15 +158,10 @@ class Song(Base):
|
|||||||
self.artist_collection.extend_object_to_attribute = {
|
self.artist_collection.extend_object_to_attribute = {
|
||||||
"album_collection": self.album_collection
|
"album_collection": self.album_collection
|
||||||
}
|
}
|
||||||
|
self.feature_artist_collection.extend_object_to_attribute = {
|
||||||
|
"album_collection": self.album_collection
|
||||||
self.album_collection.append_object_to_attribute = {
|
|
||||||
"artist_collection": self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.feature_artist_collection.push_to = [self.artist_collection]
|
|
||||||
self.artist_collection.pull_from = [self.feature_artist_collection]
|
|
||||||
|
|
||||||
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
|
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
|
||||||
if object_type is Song:
|
if object_type is Song:
|
||||||
return
|
return
|
||||||
@ -224,7 +222,7 @@ class Song(Base):
|
|||||||
r = OPTION_FOREGROUND.value + self.title_string + BColors.ENDC.value + OPTION_BACKGROUND.value
|
r = OPTION_FOREGROUND.value + self.title_string + BColors.ENDC.value + OPTION_BACKGROUND.value
|
||||||
r += get_collection_string(self.album_collection, " from {}", ignore_titles={self.title})
|
r += get_collection_string(self.album_collection, " from {}", ignore_titles={self.title})
|
||||||
r += get_collection_string(self.artist_collection, " by {}")
|
r += get_collection_string(self.artist_collection, " by {}")
|
||||||
r += get_collection_string(self.feature_artist_collection, " feat. {}")
|
r += get_collection_string(self.feature_artist_collection, " feat. {}" if len(self.artist_collection) > 0 else " by {}")
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -239,11 +237,6 @@ class Song(Base):
|
|||||||
return f"{self.tracksort}/{len(self.album_collection[0].song_collection) or 1}"
|
return f"{self.tracksort}/{len(self.album_collection[0].song_collection) or 1}"
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
All objects dependent on Album
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class Album(Base):
|
class Album(Base):
|
||||||
title: str
|
title: str
|
||||||
unified_title: str
|
unified_title: str
|
||||||
@ -311,10 +304,13 @@ class Album(Base):
|
|||||||
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", "artist_collection")
|
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", "artist_collection")
|
||||||
|
|
||||||
def __init_collections__(self):
|
def __init_collections__(self):
|
||||||
|
self.feature_artist_collection.push_to = [self.artist_collection]
|
||||||
|
self.artist_collection.pull_from = [self.feature_artist_collection]
|
||||||
|
|
||||||
self.song_collection.append_object_to_attribute = {
|
self.song_collection.append_object_to_attribute = {
|
||||||
"album_collection": self
|
"album_collection": self
|
||||||
}
|
}
|
||||||
self.song_collection.sync_on_append = {
|
self.song_collection.extend_object_to_attribute = {
|
||||||
"artist_collection": self.artist_collection
|
"artist_collection": self.artist_collection
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,6 +371,7 @@ class Album(Base):
|
|||||||
def option_string(self) -> str:
|
def option_string(self) -> str:
|
||||||
r = OPTION_FOREGROUND.value + self.title_string + BColors.ENDC.value + OPTION_BACKGROUND.value
|
r = OPTION_FOREGROUND.value + self.title_string + BColors.ENDC.value + OPTION_BACKGROUND.value
|
||||||
r += get_collection_string(self.artist_collection, " by {}")
|
r += get_collection_string(self.artist_collection, " by {}")
|
||||||
|
r += get_collection_string(self.feature_artist_collection, " feat. {}" if len(self.artist_collection) > 0 else " by {}")
|
||||||
r += get_collection_string(self.label_collection, " under {}")
|
r += get_collection_string(self.label_collection, " under {}")
|
||||||
|
|
||||||
if len(self.song_collection) > 0:
|
if len(self.song_collection) > 0:
|
||||||
@ -515,7 +512,7 @@ class Artist(Base):
|
|||||||
source_list: List[Source] = None,
|
source_list: List[Source] = None,
|
||||||
contact_list: List[Contact] = None,
|
contact_list: List[Contact] = None,
|
||||||
feature_song_list: List[Song] = None,
|
feature_song_list: List[Song] = None,
|
||||||
main_album_list: List[Album] = None,
|
album_list: List[Album] = None,
|
||||||
label_list: List[Label] = None,
|
label_list: List[Label] = None,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -529,6 +526,10 @@ class Artist(Base):
|
|||||||
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection",)
|
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection",)
|
||||||
|
|
||||||
def __init_collections__(self):
|
def __init_collections__(self):
|
||||||
|
self.album_collection.append_object_to_attribute = {
|
||||||
|
"feature_artist_collection": self
|
||||||
|
}
|
||||||
|
|
||||||
self.label_collection.append_object_to_attribute = {
|
self.label_collection.append_object_to_attribute = {
|
||||||
"current_artist_collection": self
|
"current_artist_collection": self
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class Bandcamp(Page):
|
|||||||
return Song(
|
return Song(
|
||||||
title=clean_song_title(name, artist_name=data["band_name"]),
|
title=clean_song_title(name, artist_name=data["band_name"]),
|
||||||
source_list=source_list,
|
source_list=source_list,
|
||||||
main_artist_list=[
|
artist_list=[
|
||||||
Artist(
|
Artist(
|
||||||
name=data["band_name"],
|
name=data["band_name"],
|
||||||
source_list=[
|
source_list=[
|
||||||
@ -370,7 +370,7 @@ class Bandcamp(Page):
|
|||||||
date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"),
|
date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"),
|
||||||
source_list=[Source(self.SOURCE_TYPE, album_data["@id"])]
|
source_list=[Source(self.SOURCE_TYPE, album_data["@id"])]
|
||||||
)],
|
)],
|
||||||
main_artist_list=[Artist(
|
artist_list=[Artist(
|
||||||
name=artist_data["name"].strip(),
|
name=artist_data["name"].strip(),
|
||||||
source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))]
|
source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))]
|
||||||
)],
|
)],
|
||||||
|
@ -52,7 +52,7 @@ def _song_from_json(artist_html=None, album_html=None, release_type=None, title=
|
|||||||
|
|
||||||
return Song(
|
return Song(
|
||||||
title=title,
|
title=title,
|
||||||
main_artist_list=[
|
artist_list=[
|
||||||
_artist_from_json(artist_html=artist_html)
|
_artist_from_json(artist_html=artist_html)
|
||||||
],
|
],
|
||||||
album_list=[
|
album_list=[
|
||||||
|
@ -143,7 +143,7 @@ class YouTube(SuperYouTube):
|
|||||||
self.SOURCE_TYPE, get_invidious_url(path="/watch", query=f"v={data['videoId']}")
|
self.SOURCE_TYPE, get_invidious_url(path="/watch", query=f"v={data['videoId']}")
|
||||||
)],
|
)],
|
||||||
notes=FormattedText(html=data["descriptionHtml"] + f"\n<p>{license_str}</ p>" ),
|
notes=FormattedText(html=data["descriptionHtml"] + f"\n<p>{license_str}</ p>" ),
|
||||||
main_artist_list=artist_list
|
artist_list=artist_list
|
||||||
), int(data["published"])
|
), int(data["published"])
|
||||||
|
|
||||||
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
|
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
|
||||||
@ -284,7 +284,7 @@ class YouTube(SuperYouTube):
|
|||||||
self.LOGGER.warning(f"didn't found any playlists with piped, falling back to invidious. (it is unusual)")
|
self.LOGGER.warning(f"didn't found any playlists with piped, falling back to invidious. (it is unusual)")
|
||||||
album_list, artist_name = self.fetch_invidious_album_list(parsed.id)
|
album_list, artist_name = self.fetch_invidious_album_list(parsed.id)
|
||||||
|
|
||||||
return Artist(name=artist_name, main_album_list=album_list, source_list=[source])
|
return Artist(name=artist_name, album_list=album_list, source_list=[source])
|
||||||
|
|
||||||
def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult:
|
def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult:
|
||||||
"""
|
"""
|
||||||
|
@ -58,6 +58,19 @@ def music_responsive_list_item_renderer(renderer: dict) -> List[DatabaseObject]:
|
|||||||
song.album_collection.extend(album_list)
|
song.album_collection.extend(album_list)
|
||||||
return [song]
|
return [song]
|
||||||
|
|
||||||
|
if len(album_list) == 1:
|
||||||
|
album = album_list[0]
|
||||||
|
album.artist_collection.extend(artist_list)
|
||||||
|
album.song_collection.extend(song_list)
|
||||||
|
return [album]
|
||||||
|
|
||||||
|
"""
|
||||||
|
if len(artist_list) == 1:
|
||||||
|
artist = artist_list[0]
|
||||||
|
artist.main_album_collection.extend(album_list)
|
||||||
|
return [artist]
|
||||||
|
"""
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -639,7 +639,7 @@ class YoutubeMusic(SuperYouTube):
|
|||||||
album_list=album_list,
|
album_list=album_list,
|
||||||
length=int(ydl_res.get("duration", 0)) * 1000,
|
length=int(ydl_res.get("duration", 0)) * 1000,
|
||||||
artwork=Artwork(*ydl_res.get("thumbnails", [])),
|
artwork=Artwork(*ydl_res.get("thumbnails", [])),
|
||||||
main_artist_list=artist_list,
|
artist_list=artist_list,
|
||||||
source_list=[Source(
|
source_list=[Source(
|
||||||
self.SOURCE_TYPE,
|
self.SOURCE_TYPE,
|
||||||
f"https://music.youtube.com/watch?v={ydl_res.get('id')}"
|
f"https://music.youtube.com/watch?v={ydl_res.get('id')}"
|
||||||
|
@ -12,7 +12,7 @@ if not load_dotenv(Path(__file__).parent.parent.parent / ".env"):
|
|||||||
|
|
||||||
__stage__ = os.getenv("STAGE", "prod")
|
__stage__ = os.getenv("STAGE", "prod")
|
||||||
|
|
||||||
DEBUG = (__stage__ == "dev") and False
|
DEBUG = (__stage__ == "dev") and True
|
||||||
DEBUG_LOGGING = DEBUG and False
|
DEBUG_LOGGING = DEBUG and False
|
||||||
DEBUG_TRACE = DEBUG and True
|
DEBUG_TRACE = DEBUG and True
|
||||||
DEBUG_OBJECT_TRACE = DEBUG and False
|
DEBUG_OBJECT_TRACE = DEBUG and False
|
||||||
|
@ -8,7 +8,7 @@ class TestCollection(unittest.TestCase):
|
|||||||
return Artist(
|
return Artist(
|
||||||
name="artist",
|
name="artist",
|
||||||
country=Country.by_alpha_2("DE"),
|
country=Country.by_alpha_2("DE"),
|
||||||
main_album_list=[
|
album_list=[
|
||||||
Album(
|
Album(
|
||||||
title="album",
|
title="album",
|
||||||
song_list=[
|
song_list=[
|
||||||
@ -73,7 +73,7 @@ class TestCollection(unittest.TestCase):
|
|||||||
def test_artist_artist_relation(self):
|
def test_artist_artist_relation(self):
|
||||||
artist = Artist(
|
artist = Artist(
|
||||||
name="artist",
|
name="artist",
|
||||||
main_album_list=[
|
album_list=[
|
||||||
Album(
|
Album(
|
||||||
title="album",
|
title="album",
|
||||||
song_list=[
|
song_list=[
|
||||||
@ -92,7 +92,7 @@ class TestCollection(unittest.TestCase):
|
|||||||
album_1 = Album(
|
album_1 = Album(
|
||||||
title="album",
|
title="album",
|
||||||
song_list=[
|
song_list=[
|
||||||
Song(title="song", main_artist_list=[Artist(name="artist")]),
|
Song(title="song", artist_list=[Artist(name="artist")]),
|
||||||
],
|
],
|
||||||
artist_list=[
|
artist_list=[
|
||||||
Artist(name="artist"),
|
Artist(name="artist"),
|
||||||
@ -102,7 +102,7 @@ class TestCollection(unittest.TestCase):
|
|||||||
album_2 = Album(
|
album_2 = Album(
|
||||||
title="album",
|
title="album",
|
||||||
song_list=[
|
song_list=[
|
||||||
Song(title="song", main_artist_list=[Artist(name="artist")]),
|
Song(title="song", artist_list=[Artist(name="artist")]),
|
||||||
],
|
],
|
||||||
artist_list=[
|
artist_list=[
|
||||||
Artist(name="artist"),
|
Artist(name="artist"),
|
||||||
|
Loading…
Reference in New Issue
Block a user