implemented genre in the cli
This commit is contained in:
parent
d500057315
commit
62b0102020
@ -2,11 +2,11 @@ import gc
|
||||
import musicbrainzngs
|
||||
import logging
|
||||
import re
|
||||
import os
|
||||
|
||||
from . import objects, pages
|
||||
from .utils.shared import MUSIC_DIR, NOT_A_GENRE, MODIFY_GC, get_random_message
|
||||
|
||||
|
||||
if MODIFY_GC:
|
||||
"""
|
||||
At the start I modify the garbage collector to run a bit fewer times.
|
||||
@ -40,7 +40,32 @@ EXIT_COMMANDS = {
|
||||
|
||||
|
||||
def cli():
|
||||
def next_search(_search: pages.Search, query: str) -> bool:
|
||||
def get_genre():
|
||||
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
|
||||
|
||||
existing_genres = get_existing_genre()
|
||||
print("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 next_search(_search: pages.Search, query: str, genre: str) -> bool:
|
||||
"""
|
||||
:param _search:
|
||||
:param query:
|
||||
@ -63,7 +88,7 @@ def cli():
|
||||
return False
|
||||
|
||||
if parsed in DOWNLOAD_COMMANDS:
|
||||
r = _search.download_chosen()
|
||||
r = _search.download_chosen(genre=genre)
|
||||
|
||||
print()
|
||||
print(r)
|
||||
@ -86,10 +111,13 @@ def cli():
|
||||
_search.search(query)
|
||||
return False
|
||||
|
||||
genre = get_genre()
|
||||
print(f"Selected: {genre}\n")
|
||||
|
||||
search = pages.Search()
|
||||
|
||||
while True:
|
||||
if next_search(search, input(">> ")):
|
||||
if next_search(search, input(">> "), genre):
|
||||
break
|
||||
print(search)
|
||||
|
||||
|
@ -130,7 +130,7 @@ class Search(Download):
|
||||
|
||||
return True
|
||||
|
||||
def download_chosen(self) -> DownloadResult:
|
||||
def download_chosen(self, genre: str = None, **kwargs) -> DownloadResult:
|
||||
if self._current_option._derive_from is None:
|
||||
return DownloadResult(error_message="No option has been chosen yet.")
|
||||
|
||||
@ -139,7 +139,7 @@ class Search(Download):
|
||||
page = self._get_page_from_source(source=source)
|
||||
|
||||
if page in self.audio_pages:
|
||||
return page.download(music_object=self._current_option._derive_from)
|
||||
return page.download(music_object=self._current_option._derive_from, genre=None, **kwargs)
|
||||
|
||||
return DownloadResult(error_message=f"Didn't find a source for {self._current_option._derive_from.option_string}.")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user