From a76f36bafdd95ef7f42c06b8c0ad5bc3eadd3417 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 14 Jun 2023 23:05:14 +0300 Subject: [PATCH] Some fixes in radios --- src/fw_radios.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 1e2b971..631edfb 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -15,7 +15,7 @@ fzf = FzfPrompt() @logger.catch -def list_radios(): +def list_radios(error_given=None): radios = get_radios() count = radios.get('count') @@ -35,9 +35,12 @@ def list_radios(): view.append('Favourites') view.append('Less listened') view.extend(['Tag', 'Random', 'Libraries', 'Users', 'Recently Added']) - + header = f'Found {count} radios' + if error_given: + header += f'\n{error_given}' + header = quote(header) selected = fzf.prompt( - view, f'--header \'Found {count} radios\' --read0', delimiter="\0")[0].split('.', 1) + view, f'--header {header} --read0', delimiter="\0")[0].split('.', 1) if 'Favourites' in selected: radio_load(id_radio, 'favorites', name='your favorites tracks') elif 'Tag' in selected: @@ -104,7 +107,10 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non } radio_session_id = post_radio_session(requested_radio).get('id') for i in range(0, 2): - radio_get_track(radio_session_id) + try: + radio_get_track(radio_session_id, first_run=True) + except Exception as E: + return list_radios(error_given=f'Error: {E}') radio_event_gen.set() radio_task = threading.Thread( @@ -121,8 +127,12 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non player_items_menu[2] = 'Play' else: player_items_menu[2] = 'Pause' - select = fzf.prompt(player_items_menu, + try: + select = fzf.prompt(player_items_menu, quote(f"--header=\'Radio {name} playing...\'"))[0] + except: + select = 'Exit' + if select == 'Next': playlist_remaining = player.playlist_count - player.playlist_current_pos if playlist_remaining <= 2: @@ -169,7 +179,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non break -def radio_get_track(radio_session_id): +def radio_get_track(radio_session_id, first_run=False): radio_context = get_track_radio({'session': radio_session_id}) if not radio_context: return @@ -177,6 +187,9 @@ def radio_get_track(radio_session_id): logger.error(radio_context) if radio_context == "Radio doesn't have more candidates": radio_event_gen.clear() + if first_run: + radio_context = 'This radio may be private or haven\'t tracks' + raise IOError(radio_context) return if radio_context.get('error'): logger.error(radio_context.get('error'))