From 74f9a732effa1efe4a744620e4e8b7cedccaa769 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 7 Nov 2022 01:21:49 +0300 Subject: [PATCH] Fix radio generator too many requests; logging some parts --- funkwhale_cli.py | 4 +++- src/fw_api.py | 6 +++++- src/fw_radios.py | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index ccb3640..2e7b380 100644 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -1,6 +1,6 @@ from src.fw_api import select_instance from src.fw_radios import list_radios -import json +import json, sys from loguru import logger from pyfzf.pyfzf import FzfPrompt @@ -8,6 +8,8 @@ fzf = FzfPrompt() def main(): logger.remove() + logger.add(sys.stderr, filter='src.fw_api') + logger.add(sys.stderr, filter='src.fw_radios') while True: menu = ('Radios', 'Switch instance' ) ids = fzf.prompt(menu) diff --git a/src/fw_api.py b/src/fw_api.py index 5c882f1..f308b3e 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -64,6 +64,10 @@ def post_radio_session(requested_radio): def get_track_radio(radio_session): r = s.post(f'https://{instance}/api/v1/radios/tracks/',json=radio_session) - return r.json() + try: + r.raise_for_status() + return r.json() + except: + logger.exception('Radio: get next track failed') diff --git a/src/fw_radios.py b/src/fw_radios.py index d50f5ec..f94a416 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -49,6 +49,7 @@ def radio_generator(radio_session_id): break count_t += 1 if count_t >= 60: + count_t = 0 radio_get_track(radio_session_id) logger.info('Radio generator stopped') @@ -100,7 +101,8 @@ def radio_load(id_radio=None, type_radio='custom'): def radio_get_track(radio_session_id): radio_context = get_track_radio({'session': radio_session_id}) - + if not radio_context: + return if radio_context == "Radio doesn't have more candidates": return else: