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 (
|
|
|
|
database,
|
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-12-06 16:55:07 +00:00
|
|
|
# from .lyrics import lyrics
|
2022-11-16 09:37:41 +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 13:34:36 +00:00
|
|
|
# define the most important values and function for import in the __init__ file
|
2022-11-24 17:25:49 +00:00
|
|
|
Song = database.Song
|
2022-11-30 15:15:38 +00:00
|
|
|
Artist = database.Artist
|
2022-12-06 16:55:07 +00:00
|
|
|
Source = database.Source
|
2023-01-20 22:05:15 +00:00
|
|
|
SourceTypes = database.SourceTypes
|
|
|
|
SourcePages = database.SourcePages
|
2022-12-06 16:55:07 +00:00
|
|
|
Target = database.Target
|
|
|
|
Lyrics = database.Lyrics
|
2022-12-07 14:51:38 +00:00
|
|
|
Album = database.Album
|
2023-02-09 08:40:57 +00:00
|
|
|
MusicObject = database.MusicObject
|
2023-01-30 22:54:21 +00:00
|
|
|
|
2023-01-14 13:41:40 +00:00
|
|
|
ID3Timestamp = database.ID3Timestamp
|
2023-01-30 22:54:21 +00:00
|
|
|
|
|
|
|
cache = database.cache
|
|
|
|
Database = database.Database
|
2022-11-24 17:25:49 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
def get_options_from_query(query: str) -> List[MusicObject]:
|
|
|
|
options = []
|
|
|
|
for MetadataPage in pages.MetadataPages:
|
|
|
|
options.extend(MetadataPage.search_by_query(query=query))
|
|
|
|
return options
|
2022-11-24 14:42:50 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
def get_options_from_option(option: MusicObject) -> List[MusicObject]:
|
|
|
|
for MetadataPage in pages.MetadataPages:
|
|
|
|
option = MetadataPage.fetch_details(option, flat=False)
|
|
|
|
return option.get_options()
|
2022-11-24 14:42:50 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
def print_options(options: List[MusicObject]):
|
|
|
|
print("\n".join([f"{str(j).zfill(2)}: {i.get_option_string()}" for j, i in enumerate(options)]))
|
2022-11-24 13:56:51 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
def cli():
|
|
|
|
options = []
|
2022-11-24 17:25:49 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
while True:
|
2023-02-09 14:05:49 +00:00
|
|
|
command: str = input(">> ").strip()
|
2022-11-24 13:34:36 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
if command.isdigit():
|
|
|
|
option_index = int(command)
|
2022-11-24 17:25:49 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
if option_index >= len(options):
|
|
|
|
print(f"option {option_index} doesn't exist")
|
|
|
|
continue
|
2022-11-24 13:34:36 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
options = get_options_from_option(options[option_index])
|
2022-11-22 13:25:01 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
else:
|
|
|
|
options = get_options_from_query(command)
|
2022-11-29 10:47:46 +00:00
|
|
|
|
2023-02-09 08:40:57 +00:00
|
|
|
print_options(options)
|
2022-11-15 12:04:44 +00:00
|
|
|
|
|
|
|
|