Some fixes in radios

This commit is contained in:
localhost_frssoft 2023-06-14 23:05:14 +03:00
parent f5840926a6
commit a76f36bafd

View File

@ -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'))