mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-05-19 13:59:20 +03:00
localhost_frssoft
8d441fb84a
Structure has changes Add fetch nodeinfo and avalaibility for all instances in list Can remove failed instances
99 lines
2.9 KiB
Python
99 lines
2.9 KiB
Python
import json
|
|
from os.path import exists
|
|
from loguru import logger
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
fzf = FzfPrompt()
|
|
|
|
conf_file = 'config.json'
|
|
|
|
default_conf = {
|
|
'instance': 'fw.ponychord.rocks',
|
|
'public_list_instances_extended':
|
|
{
|
|
"open.audio": None,
|
|
"funkwhale.co.uk": None,
|
|
"am.pirateradio.social": None,
|
|
"audio.liberta.vip": None,
|
|
"audio.gafamfree.party": None,
|
|
"tanukitunes.com": None,
|
|
"funkwhale.juniorjpdj.pl": None,
|
|
"audio.securetown.in.ua": None,
|
|
"tavia.mle.party": None,
|
|
"funkwhale.thurk.org": None,
|
|
"buzzworkers.com": None,
|
|
"soundship.de": None,
|
|
"funkwhale.kameha.click": None,
|
|
"music.chosto.me": None,
|
|
"zik.goe.land": None,
|
|
"music.humanoids.be": None,
|
|
"music.hempton.us": None,
|
|
"mizik.o-k-i.net": None,
|
|
"klh.radiolivre.org": None,
|
|
"hudba.feildel.fr": None,
|
|
"funkwhale.mita.me": None,
|
|
"funk.deko.cloud": None,
|
|
"audio.graz.social": None,
|
|
"funkwhale.desmu.fr": None,
|
|
"listen.knsm.cc": None,
|
|
"funkwhale.gegeweb.eu": None,
|
|
"shitnoise.monster": None,
|
|
},
|
|
'automatic_fetch_new_instances': False,
|
|
'enable_server_transcoding': False,
|
|
'external_transcoder_http_proxy_path': "",
|
|
'track_activity_history': False,
|
|
'prefetch_playlist': True,
|
|
'enable_persistent_cache': False,
|
|
'mpv_volume': 100,
|
|
'show_like_button': True,
|
|
'show_artist_name_in_albums': False
|
|
}
|
|
|
|
|
|
def set_defaults(corrected_config=None):
|
|
conf_rewrite = default_conf
|
|
if corrected_config:
|
|
conf_rewrite = corrected_config
|
|
with open(conf_file, 'wt') as f:
|
|
f.write(json.dumps(conf_rewrite, indent=4))
|
|
|
|
|
|
def check_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 = {}
|
|
for k, v in loaded_config.items():
|
|
if k in default_conf.keys():
|
|
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)
|
|
return correct_conf
|
|
|
|
|
|
if not exists(conf_file):
|
|
set_defaults()
|
|
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)
|
|
|
|
|
|
def set_config(key, value):
|
|
'''set value new value config by key'''
|
|
read_conf = check_config()
|
|
with open(conf_file, 'wt') as f:
|
|
read_conf[key] = value
|
|
f.write(json.dumps(read_conf, indent=4))
|