added cli in appropriate file

This commit is contained in:
Lars Noack 2022-11-23 08:10:22 +01:00
parent 01c27efda5
commit 2ba9c4048c
3 changed files with 208 additions and 15 deletions

66
database_structure.sql Normal file
View File

@ -0,0 +1,66 @@
DROP TABLE IF EXISTS artist;
CREATE TABLE artist (
id TEXT PRIMARY KEY NOT NULL,
name TEXT
);
DROP TABLE IF EXISTS artist_release_group;
CREATE TABLE artist_release_group (
artist_id TEXT NOT NULL,
release_group_id TEXT NOT NULL
);
DROP TABLE IF EXISTS artist_track;
CREATE TABLE artist_track (
artist_id TEXT NOT NULL,
track_id TEXT NOT NULL
);
DROP TABLE IF EXISTS release_group;
CREATE TABLE release_group (
id TEXT PRIMARY KEY NOT NULL,
albumartist TEXT,
albumsort INT,
musicbrainz_albumtype TEXT,
compilation TEXT,
album_artist_id TEXT
);
DROP TABLE IF EXISTS release_;
CREATE TABLE release_ (
id TEXT PRIMARY KEY NOT NULL,
release_group_id TEXT NOT NULL,
title TEXT,
copyright TEXT,
album_status TEXT,
language TEXT,
year TEXT,
date TEXT,
country TEXT,
barcode TEXT
);
DROP TABLE IF EXISTS track;
CREATE TABLE track (
id TEXT PRIMARY KEY NOT NULL,
downloaded BOOLEAN NOT NULL DEFAULT 0,
release_id TEXT NOT NULL,
track TEXT,
length INT,
tracknumber TEXT,
isrc TEXT,
genre TEXT,
lyrics TEXT,
path TEXT,
file TEXT,
url TEXT,
src TEXT
);
DROP TABLE IF EXISTS source;
CREATE TABLE source (
track_id TEXT NOT NULL,
src TEXT NOT NULL,
url TEXT NOT NULL,
valid BOOLEAN NOT NULL DEFAULT 1
);

View File

@ -38,15 +38,8 @@ def get_existing_genre():
return valid_directories
def search_for_metadata():
clear_console()
search = metadata_search.Search()
while True:
input_ = input(
"""
def help_search_metadata():
msg = """
- - - Type the command you want to execute - - -
.. - Previous Options
(query_string) - Search for songs, albums, bands...
@ -54,9 +47,17 @@ def search_for_metadata():
d - Start the download
h - Help
q - Quit / Exit
"""
print(msg)
command: """
)
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":
@ -65,9 +66,7 @@ command: """
clear_console()
exit()
case "h" | "help":
print()
# TODO: Help text (mainly explaining query strings and alternative command functionalities)
print("Insert here help text....")
help_search_metadata()
case inp if inp.isdigit():
print()
print(search.choose(int(input_)))

View File

@ -1,4 +1,132 @@
from music_kraken import cli
import musicbrainzngs
import logging
import os
from music_kraken.utils.shared import (
MUSIC_DIR,
NOT_A_GENRE
)
from music_kraken.metadata import (
metadata_search,
metadata_fetch
)
from music_kraken.target import set_target
from music_kraken.audio_source 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()
case inp if inp.isdigit():
print()
print(search.choose(int(input_)))
continue
case ".." :
print()
print(search.get_previous_options())
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, cleare_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__":
cli()