From 7e936d9bbb6e86997f5dadeba3226e80b206b971 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 8 Nov 2022 23:39:01 +0300 Subject: [PATCH] Users by libraries and libraries added in radio --- src/fw_api.py | 9 ++++++--- src/fw_radios.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/fw_api.py b/src/fw_api.py index 109e124..898ff8f 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -93,15 +93,18 @@ def get_albums(page=None, q=None, artist=None, pg=None): return r.json() - -def list_libraries(page=None, page_size=None, q=None, scope='all'): +@logger.catch +def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None): params = { 'page': page, 'page_size': page_size, 'q': q, 'scope': scope, } - r = s.get(f'https://{instance}/api/v1/libraries', params) + if pg: + r = s.get(pg) + else: + r = s.get(f'https://{instance}/api/v1/libraries', params=params) return r.json() diff --git a/src/fw_radios.py b/src/fw_radios.py index 295f356..ccfbea3 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -10,6 +10,7 @@ fzf = FzfPrompt() audio_info = {} +@logger.catch def list_radios(): radios = get_radios() count = radios.get('count') @@ -25,7 +26,8 @@ def list_radios(): view.append('Favourites') view.append('Less listened') view.append('Random') - view.append('Library') + view.append('Libraries') + view.append('Users') view.append('Recently Added') selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1) @@ -33,7 +35,34 @@ def list_radios(): radio_load(id_radio, 'favorites') elif 'Random' in selected: radio_load(id_radio, 'random') - elif 'Library' in selected: + elif 'Libraries' in selected: + def libraries(pg=None): + libs_res = list_libraries(pg=pg) + libs_count = libs_res.get('count') + libs_next = libs_res.get('next') + libs_prev = libs_res.get('previous') + libs = list_libraries()['results'] + libraries_listing = [] + if libs_next: + libraries_listing.append('Next') + if libs_prev: + libraries_listing.append('Prev') + for lib_i in libs: + index = libs.index(lib_i) + lib_name = lib_i.get('name') + libraries_listing.append(f'{index}.{lib_name}') + lib_select = fzf.prompt(libraries_listing, f'--header=\'found {libs_count} libraries\'')[0].split('.', 1) + if lib_select[0] == 'Next': + libraries(pg=libs_next) + elif lib_select[0] == 'Prev': + libraries(pg=libs_prev) + else: + lib_addr = lib_select[0] + lib_name = lib_select[1] + lib_uuid = libs[int(lib_addr)].get('uuid') + radio_load(None, 'library', lib_name, lib_uuid) + libraries() + elif 'Users' in selected: libs = list_libraries()['results'] libraries_listing = [] for lib_i in libs: