Users by libraries and libraries added in radio

This commit is contained in:
localhost_frssoft 2022-11-08 23:39:01 +03:00
parent e07a672466
commit 7e936d9bbb
2 changed files with 37 additions and 5 deletions

View File

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

View File

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