2022-11-14 11:32:31 +00:00
|
|
|
from .utils.shared import *
|
2022-11-11 23:29:07 +00:00
|
|
|
|
2022-11-14 11:32:31 +00:00
|
|
|
from .metadata.download import MetadataDownloader
|
|
|
|
from .metadata import download
|
|
|
|
from .metadata import search as s
|
|
|
|
from . import download_links
|
|
|
|
from . import url_to_path
|
|
|
|
from . import download
|
2022-10-21 19:24:38 +00:00
|
|
|
|
2022-11-09 21:52:32 +00:00
|
|
|
# NEEDS REFACTORING
|
2022-11-14 11:32:31 +00:00
|
|
|
from .lyrics_ import fetch_lyrics
|
2022-11-09 21:52:32 +00:00
|
|
|
|
2022-10-17 17:28:33 +00:00
|
|
|
import logging
|
2022-10-21 19:24:38 +00:00
|
|
|
import os
|
2022-11-06 22:01:03 +00:00
|
|
|
|
2022-11-11 11:12:04 +00:00
|
|
|
# configure logger default
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
|
|
|
handlers=[
|
|
|
|
logging.FileHandler(os.path.join(temp_dir, LOG_FILE)),
|
|
|
|
logging.StreamHandler()
|
|
|
|
]
|
|
|
|
)
|
2022-11-09 07:22:28 +00:00
|
|
|
|
2022-10-14 14:55:23 +00:00
|
|
|
|
2022-10-24 11:11:32 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-11-07 21:59:16 +00:00
|
|
|
def search_for_metadata():
|
2022-11-14 11:32:31 +00:00
|
|
|
search = s.Search()
|
2022-10-14 14:55:23 +00:00
|
|
|
|
|
|
|
while True:
|
2022-10-17 17:28:33 +00:00
|
|
|
input_ = input(
|
2022-11-07 21:59:16 +00:00
|
|
|
"q to quit, .. for previous options, int for this element, str to search for query, ok to download\n")
|
2022-10-14 14:55:23 +00:00
|
|
|
input_.strip()
|
2022-11-07 21:59:16 +00:00
|
|
|
if input_.lower() == "ok":
|
|
|
|
break
|
|
|
|
if input_.lower() == "q":
|
|
|
|
break
|
|
|
|
if input_.lower() == "..":
|
2022-11-08 09:39:27 +00:00
|
|
|
print()
|
2022-10-14 14:55:23 +00:00
|
|
|
print(search.get_previous_options())
|
|
|
|
continue
|
|
|
|
if input_.isdigit():
|
2022-11-08 09:39:27 +00:00
|
|
|
print()
|
2022-10-14 14:55:23 +00:00
|
|
|
print(search.choose(int(input_)))
|
|
|
|
continue
|
2022-11-08 09:39:27 +00:00
|
|
|
print()
|
|
|
|
print(search.search_from_query(input_))
|
2022-10-14 14:55:23 +00:00
|
|
|
|
2022-11-10 09:01:26 +00:00
|
|
|
print(search.current_option)
|
2022-11-07 21:59:16 +00:00
|
|
|
return search.current_option
|
2022-10-14 14:55:23 +00:00
|
|
|
|
2022-11-09 21:52:32 +00:00
|
|
|
|
2022-10-24 11:11:32 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-11-13 19:27:56 +00:00
|
|
|
def cli(start_at: int = 0, only_lyrics: bool = False):
|
|
|
|
if start_at <= 2 and not only_lyrics:
|
2022-10-24 11:11:32 +00:00
|
|
|
genre = get_genre()
|
|
|
|
logging.info(f"{genre} has been set as genre.")
|
2022-10-18 16:48:24 +00:00
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 0:
|
2022-11-10 09:03:04 +00:00
|
|
|
search = search_for_metadata()
|
|
|
|
# search = metadata.search.Option("release", "f8d4b24d-2c46-4e9c-8078-0c0f337c84dd", "Beautyfall")
|
2022-10-21 21:50:18 +00:00
|
|
|
logging.info("Starting Downloading of metadata")
|
2022-11-11 23:29:07 +00:00
|
|
|
metadata_downloader = MetadataDownloader()
|
|
|
|
metadata_downloader.download({'type': search.type, 'id': search.id})
|
2022-10-14 14:55:23 +00:00
|
|
|
|
2022-11-13 19:27:56 +00:00
|
|
|
if start_at <= 1 and not only_lyrics:
|
2022-10-21 21:50:18 +00:00
|
|
|
logging.info("creating Paths")
|
2022-11-11 23:29:07 +00:00
|
|
|
url_to_path.UrlPath(genre=genre)
|
2022-10-17 22:27:30 +00:00
|
|
|
|
2022-11-13 19:27:56 +00:00
|
|
|
if start_at <= 2 and not only_lyrics:
|
2022-11-08 10:30:54 +00:00
|
|
|
logging.info("Fetching Download Links")
|
2022-11-11 23:29:07 +00:00
|
|
|
download_links.Download()
|
2022-10-17 12:56:32 +00:00
|
|
|
|
2022-11-13 19:27:56 +00:00
|
|
|
if start_at <= 3 and not only_lyrics:
|
2022-10-21 21:50:18 +00:00
|
|
|
logging.info("starting to download the mp3's")
|
2022-11-11 23:29:07 +00:00
|
|
|
download.Download()
|
2022-10-18 16:48:24 +00:00
|
|
|
|
2022-11-09 21:52:32 +00:00
|
|
|
if start_at <= 4:
|
|
|
|
logging.info("starting to fetch the lyrics")
|
2022-11-11 23:29:07 +00:00
|
|
|
fetch_lyrics()
|
2022-11-09 21:52:32 +00:00
|
|
|
|
2022-10-14 14:55:23 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-11-14 11:32:31 +00:00
|
|
|
cli(start_at=0, only_lyrics=False)
|