From dc40e5331c5141cb3a93a59118afca13bf01aa21 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 14 Jun 2023 15:27:15 +0300 Subject: [PATCH 1/6] Fix login in to new instance --- funkwhale_cli.py | 7 ++++--- src/fw_api.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 8b97953..759bd26 100755 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -104,7 +104,7 @@ def main(): if selected == 'Sign in': print(f''' If You want sign in, please visit: -https://{instance}/settings/applications/new +https://{current_instance.instance}/settings/applications/new And fill Name funkwhale-cli Scopes: Read, Write (optional): write:favorites write:listenings write:filters @@ -113,13 +113,14 @@ Insert token from "Access token" here''') with open('.auth.json', 'rt') as f: tkns = json.loads(f.read()) with open('.auth.json', 'wt') as f: - tkns[instance] = register_token + tkns[current_instance.instance] = register_token f.write(json.dumps(tkns)) del tkns del register_token del f + os.system('clear') - current_instance.select_instance(instance) + current_instance.select_instance(current_instance.instance) if selected == 'Donate': os.system(f'less < Date: Wed, 14 Jun 2023 17:37:36 +0300 Subject: [PATCH 2/6] Print info about track in less --- src/fw_radios.py | 3 +-- src/mpv_control.py | 3 +-- src/utils.py | 8 ++++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 2d6f6a4..456287a 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -148,9 +148,8 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non name_downloaded = download_track(player.stream_open_filename) elif select == 'Info': track = player_fw_storage.storage.get(track_url_to_uuid()) + track['direct_url'] = player.stream_open_filename track_info_output(track) - print('Direct link: ' + player.stream_open_filename) - input() elif select == 'Like': favorite_track(player_fw_storage.storage.get( track_url_to_uuid())['id']) diff --git a/src/mpv_control.py b/src/mpv_control.py index 15c2790..d57acf1 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -155,9 +155,8 @@ def player_menu(header='', storage={}): name_downloaded = download_track(player.stream_open_filename) elif select == 'Info': track = player_fw_storage.storage.get(track_url_to_uuid()) + track['direct_url'] = player.stream_open_filename track_info_output(track) - print('Direct link: ' + player.stream_open_filename) - input() elif select == 'Like': src.fw_api.favorite_track( player_fw_storage.storage.get(track_url_to_uuid())['id']) diff --git a/src/utils.py b/src/utils.py index 1d7391e..a1e70d6 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,5 +1,6 @@ import src.fw_api +import os import sys import shutil from urllib.parse import unquote @@ -57,12 +58,15 @@ def print_there(x, y, text): def track_info_output(track): + output = [] for k, v in track.items(): if k not in ('cover', 'uploads', 'listen_url', 'mbid', 'id', 'is_playable') and v is not None and v != []: if isinstance(v, dict): for i in ('title', 'name', 'fid'): if v.get(i): val_override = v.get(i) - print(f'{k}: {val_override}') + output.append(f'{k}: {val_override}') else: - print(f'{k}: {v}') + output.append(f'{k}: {v}') + output = '\n'.join(output) + os.system(f'less < Date: Wed, 14 Jun 2023 18:34:26 +0300 Subject: [PATCH 3/6] Libraries menu changed --- src/fw_libraries.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fw_libraries.py b/src/fw_libraries.py index 7189985..8dd9ce8 100644 --- a/src/fw_libraries.py +++ b/src/fw_libraries.py @@ -1,4 +1,4 @@ -from src.fw_api import list_libraries, federate_remote_library, scan_remote_library +from src.fw_api import current_instance, list_libraries, federate_remote_library, scan_remote_library from pyfzf.pyfzf import FzfPrompt from loguru import logger import time @@ -18,16 +18,18 @@ def libraries(pg=None, radio=False): libraries_listing.append('Next') if libs_prev: libraries_listing.append('Prev') - if radio == False: + if current_instance.s.headers.get('Authorization'): libraries_listing.append('Add remote library') for lib_i in libs: index = libs.index(lib_i) lib_name = lib_i.get('name') + lib_tracks_count = lib_i.get('uploads_count') lib_by = lib_i.get('actor').get('full_username') - libraries_listing.append(f'{index}.{lib_name} | by {lib_by}') + libraries_listing.append(f'{index}.{lib_name} | {lib_by} | {lib_tracks_count}') lib_select = fzf.prompt( - libraries_listing, f'--header=\'found {libs_count} libraries\'')[0].split('.', 1) + libraries_listing, + f'--header=\'found {libs_count} libraries\nmap: library name | owner | tracks count\'')[0].split('.', 1) if lib_select[0] == 'Next': return libraries(pg=libs_next) elif lib_select[0] == 'Prev': @@ -61,4 +63,3 @@ def libraries(pg=None, radio=False): return None, 'library', f'{lib_name}\n{lib_fid}', lib_uuid else: return lib_uuid - From 95874e228946a5e9e5fe7a6a72b90a225d0f5270 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 14 Jun 2023 19:11:50 +0300 Subject: [PATCH 4/6] removed search from main menu, is just useless --- funkwhale_cli.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 759bd26..a176bde 100755 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from src.fw_api import current_instance, federate_search_by_url, get_instance_settings +from src.fw_api import current_instance, get_instance_settings from src.fw_radios import list_radios from src.fw_artists import list_artists from src.fw_albums import list_albums @@ -13,7 +13,6 @@ import src.mpv_control import json import os from shlex import quote -from loguru import logger from pyfzf.pyfzf import FzfPrompt fzf = FzfPrompt() @@ -32,7 +31,6 @@ def main(): 'Playlists', 'Favorites', 'Recently listened', - 'Search', 'About instance', 'Switch instance'] try: @@ -83,13 +81,6 @@ def main(): list_fav_or_history() if selected == 'Recently listened': list_fav_or_history(is_history_view=True) - 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()) - logger.info(str(returned_obj)) - if selected == 'Switch instance': with open('config.json', 'rt') as f: conf = json.loads(f.read()) From f5840926a6227f1825f57bb68c9b06e725bb081b Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 14 Jun 2023 21:39:47 +0300 Subject: [PATCH 5/6] Threading always success stop without errors --- src/fw_radios.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 456287a..1e2b971 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -154,26 +154,18 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non favorite_track(player_fw_storage.storage.get( track_url_to_uuid())['id']) elif select == 'Exit': - try: - radio_event_gen.clear() - except: - logger.exception('Error stopping Thread radio generator') - pass + radio_event_gen.clear() soft_volume_reduce() player.playlist_clear() player.stop() player_fw_storage.storage = {} break - except: - try: - radio_event_gen.clear() - except: - logger.exception('Error stopping Thread radio generator') - pass + except Exception as E: + radio_event_gen.clear() player.playlist_clear() player.stop() player_fw_storage.storage = {} - logger.exception('Radio force stopped') + logger.exception(f'Radio force stopped: {E}') break From a76f36bafdd95ef7f42c06b8c0ad5bc3eadd3417 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 14 Jun 2023 23:05:14 +0300 Subject: [PATCH 6/6] Some fixes in radios --- src/fw_radios.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 1e2b971..631edfb 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -15,7 +15,7 @@ fzf = FzfPrompt() @logger.catch -def list_radios(): +def list_radios(error_given=None): radios = get_radios() count = radios.get('count') @@ -35,9 +35,12 @@ def list_radios(): view.append('Favourites') view.append('Less listened') view.extend(['Tag', 'Random', 'Libraries', 'Users', 'Recently Added']) - + header = f'Found {count} radios' + if error_given: + header += f'\n{error_given}' + header = quote(header) selected = fzf.prompt( - view, f'--header \'Found {count} radios\' --read0', delimiter="\0")[0].split('.', 1) + view, f'--header {header} --read0', delimiter="\0")[0].split('.', 1) if 'Favourites' in selected: radio_load(id_radio, 'favorites', name='your favorites tracks') elif 'Tag' in selected: @@ -104,7 +107,10 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non } radio_session_id = post_radio_session(requested_radio).get('id') for i in range(0, 2): - radio_get_track(radio_session_id) + try: + radio_get_track(radio_session_id, first_run=True) + except Exception as E: + return list_radios(error_given=f'Error: {E}') radio_event_gen.set() radio_task = threading.Thread( @@ -121,8 +127,12 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non player_items_menu[2] = 'Play' else: player_items_menu[2] = 'Pause' - select = fzf.prompt(player_items_menu, + try: + select = fzf.prompt(player_items_menu, quote(f"--header=\'Radio {name} playing...\'"))[0] + except: + select = 'Exit' + if select == 'Next': playlist_remaining = player.playlist_count - player.playlist_current_pos if playlist_remaining <= 2: @@ -169,7 +179,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non break -def radio_get_track(radio_session_id): +def radio_get_track(radio_session_id, first_run=False): radio_context = get_track_radio({'session': radio_session_id}) if not radio_context: return @@ -177,6 +187,9 @@ def radio_get_track(radio_session_id): logger.error(radio_context) if radio_context == "Radio doesn't have more candidates": radio_event_gen.clear() + if first_run: + radio_context = 'This radio may be private or haven\'t tracks' + raise IOError(radio_context) return if radio_context.get('error'): logger.error(radio_context.get('error'))