2022-12-07 20:26:59 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-12-04 01:01:11 +00:00
|
|
|
from src.fw_api import current_instance, federate_search_by_url, get_instance_settings
|
2022-11-01 10:15:28 +00:00
|
|
|
from src.fw_radios import list_radios
|
2022-11-08 17:58:27 +00:00
|
|
|
from src.fw_artists import list_artists
|
2022-11-08 18:08:24 +00:00
|
|
|
from src.fw_albums import list_albums
|
2022-11-10 22:42:29 +00:00
|
|
|
from src.fw_tracks import list_tracks
|
2022-11-09 01:01:02 +00:00
|
|
|
from src.fw_channels import list_channels
|
2022-11-10 15:55:36 +00:00
|
|
|
from src.fw_playlists import list_playlists
|
2023-06-06 23:37:52 +00:00
|
|
|
from src.fw_recents import list_fav_or_history
|
2022-11-09 18:51:20 +00:00
|
|
|
import src.settings as settings
|
2022-11-14 20:28:01 +00:00
|
|
|
import src.mpv_control
|
2022-12-18 01:02:53 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
import time
|
2022-11-27 23:17:21 +00:00
|
|
|
from shlex import quote
|
2022-11-02 00:05:08 +00:00
|
|
|
from loguru import logger
|
2022-11-01 10:15:28 +00:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
|
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
2022-12-18 01:02:53 +00:00
|
|
|
|
2022-11-01 10:15:28 +00:00
|
|
|
def main():
|
2022-11-27 23:17:21 +00:00
|
|
|
|
2022-11-01 10:15:28 +00:00
|
|
|
while True:
|
2022-11-27 23:17:21 +00:00
|
|
|
support_message = ''
|
|
|
|
instance_title = ''
|
2023-06-10 19:53:51 +00:00
|
|
|
menu = ['Radios',
|
|
|
|
'Artists',
|
|
|
|
'Albums',
|
|
|
|
'Tracks',
|
|
|
|
'Channels',
|
|
|
|
'Playlists',
|
|
|
|
'Favorites',
|
|
|
|
'Recently listened',
|
|
|
|
'Search',
|
2023-06-12 00:18:58 +00:00
|
|
|
'About instance',
|
2023-06-10 19:53:51 +00:00
|
|
|
'Switch instance']
|
2022-11-27 23:17:21 +00:00
|
|
|
try:
|
2023-06-12 00:18:58 +00:00
|
|
|
ins_settings, ins_nodeinfo = get_instance_settings()
|
2022-11-27 23:17:21 +00:00
|
|
|
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')
|
2023-06-12 00:18:58 +00:00
|
|
|
instance_stats = []
|
|
|
|
for k, v in ins_nodeinfo['metadata']['library'].items():
|
2023-06-12 22:58:52 +00:00
|
|
|
if k == 'anonymousCanListen' and v == False and not current_instance.s.headers.get('Authorization'):
|
2023-06-12 00:18:58 +00:00
|
|
|
instance_stats.append(f'!!! {k}: {v} !!!')
|
2023-06-12 22:58:52 +00:00
|
|
|
menu = ['Switch instance', 'About instance']
|
2023-06-12 00:18:58 +00:00
|
|
|
continue
|
|
|
|
instance_stats.append(f'{k}: {v}')
|
|
|
|
instance_stats.append(ins_nodeinfo['software']['version'])
|
|
|
|
instance_stats = '\n'.join(instance_stats)
|
|
|
|
|
|
|
|
main_menu_header = quote(f'''{instance_title}\n{instance_stats}'''.strip())
|
|
|
|
except Exception as E:
|
2023-06-12 22:58:52 +00:00
|
|
|
splitted = ':\n'.join(str(E).split(':'))
|
|
|
|
main_menu_header = quote(f'''Connection failed:\n{splitted}'''.strip())
|
2023-06-10 19:53:51 +00:00
|
|
|
menu = ['Switch instance']
|
2022-12-18 01:02:53 +00:00
|
|
|
|
2022-12-04 01:01:11 +00:00
|
|
|
if not current_instance.s.headers.get('Authorization'):
|
2022-11-08 14:09:54 +00:00
|
|
|
menu.append('Sign in')
|
2022-11-27 23:17:21 +00:00
|
|
|
if support_message != '':
|
|
|
|
menu.append('Donate')
|
2022-11-28 22:02:39 +00:00
|
|
|
if src.mpv_control.player.playlist_playing_pos != -1:
|
2022-11-14 20:28:01 +00:00
|
|
|
menu.insert(0, 'Player')
|
2022-11-27 23:17:21 +00:00
|
|
|
ids = fzf.prompt(menu, f"--header={main_menu_header}")
|
2022-11-01 10:15:28 +00:00
|
|
|
|
|
|
|
selected = ids[0]
|
|
|
|
if selected == 'Radios':
|
|
|
|
list_radios()
|
2022-11-08 17:58:27 +00:00
|
|
|
if selected == 'Artists':
|
|
|
|
list_artists()
|
2022-11-08 18:08:24 +00:00
|
|
|
if selected == 'Albums':
|
|
|
|
list_albums()
|
2022-11-10 22:42:29 +00:00
|
|
|
if selected == 'Tracks':
|
|
|
|
list_tracks()
|
2022-11-09 01:01:02 +00:00
|
|
|
if selected == 'Channels':
|
|
|
|
list_channels()
|
2022-11-10 15:55:36 +00:00
|
|
|
if selected == 'Playlists':
|
|
|
|
list_playlists()
|
2022-11-15 01:22:32 +00:00
|
|
|
if selected == 'Favorites':
|
2023-06-06 23:37:52 +00:00
|
|
|
list_fav_or_history()
|
|
|
|
if selected == 'Recently listened':
|
|
|
|
list_fav_or_history(is_history_view=True)
|
2022-11-09 01:01:02 +00:00
|
|
|
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())
|
2022-11-09 22:15:57 +00:00
|
|
|
logger.info(str(returned_obj))
|
2023-06-13 21:59:09 +00:00
|
|
|
|
2022-11-03 23:45:40 +00:00
|
|
|
if selected == 'Switch instance':
|
|
|
|
with open('config.json', 'rt') as f:
|
|
|
|
conf = json.loads(f.read())
|
2022-11-27 23:48:22 +00:00
|
|
|
public_server_list_instances = settings.get_new_funkwhale_servers()
|
|
|
|
new_ins_count = len(settings.get_new_funkwhale_servers())
|
2022-12-18 01:02:53 +00:00
|
|
|
list_instances = conf.get(
|
|
|
|
'public_list_instances') + public_server_list_instances
|
2023-06-05 21:51:54 +00:00
|
|
|
settings.set_config('public_list_instances', list_instances)
|
2022-12-18 01:02:53 +00:00
|
|
|
instance = fzf.prompt(list_instances,
|
2022-11-27 23:48:22 +00:00
|
|
|
'--header='+quote(f'Select instance\nServer instances: +{new_ins_count}'))[0]
|
2022-12-04 01:01:11 +00:00
|
|
|
current_instance.select_instance(instance)
|
2022-11-08 14:09:54 +00:00
|
|
|
if selected == 'Sign in':
|
|
|
|
print(f'''
|
2023-06-13 21:59:09 +00:00
|
|
|
If You want sign in, please visit:
|
2022-11-08 14:09:54 +00:00
|
|
|
https://{instance}/settings/applications/new
|
|
|
|
And fill Name funkwhale-cli
|
2023-06-13 21:59:09 +00:00
|
|
|
Scopes: Read, Write (optional): write:favorites write:listenings write:filters
|
2022-11-08 14:09:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-12-04 01:01:11 +00:00
|
|
|
current_instance.select_instance(instance)
|
2022-11-27 23:17:21 +00:00
|
|
|
if selected == 'Donate':
|
|
|
|
print('Support instance message:')
|
|
|
|
print(support_message)
|
|
|
|
input()
|
2023-06-12 00:18:58 +00:00
|
|
|
if selected == 'About instance':
|
|
|
|
for i in ins_settings:
|
|
|
|
k, v = i.get('verbose_name'), i.get('value')
|
|
|
|
print(f'{k}: {v}')
|
|
|
|
print('|||||Some stats:')
|
|
|
|
for k, v in ins_nodeinfo['metadata']['usage'].items():
|
|
|
|
print(f'{k}: {v}')
|
|
|
|
for k, v in ins_nodeinfo['metadata']['library'].items():
|
|
|
|
print(f'{k}: {v}')
|
|
|
|
for k, v in ins_nodeinfo['usage'].items():
|
|
|
|
print(f'{k}: {v}')
|
|
|
|
input()
|
2022-11-14 20:28:01 +00:00
|
|
|
if selected == 'Player':
|
2022-12-18 01:02:53 +00:00
|
|
|
src.mpv_control.player_menu(
|
|
|
|
storage=src.mpv_control.player_fw_storage.storage)
|
2022-11-01 10:15:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|