From 2158019241c2046cae9a921e432746971e56b8a2 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 10 Nov 2022 03:23:46 +0300 Subject: [PATCH] Removed checks options mpv; Configurator changes --- src/mpv_control.py | 9 +++------ src/settings.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/mpv_control.py b/src/mpv_control.py index 4924370..1661561 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -1,5 +1,6 @@ import src.fw_api from src.utils import download_track +from src.settings import get_config from loguru import logger from pyfzf.pyfzf import FzfPrompt import mpv @@ -14,12 +15,8 @@ def mpv_log(loglevel, component, message): logger.error(f'{component} {message}') player = mpv.MPV() - -list_options = dir(player) -if 'ytdl' in list_options: - player.ytdl = False -if 'prefetch_playlist' in list_options: - player.prefetch_playlist = True +player.ytdl = False # Prevent attempts load track with yt-dlp +player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic def set_http_header(headers=[]): diff --git a/src/settings.py b/src/settings.py index 4807f0d..7f430b7 100644 --- a/src/settings.py +++ b/src/settings.py @@ -34,7 +34,8 @@ default_conf = { "listen.knsm.cc", "funkwhale.gegeweb.eu", "shitnoise.monster" - ] + ], + 'prefetch_playlist': True } @@ -47,7 +48,7 @@ def set_defaults(corrected_config=None): def check_config(): - '''Check config and remove keys if not found in default config''' + '''Check config and remove or add keys if not found in default config''' with open(conf_file, 'rt') as f: loaded_config = json.loads(f.read()) correct_conf = {} @@ -56,6 +57,10 @@ def check_config(): correct_conf[k] = v else: logger.warning(f'{k} from config will be removed. Value: {v}') + for k, v in default_conf.items(): + if k not in correct_conf.keys(): + correct_conf[k] = v + logger.warning(f'{k} added in config. Value: {v}') set_defaults(correct_conf) @@ -65,6 +70,13 @@ else: check_config() +def get_config(key): + '''return value from config by key''' + with open(conf_file, 'rt') as f: + loaded_config = json.loads(f.read()) + return loaded_config.get(key) + + @logger.catch def get_new_funkwhale_servers(): # Uses official API network.funkwhale.audio for getting new instances