From ff26263496810ef0718a4e431b6bf809bfa24cbb Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 9 Nov 2022 01:34:33 +0300 Subject: [PATCH] Libraries separated --- src/fw_libraries.py | 33 +++++++++++++++++++++++++++++++++ src/fw_radios.py | 29 +++-------------------------- 2 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 src/fw_libraries.py diff --git a/src/fw_libraries.py b/src/fw_libraries.py new file mode 100644 index 0000000..ffde50f --- /dev/null +++ b/src/fw_libraries.py @@ -0,0 +1,33 @@ +from src.fw_api import list_libraries +from pyfzf.pyfzf import FzfPrompt +from loguru import logger + +fzf = FzfPrompt() + + +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') + return None, 'library', lib_name, lib_uuid + diff --git a/src/fw_radios.py b/src/fw_radios.py index ccfbea3..e3a0887 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -1,4 +1,5 @@ from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint +from src.fw_libraries import libraries from src.utils import download_track from src.mpv_control import player from pyfzf.pyfzf import FzfPrompt @@ -36,32 +37,8 @@ def list_radios(): elif 'Random' in selected: radio_load(id_radio, 'random') 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() + id_radio, type_radio, name_radio, related_obj = libraries() + radio_load(id_radio, type_radio, name_radio, related_obj) elif 'Users' in selected: libs = list_libraries()['results'] libraries_listing = []