implemented fetching of artist overview

This commit is contained in:
2023-09-12 10:16:33 +02:00
parent 44fee8939b
commit b897e9844a
3 changed files with 77 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
import random
from collections import defaultdict
from typing import Optional, Dict, Tuple, List
from typing import Optional, Dict, Tuple, List, Type
from .metadata import Metadata
from .option import Options
@@ -129,6 +129,18 @@ class DatabaseObject:
self._build_recursive_structures(build_version=random.randint(0, 99999), merge=merge_into)
def _add_other_db_objects(self, object_type: Type["DatabaseObject"], object_list: List["DatabaseObject"]):
pass
def add_list_of_other_objects(self, object_list: List["DatabaseObject"]):
d: Dict[Type[DatabaseObject], List[DatabaseObject]] = defaultdict(list)
for db_object in object_list:
d[type(db_object)].append(db_object)
for key, value in d.items():
self._add_other_db_objects(key, value)
class MainObject(DatabaseObject):
"""

View File

@@ -1,6 +1,6 @@
import random
from collections import defaultdict
from typing import List, Optional, Dict, Tuple
from typing import List, Optional, Dict, Tuple, Type
import pycountry
@@ -109,6 +109,19 @@ class Song(MainObject):
artist.main_album_collection.append(album, merge_on_conflict=merge, merge_into_existing=False)
artist._build_recursive_structures(build_version=build_version, merge=merge)
def _add_other_db_objects(self, object_type: Type["DatabaseObject"], object_list: List["DatabaseObject"]):
if object_type is Song:
return
if object_type is Artist:
self.main_artist_collection.extend(object_list)
return
if object_type is Album:
self.album_collection.extend(object_list)
return
@property
def indexing_values(self) -> List[Tuple[str, object]]:
return [
@@ -280,6 +293,22 @@ class Album(MainObject):
label.album_collection.append(self, merge_on_conflict=merge, merge_into_existing=False)
label._build_recursive_structures(build_version=build_version, merge=merge)
def _add_other_db_objects(self, object_type: Type["DatabaseObject"], object_list: List["DatabaseObject"]):
if object_type is Song:
self.song_collection.extend(object_list)
return
if object_type is Artist:
self.artist_collection.extend(object_list)
return
if object_type is Album:
return
if object_type is Label:
self.label_collection.extend(object_list)
return
@property
def indexing_values(self) -> List[Tuple[str, object]]:
return [
@@ -483,6 +512,23 @@ class Artist(MainObject):
self.main_album_collection: Collection[Album] = Collection(data=main_album_list, element_type=Album)
self.label_collection: Collection[Label] = Collection(data=label_list, element_type=Label)
def _add_other_db_objects(self, object_type: Type["DatabaseObject"], object_list: List["DatabaseObject"]):
if object_type is Song:
# this doesn't really make sense
# self.feature_song_collection.extend(object_list)
return
if object_type is Artist:
return
if object_type is Album:
self.main_album_collection.extend(object_list)
return
if object_type is Label:
self.label_collection.extend(object_list)
return
def compile(self, merge_into: bool = False):
"""
compiles the recursive structures,
@@ -686,6 +732,18 @@ class Label(MainObject):
self.album_collection: Collection[Album] = Collection(data=album_list, element_type=Album)
self.current_artist_collection: Collection[Artist] = Collection(data=current_artist_list, element_type=Artist)
def _add_other_db_objects(self, object_type: Type["DatabaseObject"], object_list: List["DatabaseObject"]):
if object_type is Song:
return
if object_type is Artist:
self.current_artist_collection.extend(object_list)
return
if object_type is Album:
self.album_collection.extend(object_list)
return
def _build_recursive_structures(self, build_version: int, merge: False):
if build_version == self.build_version:
return