Instance title and donate button when starting

This commit is contained in:
localhost_frssoft 2022-11-28 02:17:21 +03:00
parent c4aaab97bf
commit 67aa2257cb
2 changed files with 32 additions and 3 deletions

View File

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

View File

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