From 67aa2257cb1a90817b9002345d8baba85e46ab23 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 28 Nov 2022 02:17:21 +0300 Subject: [PATCH] Instance title and donate button when starting --- funkwhale_cli.py | 28 +++++++++++++++++++++++++--- src/fw_api.py | 7 +++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 2a61c30..193ac65 100644 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -1,4 +1,4 @@ -from src.fw_api import s, select_instance, instance, federate_search_by_url +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 @@ -8,14 +8,30 @@ 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 +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', @@ -27,9 +43,11 @@ def main(): '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) + ids = fzf.prompt(menu, f"--header={main_menu_header}") selected = ids[0] if selected == 'Radios': @@ -78,6 +96,10 @@ Insert token from "Access token" here''') 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) diff --git a/src/fw_api.py b/src/fw_api.py index ad4fe4a..8cc2766 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -60,6 +60,12 @@ def select_instance(new_instance=None): set_http_header(['Authorization: ' + 'Bearer ' + token]) +@logger.catch +def get_instance_settings(): + r = s.get(f'https://{instance}/api/v1/instance/settings') + return r.json() + + @logger.catch def get_audio_file(track_uuid, listen_url=False, download=False, transcoding=get_config('enable_server_transcoding'), to='ogg'): @@ -93,6 +99,7 @@ def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, incl r = s.get(f'https://{instance}/api/v1/tracks', params=params) return r.json() + @logger.catch def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None): '''This function get favorites tracks (not only for user)'''