From fba68e7a7096163a03f226350764f9b48be047e0 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 10 Nov 2022 02:23:18 +0300 Subject: [PATCH] Checks config; other changes --- .gitignore | 1 + config.json | 64 ----------------------------------------------- src/fw_artists.py | 6 ++++- src/settings.py | 32 +++++++++++++++++++++++- 4 files changed, 37 insertions(+), 66 deletions(-) delete mode 100644 config.json diff --git a/.gitignore b/.gitignore index 7eb9c68..a7cd674 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tags_db music_dl .auth.json +config.json diff --git a/config.json b/config.json deleted file mode 100644 index 4b41ed4..0000000 --- a/config.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "instance": "fw.ponychord.rocks", - "download_selected_track": false, - "local_content_only": true, - "tags": [ - "8bit", - "Alternative", - "Ambient", - "Classical", - "Comedy", - "Country", - "Dance", - "Blues", - "Electronic", - "Hip-Hop", - "Industrial", - "Instrumental", - "J-Pop", - "Jazz", - "Karaoke", - "Latin", - "Metal", - "Orchestral", - "Opera", - "Pop", - "Progressive", - "Reggae", - "Rock", - "Singler", - "Synth", - "Songwriter", - "Soundtrack", - "Vocal" - ], - "public_list_instances": [ - "open.audio", - "audio.securetown.top", - "funkwhale.co.uk", - "am.pirateradio.social", - "audio.liberta.vip", - "audio.gafamfree.party", - "tanukitunes.com", - "funkwhale.juniorjpdj.pl", - "tavia.mle.party", - "funkwhale.thurk.org", - "buzzworkers.com", - "soundship.de", - "funkwhale.kameha.click", - "music.chosto.me", - "zik.goe.land", - "music.humanoids.be", - "music.hempton.us", - "mizik.o-k-i.net", - "klh.radiolivre.org", - "hudba.feildel.fr", - "funkwhale.mita.me", - "funk.deko.cloud", - "audio.graz.social", - "funkwhale.desmu.fr", - "listen.knsm.cc", - "funkwhale.gegeweb.eu", - "shitnoise.monster" - ] -} diff --git a/src/fw_artists.py b/src/fw_artists.py index 6fa6e41..8868893 100644 --- a/src/fw_artists.py +++ b/src/fw_artists.py @@ -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) diff --git a/src/settings.py b/src/settings.py index abef652..803b161 100644 --- a/src/settings.py +++ b/src/settings.py @@ -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