Libraries separated

This commit is contained in:
localhost_frssoft 2022-11-09 01:34:33 +03:00
parent f3762e2a4e
commit ff26263496
2 changed files with 36 additions and 26 deletions

33
src/fw_libraries.py Normal file
View File

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

View File

@ -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 = []