from src.fw_api import get_favorires_tracks, concatinate_endpoint from src.mpv_control import player, player_menu from pyfzf.pyfzf import FzfPrompt from loguru import logger fzf = FzfPrompt() @logger.catch def list_favorites_tracks(pg=None, search=None, scope=None): tracks = get_favorires_tracks(q=search, scope=scope, pg=pg) tracks_next = tracks.get('next') tracks_prev = tracks.get('previous') tracks_results = tracks.get('results') view = ['Search', 'Limit by scope'] if tracks_next: view.append('Next page') if tracks_prev: view.append('Prev page') for i in tracks_results: index = tracks_results.index(i) track_name = i['track'].get('title') who_user = i['user'].get('username') view.append(f'{index}.{track_name} | liked: {who_user}') select = fzf.prompt(view)[0].split('.', 1)[0] if select == 'Next page': list_favorites_tracks(pg=tracks_next) elif select == 'Prev page': list_favorites_tracks(pg=tracks_prev) elif select == 'Search': print('Search by track:') list_favorites_tracks(search=input()) elif select == 'Limit by scope': print(''' Limit the results to a given user or pod: Use all (or do not specify the property to disable scope filtering) Use me to retrieve content relative to the current user Use subscribed to retrieve content in libraries you follow Use actor:alice@example.com to retrieve content relative to the account `alice@example.com Use domain:example.com to retrieve content relative to the domain `example.com ''') scope = input() list_favorites_tracks(scope=scope, search=search) else: play_track(track=tracks_results[int(select)]['track']) def play_track(track): storage = {} listen_url = concatinate_endpoint(track.get('listen_url')) storage[listen_url] = track player.loadfile(listen_url, 'append-play') track_name = track.get('title') player_menu(f"{track_name} playing...", storage)