2022-11-24 21:10:22 +00:00
|
|
|
import gc
|
|
|
|
|
2022-11-24 13:34:36 +00:00
|
|
|
from typing import List
|
2022-11-23 07:24:05 +00:00
|
|
|
import musicbrainzngs
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2022-11-24 13:34:36 +00:00
|
|
|
from . import (
|
2023-03-02 06:59:53 +00:00
|
|
|
objects,
|
2023-02-09 08:40:57 +00:00
|
|
|
pages
|
2022-11-24 13:34:36 +00:00
|
|
|
)
|
2023-02-06 08:16:28 +00:00
|
|
|
|
2022-11-24 13:34:36 +00:00
|
|
|
|
2022-11-23 07:24:05 +00:00
|
|
|
from .utils.shared import (
|
|
|
|
MUSIC_DIR,
|
|
|
|
NOT_A_GENRE
|
|
|
|
)
|
2022-11-24 13:56:51 +00:00
|
|
|
|
2022-11-28 16:18:26 +00:00
|
|
|
|
2022-11-24 21:10:22 +00:00
|
|
|
"""
|
|
|
|
At the start I modify the garbage collector to run a bit fewer times.
|
|
|
|
This should increase speed:
|
|
|
|
https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
|
|
|
"""
|
|
|
|
# Clean up what might be garbage so far.
|
|
|
|
gc.collect(2)
|
|
|
|
|
|
|
|
allocs, gen1, gen2 = gc.get_threshold()
|
|
|
|
allocs = 50_000 # Start the GC sequence every 50K not 700 allocations.
|
|
|
|
gen1 = gen1 * 2
|
|
|
|
gen2 = gen2 * 2
|
|
|
|
gc.set_threshold(allocs, gen1, gen2)
|
|
|
|
|
2022-11-22 13:53:29 +00:00
|
|
|
logging.getLogger("musicbrainzngs").setLevel(logging.WARNING)
|
|
|
|
musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader")
|
2022-11-15 12:04:44 +00:00
|
|
|
|
2022-11-24 17:25:49 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
def cli():
|
2023-03-30 08:49:17 +00:00
|
|
|
def next_search(search: pages.Search, query: str):
|
|
|
|
query: str = query.strip()
|
|
|
|
parsed: str = query.lower()
|
|
|
|
|
|
|
|
if parsed == ".":
|
|
|
|
return
|
|
|
|
if parsed == "..":
|
|
|
|
search.goto_previous()
|
|
|
|
return
|
|
|
|
|
|
|
|
if parsed.isdigit():
|
|
|
|
search.choose_index(int(parsed))
|
|
|
|
return
|
|
|
|
|
|
|
|
page = search.get_page_from_query(parsed)
|
|
|
|
if page is not None:
|
|
|
|
search.choose_page(page)
|
|
|
|
return
|
|
|
|
|
|
|
|
# if everything else is not valid search
|
|
|
|
search.search(query)
|
2023-03-29 15:24:02 +00:00
|
|
|
|
2023-03-30 08:49:17 +00:00
|
|
|
search = pages.Search()
|
|
|
|
|
2023-03-29 15:24:02 +00:00
|
|
|
while True:
|
2023-03-30 08:49:17 +00:00
|
|
|
next_search(search, input(">> "))
|
2023-03-29 15:24:02 +00:00
|
|
|
print(search)
|
2023-03-30 08:49:17 +00:00
|
|
|
|