completed the refactored and improved version of the metadata search module :3
This commit is contained in:
parent
9a771b6673
commit
b4de6cd639
34
src/main.py
34
src/main.py
@ -1,7 +1,7 @@
|
|||||||
from metadata.database import Database
|
from metadata.database import Database
|
||||||
from metadata.download import MetadataDownloader
|
from metadata.download import MetadataDownloader
|
||||||
import metadata.download
|
import metadata.download
|
||||||
import metadata.metadata
|
import metadata.search
|
||||||
import download_links
|
import download_links
|
||||||
import url_to_path
|
import url_to_path
|
||||||
import download
|
import download
|
||||||
@ -17,6 +17,7 @@ DATABASE_FILE = "metadata.db"
|
|||||||
DATABASE_STRUCTURE_FILE = "database_structure.sql"
|
DATABASE_STRUCTURE_FILE = "database_structure.sql"
|
||||||
DATABASE_STRUCTURE_FALLBACK = "https://raw.githubusercontent.com/HeIIow2/music-downloader/new_metadata/assets/database_structure.sql"
|
DATABASE_STRUCTURE_FALLBACK = "https://raw.githubusercontent.com/HeIIow2/music-downloader/new_metadata/assets/database_structure.sql"
|
||||||
|
|
||||||
|
SEARCH_LOGGER = logging.getLogger("mb-cli")
|
||||||
DATABASE_LOGGER = logging.getLogger("database")
|
DATABASE_LOGGER = logging.getLogger("database")
|
||||||
METADATA_DOWNLOAD_LOGGER = logging.getLogger("metadata-download")
|
METADATA_DOWNLOAD_LOGGER = logging.getLogger("metadata-download")
|
||||||
URL_DOWNLOAD_LOGGER = logging.getLogger("ling-download")
|
URL_DOWNLOAD_LOGGER = logging.getLogger("ling-download")
|
||||||
@ -27,9 +28,6 @@ NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea"
|
|||||||
MUSIC_DIR = os.path.expanduser('~/Music')
|
MUSIC_DIR = os.path.expanduser('~/Music')
|
||||||
TOR = False
|
TOR = False
|
||||||
|
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.level = logging.DEBUG
|
|
||||||
|
|
||||||
temp_dir = os.path.join(tempfile.gettempdir(), TEMP_FOLDER)
|
temp_dir = os.path.join(tempfile.gettempdir(), TEMP_FOLDER)
|
||||||
if not os.path.exists(temp_dir):
|
if not os.path.exists(temp_dir):
|
||||||
os.mkdir(temp_dir)
|
os.mkdir(temp_dir)
|
||||||
@ -52,28 +50,26 @@ def get_existing_genre():
|
|||||||
return valid_directories
|
return valid_directories
|
||||||
|
|
||||||
|
|
||||||
def search_for_metadata(query: str):
|
def search_for_metadata():
|
||||||
search = metadata.metadata.Search(query=query)
|
search = metadata.search.Search(logger=SEARCH_LOGGER)
|
||||||
|
|
||||||
print(search.options)
|
|
||||||
while True:
|
while True:
|
||||||
input_ = input(
|
input_ = input(
|
||||||
"q to quit, ok to download, .. for previous options, . for current options, int for this element: ").lower()
|
"q to quit, .. for previous options, int for this element, str to search for query, ok to download\n")
|
||||||
input_.strip()
|
input_.strip()
|
||||||
if input_ == "q":
|
if input_.lower() == "ok":
|
||||||
exit(0)
|
break
|
||||||
if input_ == "ok":
|
if input_.lower() == "q":
|
||||||
return search.current_chosen_option
|
break
|
||||||
if input_ == ".":
|
if input_.lower() == "..":
|
||||||
print(search.options)
|
search.get_previous_options()
|
||||||
continue
|
|
||||||
if input_ == "..":
|
|
||||||
print(search.get_previous_options())
|
|
||||||
continue
|
continue
|
||||||
if input_.isdigit():
|
if input_.isdigit():
|
||||||
print(search.choose(int(input_)))
|
search.choose(int(input_))
|
||||||
continue
|
continue
|
||||||
|
search.search_from_query(input_)
|
||||||
|
|
||||||
|
return search.current_option
|
||||||
|
|
||||||
def get_genre():
|
def get_genre():
|
||||||
existing_genres = get_existing_genre()
|
existing_genres = get_existing_genre()
|
||||||
@ -106,7 +102,7 @@ def cli(start_at: int = 0):
|
|||||||
logging.info(f"{genre} has been set as genre.")
|
logging.info(f"{genre} has been set as genre.")
|
||||||
|
|
||||||
if start_at <= 0:
|
if start_at <= 0:
|
||||||
search = search_for_metadata(query=input("initial query: "))
|
search = search_for_metadata()
|
||||||
logging.info("Starting Downloading of metadata")
|
logging.info("Starting Downloading of metadata")
|
||||||
metadata_downloader = MetadataDownloader(database, METADATA_DOWNLOAD_LOGGER)
|
metadata_downloader = MetadataDownloader(database, METADATA_DOWNLOAD_LOGGER)
|
||||||
metadata_downloader.download(search)
|
metadata_downloader.download(search)
|
||||||
|
@ -19,6 +19,6 @@ def parse_music_brainz_date(mb_date: str) -> date:
|
|||||||
first_release_date = mb_date
|
first_release_date = mb_date
|
||||||
if first_release_date.count("-") == 2:
|
if first_release_date.count("-") == 2:
|
||||||
year, month, day = [int(i) for i in first_release_date.split("-")]
|
year, month, day = [int(i) for i in first_release_date.split("-")]
|
||||||
elif first_release_date.count("-") == 0:
|
elif first_release_date.count("-") == 0 and first_release_date.isdigit():
|
||||||
year = int(first_release_date)
|
year = int(first_release_date)
|
||||||
return date(year, month, day)
|
return date(year, month, day)
|
||||||
|
@ -26,6 +26,15 @@ class Option:
|
|||||||
|
|
||||||
self.additional_info = additional_info
|
self.additional_info = additional_info
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
map_ = {
|
||||||
|
"id": self.id,
|
||||||
|
"type": self.type,
|
||||||
|
"kind": self.type,
|
||||||
|
"name": self.name
|
||||||
|
}
|
||||||
|
return map_[item]
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
type_repr = {
|
type_repr = {
|
||||||
'artist': 'artist\t\t',
|
'artist': 'artist\t\t',
|
||||||
|
Loading…
Reference in New Issue
Block a user