From 5184f81277b53cb42c1050fbaf6f764f1902d205 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 8 Nov 2022 03:29:44 +0300 Subject: [PATCH] Listing user libraries for radio --- src/fw_api.py | 11 +++++++++++ src/fw_radios.py | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/fw_api.py b/src/fw_api.py index f308b3e..ad6a3bf 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -51,6 +51,17 @@ def list_tracks(page=None, q=None, artist=None, album=None, favourites=None): return r.json() +def list_libraries(page=None, page_size=None, q=None, scope='all'): + params = { + 'page': page, + 'page_size': page_size, + 'q': q, + 'scope': scope, + } + r = requests.get(f'https://{instance}/api/v1/libraries', params) + return r.json() + + # [FunkWhale radios] def get_radios(): r = s.get(f'https://{instance}/api/v1/radios/radios/') diff --git a/src/fw_radios.py b/src/fw_radios.py index 207a43a..8e663e1 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -1,4 +1,4 @@ -from src.fw_api import s, get_radios, post_radio_session, get_track_radio, concatinate_endpoint +from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint from src.utils import download_track from src.mpv_control import player from pyfzf.pyfzf import FzfPrompt @@ -34,8 +34,17 @@ def list_radios(): elif 'Random' in selected: radio_load(id_radio, 'random') elif 'Library' in selected: - print('Input library address (ex. example@example.example): ') - lib_addr = input() + libs = list_libraries()['results'] + libraries_listing = [] + for lib_i in libs: + lib_name = lib_i.get('actor').get('full_username') + if lib_name not in libraries_listing: + libraries_listing.append(lib_name) + libraries_listing.append('Custom') + lib_addr = fzf.prompt(libraries_listing)[0] + if lib_addr == 'Custom': + print('Input remote user library (ex. nick@funkwhale.domain.example: ') + lib_addr = input() radio_load(None, 'actor-content', lib_addr, lib_addr) elif 'Recently Added' in selected: radio_load(id_radio, 'recently-added')