diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 6f60136..eeaebec 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -7,8 +7,7 @@ import os from . import ( database, - not_used_anymore, - target + pages ) @@ -46,76 +45,46 @@ SourcePages = database.SourcePages Target = database.Target Lyrics = database.Lyrics Album = database.Album +MusicObject = database.MusicObject ID3Timestamp = database.ID3Timestamp cache = database.cache Database = database.Database +def get_options_from_query(query: str) -> List[MusicObject]: + options = [] + for MetadataPage in pages.MetadataPages: + options.extend(MetadataPage.search_by_query(query=query)) + return options + +def get_options_from_option(option: MusicObject) -> List[MusicObject]: + print("fetching", option) + for MetadataPage in pages.MetadataPages: + option = MetadataPage.fetch_details(option, flat=False) + return option.get_options() + +def print_options(options: List[MusicObject]): + print("\n".join([f"{str(j).zfill(2)}: {i.get_option_string()}" for j, i in enumerate(options)])) + +def cli(): + options = [] + + while True: + command: str = input(">> ") + + if command.isdigit(): + option_index = int(command) + + if option_index >= len(options): + print(f"option {option_index} doesn't exist") + continue + + options = get_options_from_option(options[option_index]) + + else: + options = get_options_from_query(command) + + print_options(options) -def set_targets(genre: str): - target.set_target.UrlPath(genre=genre) - - -def fetch_sources(songs: List[Song], skip_existing_files: bool = True): - not_used_anymore.fetch_sources(songs=songs, skip_existing_files=skip_existing_files) - - -def fetch_audios(songs: List[Song], override_existing: bool = False): - not_used_anymore.fetch_audios(songs=songs, override_existing=override_existing) - - -def clear_cache(): - cache.init_db(reset_anyways=True) - -def get_existing_genre(): - valid_directories = [] - for elem in os.listdir(MUSIC_DIR): - if elem not in NOT_A_GENRE: - valid_directories.append(elem) - - return valid_directories - - -def help_search_metadata(): - msg = """ -- - - Available Options - - - -.. - Previous Options -(query_string) - Search for songs, albums, bands... -(int) - Select an item from the search results -d - Start the download -h - Help -q - Quit / Exit - -- - - How the Query works (examples) - - - -> #a -searches for the artist - -> #a #r -searches for the release (album) by the artist - -> #r Me #t -searches for the track from the release -""" - print(msg) - - - - -def get_genre(): - existing_genres = get_existing_genre() - print("printing available genres:") - for i, genre_option in enumerate(existing_genres): - print(f"{i}: {genre_option}") - - genre = input("Input the ID for an existing genre or text for a new one: ") - - if genre.isdigit(): - genre_id = int(genre) - if genre_id >= len(existing_genres): - logging.warning("An invalid genre id has been given") - return get_genre() - return existing_genres[genre_id] - - return genre diff --git a/src/music_kraken/database/objects/parents.py b/src/music_kraken/database/objects/parents.py index 6e104d8..da4903f 100644 --- a/src/music_kraken/database/objects/parents.py +++ b/src/music_kraken/database/objects/parents.py @@ -43,6 +43,24 @@ class DatabaseObject: def get_reference(self) -> Reference: return Reference(self.id) + def get_options(self) -> list: + """ + makes only sense in + - artist + - song + - album + """ + return [] + + def get_option_string(self) -> str: + """ + makes only sense in + - artist + - song + - album + """ + return "" + id = property(fget=get_id) reference = property(fget=get_reference) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index a32db30..51f286f 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -225,6 +225,17 @@ class Song(DatabaseObject, SourceAttribute, MetadataAttribute): flat_copy.dynamic = True self._album.tracklist.append(flat_copy) + def get_options(self) -> list: + options = self.main_artist_list.copy() + options.extend(self.feature_artist_list.copy()) + if self.album is not None: + options.append(self.album) + options.append(self) + return options + + def get_option_string(self) -> str: + return f"Song: {self.title}; Album: {self.album.title}; Artists: {self.get_artist_credits()}" + tracksort_str = property(fget=get_tracksort_str) album = property(fget=lambda self: self._album, fset=set_album) @@ -323,15 +334,6 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute): map_attributes=["title"], element_type=Song ) - - - def add_song(self, song: Song): - for existing_song in self._tracklist: - if existing_song == song: - return - - song.tracksort = len(self.tracklist) - self.tracklist.append(song) def get_metadata(self) -> MetadataAttribute.Metadata: return MetadataAttribute.Metadata({ @@ -356,6 +358,19 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute): return self.language.alpha_3 + def get_options(self) -> list: + options = self.artists.copy() + options.append(self) + for track in self.tracklist: + new_track: Song = copy.copy(track) + new_track.album = self + options.append(new_track) + + return options + + def get_option_string(self) -> str: + return f"Album: {self.title}; Artists {', '.join([i.name for i in self.artists])}" + copyright = property(fget=get_copyright) iso_639_2_language = property(fget=get_iso_639_2_lang) @@ -491,6 +506,17 @@ class Artist(DatabaseObject, SourceAttribute, MetadataAttribute): return metadata + def get_options(self) -> list: + options = [self] + for album in self.main_albums: + new_album: Album = copy.copy(album) + new_album.artists.append(self) + options.append(new_album) + return options + + def get_option_string(self) -> str: + return f"Artist: {self.name}" + discography: List[Album] = property(fget=get_discography) features: Album = property(fget=get_features) songs: Album = property(fget=get_songs) diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index cc6d39e..357a999 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -152,7 +152,7 @@ class EncyclopaediaMetallum(Page): source_list=[ Source(SourcePages.ENCYCLOPAEDIA_METALLUM, artist_url) ], - notes=notes + notes=FormattedText(plaintext=notes) ) @classmethod @@ -358,9 +358,6 @@ class EncyclopaediaMetallum(Page): years active: 2012-present process this and add field to class """ - # print(title_text, data.text) - # print(data) - # print(band_stat_soup) return artist @@ -420,7 +417,6 @@ class EncyclopaediaMetallum(Page): source = source_list[0] album_id = source.url.split("/")[-1] - print(source) # = len(existing_genres): - logging.warning("An invalid genre id has been given") - return get_genre() - return existing_genres[genre_id] - - return genre - - -def cli(start_at: int = 0, only_lyrics: bool = False, clear_console: bool = True): - if clear_console: - clear_console() - - if start_at <= 2 and not only_lyrics: - genre = get_genre() - logging.info(f"{genre} has been set as genre.") - - if start_at <= 0: - search = search_for_metadata() - # search = metadata.search.Option("release", "f8d4b24d-2c46-4e9c-8078-0c0f337c84dd", "Beautyfall") - logging.info("Starting Downloading of metadata") - metadata_downloader = metadata_fetch.MetadataDownloader() - metadata_downloader.download({'type': search.type, 'id': search.id}) - - if start_at <= 1 and not only_lyrics: - logging.info("creating Paths") - set_target.UrlPath(genre=genre) - - if start_at <= 2 and not only_lyrics: - logging.info("Fetching Download Links") - fetch_source.Download() - - if start_at <= 3 and not only_lyrics: - logging.info("starting to download the mp3's") - fetch_audio.Download() - - if start_at <= 4: - logging.info("starting to fetch the lyrics") - lyrics.fetch_lyrics() - +import music_kraken if __name__ == "__main__": - cli() + music_kraken.cli()