started cli
This commit is contained in:
@@ -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 <any artist>
|
||||
searches for the artist <any artist>
|
||||
|
||||
> #a <any artist> #r <any releas>
|
||||
searches for the release (album) <any release> by the artist <any artist>
|
||||
|
||||
> #r <any release> Me #t <any track>
|
||||
searches for the track <any track> from the release <any relaese>
|
||||
"""
|
||||
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
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
# <table class="display table_lyrics
|
||||
|
||||
r = cls.API_SESSION.get(source.url)
|
||||
@@ -458,7 +454,7 @@ class EncyclopaediaMetallum(Page):
|
||||
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds
|
||||
|
||||
track: Song = album.tracklist.get_object_with_source(track_id) or album.tracklist.get_object_with_attribute("title", title)
|
||||
|
||||
|
||||
if track is not None:
|
||||
track.add_source(Source(cls.SOURCE_TYPE, track_id))
|
||||
track.length = length
|
||||
@@ -476,6 +472,7 @@ class EncyclopaediaMetallum(Page):
|
||||
]
|
||||
)
|
||||
|
||||
print(track)
|
||||
album.tracklist.append(track)
|
||||
|
||||
return album
|
||||
|
Reference in New Issue
Block a user