2022-11-22 08:24:25 +00:00
|
|
|
from .utils.functions import *
|
2022-11-15 12:04:44 +00:00
|
|
|
from .utils.shared import *
|
|
|
|
|
2022-11-16 09:37:41 +00:00
|
|
|
from .metadata import (
|
|
|
|
metadata_search,
|
|
|
|
metadata_fetch
|
|
|
|
)
|
|
|
|
|
2022-11-16 09:15:35 +00:00
|
|
|
from .target import set_target
|
2022-11-15 12:04:44 +00:00
|
|
|
|
2022-11-16 09:37:41 +00:00
|
|
|
from .audio_source import (
|
|
|
|
fetch_source,
|
|
|
|
fetch_audio
|
|
|
|
)
|
|
|
|
|
|
|
|
from .lyrics import lyrics
|
|
|
|
|
|
|
|
# from .metadata.fetch import MetadataDownloader
|
|
|
|
# from .metadata import fetch
|
|
|
|
# from .metadata import search as s
|
|
|
|
# from .audio_source import fetch_source, fetch_audio
|
|
|
|
# from .target import set_target
|
|
|
|
|
2022-11-15 12:04:44 +00:00
|
|
|
# NEEDS REFACTORING
|
2022-11-16 09:37:41 +00:00
|
|
|
# from .lyrics.lyrics import fetch_lyrics
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
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 search_for_metadata():
|
2022-11-22 08:24:25 +00:00
|
|
|
clear_console()
|
|
|
|
|
2022-11-16 09:37:41 +00:00
|
|
|
search = metadata_search.Search()
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
input_ = input(
|
2022-11-22 08:24:25 +00:00
|
|
|
"""
|
|
|
|
- - - 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
|
|
|
|
|
|
|
|
command: """
|
|
|
|
)
|
|
|
|
|
|
|
|
match (input_.strip().lower()):
|
|
|
|
case "d" | "ok" | "dl" | "download":
|
|
|
|
break
|
|
|
|
case "q" | "quit" | "exit":
|
|
|
|
clear_console()
|
|
|
|
exit()
|
|
|
|
case "h" | "help":
|
|
|
|
print()
|
|
|
|
# TODO: Help text (mainly explaining query strings and alternative command functionalities)
|
|
|
|
print("Insert here help text....")
|
|
|
|
case inp if inp.isdigit():
|
|
|
|
print()
|
|
|
|
print(search.choose(int(input_)))
|
|
|
|
continue
|
|
|
|
case ".." :
|
|
|
|
print()
|
|
|
|
print(search.get_previous_options())
|
|
|
|
|
2022-11-15 12:04:44 +00:00
|
|
|
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):
|
2022-11-22 08:24:25 +00:00
|
|
|
clear_console()
|
|
|
|
|
2022-11-15 12:04:44 +00:00
|
|
|
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")
|
2022-11-16 09:37:41 +00:00
|
|
|
metadata_downloader = metadata_fetch.MetadataDownloader()
|
2022-11-15 12:04:44 +00:00
|
|
|
metadata_downloader.download({'type': search.type, 'id': search.id})
|
|
|
|
|
|
|
|
if start_at <= 1 and not only_lyrics:
|
|
|
|
logging.info("creating Paths")
|
2022-11-16 09:15:35 +00:00
|
|
|
set_target.UrlPath(genre=genre)
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
if start_at <= 2 and not only_lyrics:
|
|
|
|
logging.info("Fetching Download Links")
|
2022-11-16 09:15:35 +00:00
|
|
|
fetch_source.Download()
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
if start_at <= 3 and not only_lyrics:
|
|
|
|
logging.info("starting to download the mp3's")
|
2022-11-16 09:15:35 +00:00
|
|
|
fetch_audio.Download()
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
if start_at <= 4:
|
|
|
|
logging.info("starting to fetch the lyrics")
|
2022-11-16 09:37:41 +00:00
|
|
|
lyrics.fetch_lyrics()
|
2022-11-22 08:24:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def gtk_gui():
|
|
|
|
pass
|