From 93380080d06988c8f2bd90f5045019697e139bc5 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Fri, 11 Nov 2022 01:42:29 +0300 Subject: [PATCH] Added partially working tracks list; Removed mpv logger func --- funkwhale_cli.py | 4 ++++ src/fw_tracks.py | 42 ++++++++++++++++++++++++++++++++++++++++++ src/mpv_control.py | 7 ------- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/fw_tracks.py diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 1c96bde..dd354fb 100644 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -2,6 +2,7 @@ from src.fw_api import s, select_instance, instance, federate_search_by_url from src.fw_radios import list_radios from src.fw_artists import list_artists from src.fw_albums import list_albums +from src.fw_tracks import list_tracks from src.fw_channels import list_channels from src.fw_playlists import list_playlists import src.settings as settings @@ -16,6 +17,7 @@ def main(): menu = ['Radios', 'Artists', 'Albums', + 'Tracks', 'Channels', 'Playlists', 'Search', @@ -31,6 +33,8 @@ def main(): list_artists() if selected == 'Albums': list_albums() + if selected == 'Tracks': + list_tracks() if selected == 'Channels': list_channels() if selected == 'Playlists': diff --git a/src/fw_tracks.py b/src/fw_tracks.py new file mode 100644 index 0000000..a90f7a3 --- /dev/null +++ b/src/fw_tracks.py @@ -0,0 +1,42 @@ +from src.fw_api import get_tracks, concatinate_endpoint +from src.mpv_control import player, player_menu +from pyfzf.pyfzf import FzfPrompt +from loguru import logger + +fzf = FzfPrompt() + +@logger.catch +def list_tracks(pg=None, search=None): + tracks = get_tracks(q=search, pg=pg) + tracks_next = tracks.get('next') + tracks_prev = tracks.get('previous') + tracks_results = tracks.get('results') + view = ['Search'] + if tracks_next: + view.append('Next page') + if tracks_prev: + view.append('Prev page') + + for i in tracks_results: + index = tracks_results.index(i) + track_name = i.get('title') + view.append(f'{index}.{track_name}') + select = fzf.prompt(view)[0].split('.', 1)[0] + if select == 'Next page': + list_tracks(pg=tracks_next) + elif select == 'Prev page': + list_tracks(pg=tracks_prev) + elif select == 'Search': + print('Search by track:') + list_tracks(search=input()) + else: + play_track(track=tracks_results[int(select)]) + + +def play_track(track): + storage = {} + listen_url = concatinate_endpoint(track.get('listen_url')) + storage[listen_url] = track + player.loadfile(listen_url, 'append-play') + track_name = track.get('title') + player_menu(f"{track_name} playing...", storage) diff --git a/src/mpv_control.py b/src/mpv_control.py index 1661561..1146830 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -7,13 +7,6 @@ import mpv fzf = FzfPrompt() - -def mpv_log(loglevel, component, message): - if loglevel == 'info': - logger.info(f'{component} {message}') - elif loglevel == 'error': - logger.error(f'{component} {message}') - player = mpv.MPV() player.ytdl = False # Prevent attempts load track with yt-dlp player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic