implemented fetching of artist overview
This commit is contained in:
parent
44fee8939b
commit
b897e9844a
@ -1,6 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Optional, Dict, Tuple, List
|
from typing import Optional, Dict, Tuple, List, Type
|
||||||
|
|
||||||
from .metadata import Metadata
|
from .metadata import Metadata
|
||||||
from .option import Options
|
from .option import Options
|
||||||
@ -129,6 +129,18 @@ class DatabaseObject:
|
|||||||
|
|
||||||
self._build_recursive_structures(build_version=random.randint(0, 99999), merge=merge_into)
|
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):
|
class MainObject(DatabaseObject):
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import List, Optional, Dict, Tuple
|
from typing import List, Optional, Dict, Tuple, Type
|
||||||
|
|
||||||
import pycountry
|
import pycountry
|
||||||
|
|
||||||
@ -109,6 +109,19 @@ class Song(MainObject):
|
|||||||
artist.main_album_collection.append(album, merge_on_conflict=merge, merge_into_existing=False)
|
artist.main_album_collection.append(album, merge_on_conflict=merge, merge_into_existing=False)
|
||||||
artist._build_recursive_structures(build_version=build_version, merge=merge)
|
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
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
@ -280,6 +293,22 @@ class Album(MainObject):
|
|||||||
label.album_collection.append(self, merge_on_conflict=merge, merge_into_existing=False)
|
label.album_collection.append(self, merge_on_conflict=merge, merge_into_existing=False)
|
||||||
label._build_recursive_structures(build_version=build_version, merge=merge)
|
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
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
@ -483,6 +512,23 @@ class Artist(MainObject):
|
|||||||
self.main_album_collection: Collection[Album] = Collection(data=main_album_list, element_type=Album)
|
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)
|
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):
|
def compile(self, merge_into: bool = False):
|
||||||
"""
|
"""
|
||||||
compiles the recursive structures,
|
compiles the recursive structures,
|
||||||
@ -686,6 +732,18 @@ class Label(MainObject):
|
|||||||
self.album_collection: Collection[Album] = Collection(data=album_list, element_type=Album)
|
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)
|
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):
|
def _build_recursive_structures(self, build_version: int, merge: False):
|
||||||
if build_version == self.build_version:
|
if build_version == self.build_version:
|
||||||
return
|
return
|
||||||
|
@ -267,6 +267,8 @@ class YoutubeMusic(SuperYouTube):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
|
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
|
||||||
|
artist = Artist()
|
||||||
|
|
||||||
# construct the request
|
# construct the request
|
||||||
url = urlparse(source.url)
|
url = urlparse(source.url)
|
||||||
browse_id = url.path.replace("/channel/", "")
|
browse_id = url.path.replace("/channel/", "")
|
||||||
@ -280,7 +282,7 @@ class YoutubeMusic(SuperYouTube):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if r is None:
|
if r is None:
|
||||||
return Artist()
|
return artist
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
dump_to_file(f"{browse_id}.json", r.text, is_json=True, exit_after_dump=False)
|
dump_to_file(f"{browse_id}.json", r.text, is_json=True, exit_after_dump=False)
|
||||||
@ -301,9 +303,9 @@ class YoutubeMusic(SuperYouTube):
|
|||||||
for renderer in renderer_list:
|
for renderer in renderer_list:
|
||||||
results.extend(parse_renderer(renderer))
|
results.extend(parse_renderer(renderer))
|
||||||
|
|
||||||
print(results)
|
artist.add_list_of_other_objects(results)
|
||||||
|
|
||||||
return Artist()
|
return artist
|
||||||
|
|
||||||
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
|
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
|
||||||
print(source)
|
print(source)
|
||||||
|
Loading…
Reference in New Issue
Block a user