2022-12-07 22:26:59 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-06-15 23:53:31 +03:00
|
|
|
from src.fw_api import current_instance, get_instance_settings, get_node_info
|
2022-11-01 12:15:28 +02:00
|
|
|
from src.fw_radios import list_radios
|
2022-11-08 19:58:27 +02:00
|
|
|
from src.fw_artists import list_artists
|
2022-11-08 20:08:24 +02:00
|
|
|
from src.fw_albums import list_albums
|
2022-11-11 00:42:29 +02:00
|
|
|
from src.fw_tracks import list_tracks
|
2022-11-09 03:01:02 +02:00
|
|
|
from src.fw_channels import list_channels
|
2022-11-10 17:55:36 +02:00
|
|
|
from src.fw_playlists import list_playlists
|
2023-06-07 02:37:52 +03:00
|
|
|
from src.fw_recents import list_fav_or_history
|
2023-06-26 14:26:20 +03:00
|
|
|
from src.fw_instances import instances_menu
|
2022-11-14 22:28:01 +02:00
|
|
|
import src.mpv_control
|
2022-12-18 03:02:53 +02:00
|
|
|
import json
|
2023-06-14 01:52:06 +03:00
|
|
|
import os
|
2022-11-28 01:17:21 +02:00
|
|
|
from shlex import quote
|
2023-06-15 23:55:45 +03:00
|
|
|
from shutil import get_terminal_size
|
2022-11-01 12:15:28 +02:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
|
2023-06-16 20:54:29 +03:00
|
|
|
os.environ['FZF_DEFAULT_OPTS'] = "--margin 2,0,0,0 --preview-window down:2:hidden:wrap --bind ?:toggle-preview --preview 'echo {}'"
|
2022-11-01 12:15:28 +02:00
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
2023-06-15 23:55:45 +03:00
|
|
|
os.system('clear')
|
|
|
|
if get_terminal_size().columns > 32:
|
|
|
|
print('\n\n')
|
|
|
|
os.system('cat .icon.txt')
|
2022-12-18 03:02:53 +02:00
|
|
|
|
2022-11-01 12:15:28 +02:00
|
|
|
def main():
|
2022-11-28 01:17:21 +02:00
|
|
|
|
2022-11-01 12:15:28 +02:00
|
|
|
while True:
|
2022-11-28 01:17:21 +02:00
|
|
|
support_message = ''
|
|
|
|
instance_title = ''
|
2023-06-10 22:53:51 +03:00
|
|
|
menu = ['Radios',
|
|
|
|
'Artists',
|
|
|
|
'Albums',
|
|
|
|
'Tracks',
|
|
|
|
'Channels',
|
|
|
|
'Playlists',
|
|
|
|
'Favorites',
|
|
|
|
'Recently listened',
|
2023-06-12 03:18:58 +03:00
|
|
|
'About instance',
|
2023-06-10 22:53:51 +03:00
|
|
|
'Switch instance']
|
2022-11-28 01:17:21 +02:00
|
|
|
try:
|
2023-06-15 23:53:31 +03:00
|
|
|
ins_nodeinfo = get_node_info()
|
|
|
|
support_message = ins_nodeinfo['metadata']['instanceSupportMessage']
|
|
|
|
instance_title = ins_nodeinfo['metadata']['nodeName']
|
2023-06-12 03:18:58 +03:00
|
|
|
instance_stats = []
|
|
|
|
for k, v in ins_nodeinfo['metadata']['library'].items():
|
2023-06-13 01:58:52 +03:00
|
|
|
if k == 'anonymousCanListen' and v == False and not current_instance.s.headers.get('Authorization'):
|
2023-06-12 03:18:58 +03:00
|
|
|
instance_stats.append(f'!!! {k}: {v} !!!')
|
2023-06-13 01:58:52 +03:00
|
|
|
menu = ['Switch instance', 'About instance']
|
2023-06-12 03:18:58 +03: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-13 01:58:52 +03:00
|
|
|
splitted = ':\n'.join(str(E).split(':'))
|
|
|
|
main_menu_header = quote(f'''Connection failed:\n{splitted}'''.strip())
|
2023-06-10 22:53:51 +03:00
|
|
|
menu = ['Switch instance']
|
2022-12-18 03:02:53 +02:00
|
|
|
|
2022-12-04 03:01:11 +02:00
|
|
|
if not current_instance.s.headers.get('Authorization'):
|
2022-11-08 16:09:54 +02:00
|
|
|
menu.append('Sign in')
|
2022-11-28 01:17:21 +02:00
|
|
|
if support_message != '':
|
|
|
|
menu.append('Donate')
|
2022-11-29 00:02:39 +02:00
|
|
|
if src.mpv_control.player.playlist_playing_pos != -1:
|
2022-11-14 22:28:01 +02:00
|
|
|
menu.insert(0, 'Player')
|
2023-06-15 00:52:34 +03:00
|
|
|
selected = fzf.prompt(menu, f"--header={main_menu_header}")
|
|
|
|
if selected == []:
|
|
|
|
print('bye-bye :3')
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
selected = selected[0]
|
2022-11-01 12:15:28 +02:00
|
|
|
|
|
|
|
if selected == 'Radios':
|
|
|
|
list_radios()
|
2022-11-08 19:58:27 +02:00
|
|
|
if selected == 'Artists':
|
|
|
|
list_artists()
|
2022-11-08 20:08:24 +02:00
|
|
|
if selected == 'Albums':
|
|
|
|
list_albums()
|
2022-11-11 00:42:29 +02:00
|
|
|
if selected == 'Tracks':
|
|
|
|
list_tracks()
|
2022-11-09 03:01:02 +02:00
|
|
|
if selected == 'Channels':
|
|
|
|
list_channels()
|
2022-11-10 17:55:36 +02:00
|
|
|
if selected == 'Playlists':
|
|
|
|
list_playlists()
|
2022-11-15 03:22:32 +02:00
|
|
|
if selected == 'Favorites':
|
2023-06-07 02:37:52 +03:00
|
|
|
list_fav_or_history()
|
|
|
|
if selected == 'Recently listened':
|
|
|
|
list_fav_or_history(is_history_view=True)
|
2022-11-04 01:45:40 +02:00
|
|
|
if selected == 'Switch instance':
|
2023-06-26 14:26:20 +03:00
|
|
|
instances_menu()
|
2022-11-08 16:09:54 +02:00
|
|
|
if selected == 'Sign in':
|
|
|
|
print(f'''
|
2023-06-14 00:59:09 +03:00
|
|
|
If You want sign in, please visit:
|
2023-06-14 15:27:15 +03:00
|
|
|
https://{current_instance.instance}/settings/applications/new
|
2022-11-08 16:09:54 +02:00
|
|
|
And fill Name funkwhale-cli
|
2023-06-15 15:11:21 +03:00
|
|
|
Scopes:
|
|
|
|
Read | Write (optional):
|
|
|
|
write:libraries
|
|
|
|
write:favorites
|
|
|
|
write:listenings
|
|
|
|
write:follows
|
|
|
|
write:filters
|
2022-11-08 16:09:54 +02:00
|
|
|
|
|
|
|
Insert token from "Access token" here''')
|
|
|
|
register_token = input()
|
|
|
|
with open('.auth.json', 'rt') as f:
|
2023-06-16 02:22:52 +03:00
|
|
|
tkns = json.load(f)
|
2022-11-08 16:09:54 +02:00
|
|
|
with open('.auth.json', 'wt') as f:
|
2023-06-14 15:27:15 +03:00
|
|
|
tkns[current_instance.instance] = register_token
|
2023-06-16 02:22:52 +03:00
|
|
|
f.write(json.dumps(tkns, indent=4))
|
2022-11-08 16:09:54 +02:00
|
|
|
del tkns
|
|
|
|
del register_token
|
|
|
|
del f
|
2023-06-14 15:27:15 +03:00
|
|
|
os.system('clear')
|
2022-11-08 16:09:54 +02:00
|
|
|
|
2023-06-14 15:27:15 +03:00
|
|
|
current_instance.select_instance(current_instance.instance)
|
2022-11-28 01:17:21 +02:00
|
|
|
if selected == 'Donate':
|
2023-06-15 19:07:56 +03:00
|
|
|
os.system(f'less <<EOF\nSupport instance message:\n{support_message}\nEOF')
|
2023-06-12 03:18:58 +03:00
|
|
|
if selected == 'About instance':
|
2023-06-15 23:53:31 +03:00
|
|
|
ins_settings = get_instance_settings()
|
2023-06-14 01:52:06 +03:00
|
|
|
about_instance_info = []
|
2023-06-12 03:18:58 +03:00
|
|
|
for i in ins_settings:
|
|
|
|
k, v = i.get('verbose_name'), i.get('value')
|
2023-06-14 01:52:06 +03:00
|
|
|
about_instance_info.append(f'{k}: {v}')
|
|
|
|
about_instance_info.append('|||||Some stats:')
|
2023-06-15 13:35:16 +03:00
|
|
|
if ins_nodeinfo['metadata'].get('usage'):
|
|
|
|
for k, v in ins_nodeinfo['metadata']['usage'].items():
|
|
|
|
about_instance_info.append(f'{k}: {v}')
|
2023-06-12 03:18:58 +03:00
|
|
|
for k, v in ins_nodeinfo['metadata']['library'].items():
|
2023-06-14 01:52:06 +03:00
|
|
|
about_instance_info.append(f'{k}: {v}')
|
2023-06-12 03:18:58 +03:00
|
|
|
for k, v in ins_nodeinfo['usage'].items():
|
2023-06-14 01:52:06 +03:00
|
|
|
about_instance_info.append(f'{k}: {v}')
|
|
|
|
about_instance_info = '\n'.join(about_instance_info)
|
2023-06-15 19:07:56 +03:00
|
|
|
os.system(f'less <<EOF\n{about_instance_info}\nEOF')
|
2023-06-14 01:52:06 +03:00
|
|
|
del about_instance_info
|
2022-11-14 22:28:01 +02:00
|
|
|
if selected == 'Player':
|
2022-12-18 03:02:53 +02:00
|
|
|
src.mpv_control.player_menu(
|
|
|
|
storage=src.mpv_control.player_fw_storage.storage)
|
2022-11-01 12:15:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|