started cli
This commit is contained in:
parent
9efc806bec
commit
bf5d0458ca
@ -7,8 +7,7 @@ import os
|
|||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
database,
|
database,
|
||||||
not_used_anymore,
|
pages
|
||||||
target
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -46,76 +45,46 @@ SourcePages = database.SourcePages
|
|||||||
Target = database.Target
|
Target = database.Target
|
||||||
Lyrics = database.Lyrics
|
Lyrics = database.Lyrics
|
||||||
Album = database.Album
|
Album = database.Album
|
||||||
|
MusicObject = database.MusicObject
|
||||||
|
|
||||||
ID3Timestamp = database.ID3Timestamp
|
ID3Timestamp = database.ID3Timestamp
|
||||||
|
|
||||||
cache = database.cache
|
cache = database.cache
|
||||||
Database = database.Database
|
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:
|
def get_reference(self) -> Reference:
|
||||||
return Reference(self.id)
|
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)
|
id = property(fget=get_id)
|
||||||
reference = property(fget=get_reference)
|
reference = property(fget=get_reference)
|
||||||
|
|
||||||
|
@ -225,6 +225,17 @@ class Song(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
flat_copy.dynamic = True
|
flat_copy.dynamic = True
|
||||||
self._album.tracklist.append(flat_copy)
|
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)
|
tracksort_str = property(fget=get_tracksort_str)
|
||||||
album = property(fget=lambda self: self._album, fset=set_album)
|
album = property(fget=lambda self: self._album, fset=set_album)
|
||||||
|
|
||||||
@ -323,15 +334,6 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
map_attributes=["title"],
|
map_attributes=["title"],
|
||||||
element_type=Song
|
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:
|
def get_metadata(self) -> MetadataAttribute.Metadata:
|
||||||
return MetadataAttribute.Metadata({
|
return MetadataAttribute.Metadata({
|
||||||
@ -356,6 +358,19 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
|
|
||||||
return self.language.alpha_3
|
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)
|
copyright = property(fget=get_copyright)
|
||||||
iso_639_2_language = property(fget=get_iso_639_2_lang)
|
iso_639_2_language = property(fget=get_iso_639_2_lang)
|
||||||
@ -491,6 +506,17 @@ class Artist(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
|
|
||||||
return metadata
|
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)
|
discography: List[Album] = property(fget=get_discography)
|
||||||
features: Album = property(fget=get_features)
|
features: Album = property(fget=get_features)
|
||||||
songs: Album = property(fget=get_songs)
|
songs: Album = property(fget=get_songs)
|
||||||
|
@ -152,7 +152,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
source_list=[
|
source_list=[
|
||||||
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, artist_url)
|
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, artist_url)
|
||||||
],
|
],
|
||||||
notes=notes
|
notes=FormattedText(plaintext=notes)
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -358,9 +358,6 @@ class EncyclopaediaMetallum(Page):
|
|||||||
years active: 2012-present
|
years active: 2012-present
|
||||||
process this and add field to class
|
process this and add field to class
|
||||||
"""
|
"""
|
||||||
# print(title_text, data.text)
|
|
||||||
# print(data)
|
|
||||||
# print(band_stat_soup)
|
|
||||||
|
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
@ -420,7 +417,6 @@ class EncyclopaediaMetallum(Page):
|
|||||||
source = source_list[0]
|
source = source_list[0]
|
||||||
album_id = source.url.split("/")[-1]
|
album_id = source.url.split("/")[-1]
|
||||||
|
|
||||||
print(source)
|
|
||||||
# <table class="display table_lyrics
|
# <table class="display table_lyrics
|
||||||
|
|
||||||
r = cls.API_SESSION.get(source.url)
|
r = cls.API_SESSION.get(source.url)
|
||||||
@ -458,7 +454,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds
|
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)
|
track: Song = album.tracklist.get_object_with_source(track_id) or album.tracklist.get_object_with_attribute("title", title)
|
||||||
|
|
||||||
if track is not None:
|
if track is not None:
|
||||||
track.add_source(Source(cls.SOURCE_TYPE, track_id))
|
track.add_source(Source(cls.SOURCE_TYPE, track_id))
|
||||||
track.length = length
|
track.length = length
|
||||||
@ -476,6 +472,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(track)
|
||||||
album.tracklist.append(track)
|
album.tracklist.append(track)
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
@ -1,131 +1,5 @@
|
|||||||
import musicbrainzngs
|
import music_kraken
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
|
|
||||||
from music_kraken.utils.shared import (
|
|
||||||
MUSIC_DIR,
|
|
||||||
NOT_A_GENRE
|
|
||||||
)
|
|
||||||
from src.music_kraken.not_used_anymore.metadata import metadata_search, metadata_fetch
|
|
||||||
from music_kraken.target import set_target
|
|
||||||
from music_kraken.not_used_anymore import (
|
|
||||||
fetch_source,
|
|
||||||
fetch_audio
|
|
||||||
)
|
|
||||||
from music_kraken.lyrics import lyrics
|
|
||||||
|
|
||||||
|
|
||||||
def clear_console():
|
|
||||||
os.system('cls' if os.name in ('nt', 'dos') else 'clear')
|
|
||||||
|
|
||||||
logging.getLogger("musicbrainzngs").setLevel(logging.WARNING)
|
|
||||||
musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader")
|
|
||||||
|
|
||||||
|
|
||||||
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 = """
|
|
||||||
- - - Type the command you want to execute - - -
|
|
||||||
.. - 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
|
|
||||||
"""
|
|
||||||
print(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def search_for_metadata():
|
|
||||||
clear_console()
|
|
||||||
|
|
||||||
search = metadata_search.Search()
|
|
||||||
|
|
||||||
while True:
|
|
||||||
input_ = input("\"help\" for an overfiew of commands: ")
|
|
||||||
|
|
||||||
match (input_.strip().lower()):
|
|
||||||
case "d" | "ok" | "dl" | "download":
|
|
||||||
break
|
|
||||||
case "q" | "quit" | "exit":
|
|
||||||
clear_console()
|
|
||||||
exit()
|
|
||||||
case "h" | "help":
|
|
||||||
help_search_metadata()
|
|
||||||
continue
|
|
||||||
case inp if inp.isdigit():
|
|
||||||
print()
|
|
||||||
print(search.choose(int(input_)))
|
|
||||||
continue
|
|
||||||
case ".." :
|
|
||||||
print()
|
|
||||||
print(search.get_previous_options())
|
|
||||||
continue
|
|
||||||
|
|
||||||
print()
|
|
||||||
print(search.search_from_query(input_))
|
|
||||||
|
|
||||||
print(search.current_option)
|
|
||||||
return search.current_option
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
music_kraken.cli()
|
||||||
|
Loading…
Reference in New Issue
Block a user