from src.fw_api import s, select_instance, instance, federate_search_by_url, get_instance_settings from src.fw_radios import list_radios from src.fw_artists import list_artists from src.fw_albums import list_albums from src.fw_tracks import list_tracks from src.fw_channels import list_channels from src.fw_playlists import list_playlists from src.fw_fav_tracks import list_favorites_tracks import src.settings as settings import src.mpv_control import json, sys, time from shlex import quote from loguru import logger from pyfzf.pyfzf import FzfPrompt fzf = FzfPrompt() def main(): while True: support_message = '' instance_title = '' try: ins_settings = get_instance_settings() for i in ins_settings: if i.get('name') == 'support_message': support_message = i.get('value') if i.get('name') == 'name': instance_title = i.get('value') main_menu_header = quote(f'''{instance_title}'''.strip()) except: time.sleep(1) main_menu_header = quote(f'''Connection failed'''.strip()) menu = ['Radios', 'Artists', 'Albums', 'Tracks', 'Channels', 'Playlists', 'Favorites', 'Search', 'Switch instance'] if not s.headers.get('Authorization'): menu.append('Sign in') if support_message != '': menu.append('Donate') if not src.mpv_control.player.core_idle: menu.insert(0, 'Player') ids = fzf.prompt(menu, f"--header={main_menu_header}") selected = ids[0] if selected == 'Radios': list_radios() if selected == 'Artists': list_artists() if selected == 'Albums': list_albums() if selected == 'Tracks': list_tracks() if selected == 'Channels': list_channels() if selected == 'Playlists': list_playlists() if selected == 'Favorites': list_favorites_tracks() if selected == 'Search': search_type = fzf.prompt(('Federated', 'All types'))[0] if search_type == 'Federated': print('Input url:') returned_obj = federate_search_by_url(input()) logger.info(str(returned_obj)) if selected == 'Switch instance': with open('config.json', 'rt') as f: conf = json.loads(f.read()) list_instances = conf.get('public_list_instances') + settings.get_new_funkwhale_servers() instance = fzf.prompt(list_instances, '--header \'Select instance\'')[0] select_instance(instance) if selected == 'Sign in': print(f''' If You want sign in, please visit: https://{instance}/settings/applications/new And fill Name funkwhale-cli Scopes: Read (only listen music), Write (optional) Insert token from "Access token" here''') register_token = input() with open('.auth.json', 'rt') as f: tkns = json.loads(f.read()) with open('.auth.json', 'wt') as f: tkns[instance] = register_token f.write(json.dumps(tkns)) del tkns del register_token del f select_instance(instance) if selected == 'Donate': print('Support instance message:') print(support_message) input() if selected == 'Player': src.mpv_control.player_menu(storage=src.mpv_control.player_fw_storage.storage) if __name__ == '__main__': main()