implemented options
This commit is contained in:
parent
76a91f57cb
commit
d8be349a40
@ -62,7 +62,7 @@ artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
|
||||
print_artist(artist)
|
||||
"""
|
||||
|
||||
results = EncyclopaediaMetallum.search_by_query("#a Ghost Bath")
|
||||
results = EncyclopaediaMetallum.search_by_query("#a Thy art is Murder")
|
||||
|
||||
artist = results[0]
|
||||
print(artist)
|
||||
|
28
src/music_kraken/objects/option.py
Normal file
28
src/music_kraken/objects/option.py
Normal file
@ -0,0 +1,28 @@
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .parents import DatabaseObject
|
||||
|
||||
|
||||
class Options:
|
||||
def __init__(self, option_list: List[DatabaseObject] = None):
|
||||
self._data: List[DatabaseObject] = option_list or list()
|
||||
|
||||
def __str__(self):
|
||||
return "\n".join(f"{i:02d}: {database_object.option_string}" for i, database_object in enumerate(self._data))
|
||||
|
||||
def __iter__(self):
|
||||
for database_object in self._data:
|
||||
yield database_object
|
||||
|
||||
def get_next_options(self, index: int) -> 'Options':
|
||||
if index >= len(self._data):
|
||||
raise ValueError("Index out of bounds")
|
||||
|
||||
return self._data[index].options
|
||||
|
||||
def __getitem__(self, item: int) -> 'Options':
|
||||
if type(item) != int:
|
||||
raise TypeError("Key needs to be an Integer")
|
||||
|
||||
return self.get_next_options(item)
|
@ -6,6 +6,7 @@ from ..utils.shared import (
|
||||
SONG_LOGGER as LOGGER
|
||||
)
|
||||
from .metadata import Metadata
|
||||
from .option import Options
|
||||
|
||||
|
||||
class DatabaseObject:
|
||||
@ -75,8 +76,8 @@ class DatabaseObject:
|
||||
return Metadata()
|
||||
|
||||
@property
|
||||
def option_list(self) -> List[Type['DatabaseObject']]:
|
||||
return [self]
|
||||
def options(self) -> Options:
|
||||
return Options([self])
|
||||
|
||||
@property
|
||||
def option_string(self) -> str:
|
||||
|
@ -27,6 +27,7 @@ from .collection import Collection
|
||||
from .album import AlbumType, AlbumStatus
|
||||
from .lyrics import Lyrics
|
||||
from .target import Target
|
||||
from .option import Options
|
||||
|
||||
"""
|
||||
All Objects dependent
|
||||
@ -136,15 +137,7 @@ class Song(MainObject):
|
||||
f"feat. Artist({OPTION_STRING_DELIMITER.join(artist.name for artist in self.feature_artist_collection)})"
|
||||
|
||||
@property
|
||||
def tracksort_str(self) -> str:
|
||||
"""
|
||||
if the album tracklist is empty, it sets it length to 1, this song has to be in the Album
|
||||
:returns id3_tracksort: {song_position}/{album.length_of_tracklist}
|
||||
"""
|
||||
return f"{self.tracksort}/{len(self.album.tracklist) or 1}"
|
||||
|
||||
@property
|
||||
def option_list(self) -> list:
|
||||
def options(self) -> Options:
|
||||
"""
|
||||
Return a list of related objects including the song object, album object, main artist objects, and feature artist objects.
|
||||
|
||||
@ -154,7 +147,15 @@ class Song(MainObject):
|
||||
options.extend(self.feature_artist_collection)
|
||||
options.extend(self.album_collection)
|
||||
options.append(self)
|
||||
return options
|
||||
return Options(options)
|
||||
|
||||
@property
|
||||
def tracksort_str(self) -> str:
|
||||
"""
|
||||
if the album tracklist is empty, it sets it length to 1, this song has to be in the Album
|
||||
:returns id3_tracksort: {song_position}/{album.length_of_tracklist}
|
||||
"""
|
||||
return f"{self.tracksort}/{len(self.album.tracklist) or 1}"
|
||||
|
||||
|
||||
"""
|
||||
@ -240,6 +241,14 @@ class Album(MainObject):
|
||||
f"by Artist({OPTION_STRING_DELIMITER.join([artist.name for artist in self.artist_collection])}) " \
|
||||
f"under Label({OPTION_STRING_DELIMITER.join([label.name for label in self.label_collection])})"
|
||||
|
||||
@property
|
||||
def options(self) -> Options:
|
||||
options = self.artist_collection.shallow_list
|
||||
options.append(self)
|
||||
options.extend(self.song_collection)
|
||||
|
||||
return Options(options)
|
||||
|
||||
def update_tracksort(self):
|
||||
"""
|
||||
This updates the tracksort attributes, of the songs in
|
||||
@ -298,14 +307,6 @@ class Album(MainObject):
|
||||
"""
|
||||
return len(self.artist_collection) > 1
|
||||
|
||||
@property
|
||||
def option_list(self) -> list:
|
||||
options = self.artist_collection.shallow_list
|
||||
options.append(self)
|
||||
options.extend(self.song_collection)
|
||||
|
||||
return options
|
||||
|
||||
|
||||
|
||||
|
||||
@ -395,6 +396,13 @@ class Artist(MainObject):
|
||||
return f"{self.__repr__()} " \
|
||||
f"under Label({OPTION_STRING_DELIMITER.join([label.name for label in self.label_collection])})"
|
||||
|
||||
@property
|
||||
def options(self) -> Options:
|
||||
options = [self]
|
||||
options.extend(self.main_album_collection)
|
||||
options.extend(self.feature_song_collection)
|
||||
return Options(options)
|
||||
|
||||
@property
|
||||
def country_string(self):
|
||||
return self.country.alpha_3
|
||||
@ -428,13 +436,6 @@ class Artist(MainObject):
|
||||
song_list=self.feature_song_collection.copy()
|
||||
)
|
||||
|
||||
@property
|
||||
def option_list(self) -> list:
|
||||
options = [self]
|
||||
options.extend(self.main_album_collection)
|
||||
options.extend(self.feature_song_collection)
|
||||
return options
|
||||
|
||||
def get_all_songs(self) -> List[Song]:
|
||||
"""
|
||||
returns a list of all Songs.
|
||||
@ -490,3 +491,9 @@ class Label(MainObject):
|
||||
('name', self.unified_name),
|
||||
*[('url', source.url) for source in self.source_collection]
|
||||
]
|
||||
|
||||
@property
|
||||
def options(self) -> Options:
|
||||
options = [self]
|
||||
options.extend(self.current_artist_collection.shallow_list)
|
||||
options.extend(self.album_collection.shallow_list)
|
Loading…
Reference in New Issue
Block a user