mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2025-05-07 20:38:41 +00:00
Checks config; other changes
This commit is contained in:
parent
097051cdef
commit
fba68e7a70
4 changed files with 37 additions and 66 deletions
|
@ -41,6 +41,9 @@ def play_artist(artist_id):
|
|||
storage = {}
|
||||
if tracks_count > 50:
|
||||
print(f'Loading {tracks_count} tracks...')
|
||||
elif tracks_count == 0:
|
||||
logger.warning('Empty tracks. Nothing to do')
|
||||
return
|
||||
while True:
|
||||
tracks_results = tracks.get('results')
|
||||
tracks_next = tracks.get('next')
|
||||
|
@ -52,4 +55,5 @@ def play_artist(artist_id):
|
|||
tracks = get_tracks(artist=artist_id, include_channels=True, pg=tracks_next)
|
||||
else:
|
||||
break
|
||||
player_menu("Artist playing...", storage)
|
||||
artist_name = tracks.get('results')[0].get('artist').get('name')
|
||||
player_menu(f"Artist {artist_name} playing...", storage)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import json, requests, time
|
||||
from os.path import exists
|
||||
from loguru import logger
|
||||
|
||||
defaut_conf = {
|
||||
conf_file = 'config.json'
|
||||
|
||||
default_conf = {
|
||||
'instance': 'fw.ponychord.rocks',
|
||||
'public_list_instances': [
|
||||
"open.audio",
|
||||
|
@ -35,6 +38,33 @@ defaut_conf = {
|
|||
}
|
||||
|
||||
|
||||
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 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}')
|
||||
set_defaults(correct_conf)
|
||||
|
||||
|
||||
if not exists(conf_file):
|
||||
set_defaults()
|
||||
else:
|
||||
check_config()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def get_new_funkwhale_servers():
|
||||
# Uses official API network.funkwhale.audio for getting new instances
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue