2022-11-09 03:01:02 +02:00
|
|
|
from src.fw_api import s, select_instance, instance, federate_search_by_url
|
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
|
2022-11-09 20:51:20 +02:00
|
|
|
import src.settings as settings
|
2022-11-07 00:21:49 +02:00
|
|
|
import json, sys
|
2022-11-02 02:05:08 +02:00
|
|
|
from loguru import logger
|
2022-11-01 12:15:28 +02:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
|
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
while True:
|
2022-11-08 19:58:27 +02:00
|
|
|
menu = ['Radios',
|
|
|
|
'Artists',
|
2022-11-09 03:01:02 +02:00
|
|
|
'Albums',
|
2022-11-11 00:42:29 +02:00
|
|
|
'Tracks',
|
2022-11-09 03:01:02 +02:00
|
|
|
'Channels',
|
2022-11-10 17:55:36 +02:00
|
|
|
'Playlists',
|
2022-11-09 03:01:02 +02:00
|
|
|
'Search',
|
2022-11-08 19:58:27 +02:00
|
|
|
'Switch instance']
|
2022-11-08 16:09:54 +02:00
|
|
|
if not s.headers.get('Authorization'):
|
|
|
|
menu.append('Sign in')
|
2022-11-01 12:15:28 +02:00
|
|
|
ids = fzf.prompt(menu)
|
|
|
|
|
|
|
|
selected = ids[0]
|
|
|
|
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-09 03:01:02 +02: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-10 00:15:57 +02:00
|
|
|
logger.info(str(returned_obj))
|
2022-11-09 03:01:02 +02:00
|
|
|
|
2022-11-04 01:45:40 +02:00
|
|
|
if selected == 'Switch instance':
|
|
|
|
with open('config.json', 'rt') as f:
|
|
|
|
conf = json.loads(f.read())
|
2022-11-09 20:51:20 +02:00
|
|
|
list_instances = conf.get('public_list_instances') + settings.get_new_funkwhale_servers()
|
2022-11-04 01:45:40 +02:00
|
|
|
instance = fzf.prompt(list_instances, '--header \'Select instance\'')[0]
|
|
|
|
select_instance(instance)
|
2022-11-08 16:09:54 +02:00
|
|
|
if selected == 'Sign in':
|
|
|
|
print(f'''
|
|
|
|
If You want sign in, please visit:
|
|
|
|
https://{instance}/settings/applications/new
|
|
|
|
And fill Name funkwhale-cli
|
2022-11-08 21:23:19 +02:00
|
|
|
Scopes: Read (only listen music), Write (optional)
|
2022-11-08 16:09:54 +02: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
|
|
|
|
|
|
|
|
select_instance(instance)
|
|
|
|
|
2022-11-01 12:15:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|