From 0b5c9f0d0259191a5d995fbde631a4744104e434 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 2 Nov 2022 03:05:08 +0300 Subject: [PATCH] Radio generator and other uncommited changes --- funkwhale_cli.py | 3 ++- src/fw_radios.py | 43 +++++++++++++++++++++++++++++++++++++++---- src/mpv_control.py | 13 +++++-------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 8afe05e..eb7fe43 100644 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -1,10 +1,11 @@ from src.fw_radios import list_radios +from loguru import logger from pyfzf.pyfzf import FzfPrompt fzf = FzfPrompt() - def main(): + logger.remove() while True: menu = ('Radios', ) ids = fzf.prompt(menu) diff --git a/src/fw_radios.py b/src/fw_radios.py index 6d9615d..292831c 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -1,7 +1,9 @@ from src.fw_api import get_radios, post_radio_session, get_track_radio, concatinate_endpoint from src.mpv_control import player from pyfzf.pyfzf import FzfPrompt - +import threading +import time + fzf = FzfPrompt() @@ -17,11 +19,18 @@ def list_radios(): name = i.get('name') view.append(f'{index}.{name}') - selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.')[0] - id_radio = results[int(selected)].get('id') + selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1) + id_selected = selected[0] + id_radio = results[int(id_selected)].get('id') radio_load(id_radio) +def radio_generator(radio_session_id): + while radio_session_id != '': + radio_get_track(radio_session_id) + time.sleep(60) + + def radio_load(id_radio): requested_radio = { 'custom_radio': id_radio, @@ -31,8 +40,34 @@ def radio_load(id_radio): radio_session_id = post_radio_session(requested_radio).get('id') for i in range(0, 10): radio_get_track(radio_session_id) + player.playlist_pos = 0 - player.wait_for_playback() + radio_task = threading.Thread(target=radio_generator, args=(radio_session_id,), daemon=True) + radio_task.start() + while True: + try: + print(len(player.playlist)) + select = fzf.prompt(('Next', 'Prev', 'Pause', 'Exit'), f'--header=\'Radio playing...\'')[0] + if select == 'Next': + radio_get_track(radio_session_id) + player.playlist_next() + elif select == 'Prev': + player.playlist_prev() + elif select == 'Pause': + if player.pause: + player.pause = False + else: + player.pause = True + elif select == 'Exit': + try: + radio_task.join(1) + except: + pass + player.playlist_clear() + player.stop() + break + except KeyboardInterrupt: + break def radio_get_track(radio_session_id): diff --git a/src/mpv_control.py b/src/mpv_control.py index 15a3d0c..da73f39 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -1,5 +1,7 @@ -import mpv +from src.fw_api import headers from loguru import logger +import mpv + def mpv_log(loglevel, component, message): if loglevel == 'info': @@ -7,11 +9,6 @@ def mpv_log(loglevel, component, message): elif loglevel == 'error': logger.error(f'{component} {message}') -player = mpv.MPV(log_handler=mpv_log, ytdl=False, - player_operation_mode='pseudo-gui', - script_opts='osc-layout=box,osc-seekbarstyle=bar,osc-deadzonesize=0,osc-minmousemove=3', - input_default_bindings=True, - input_vo_keyboard=True, - osc=True) - +player = mpv.MPV(log_handler=mpv_log, ytdl=False) +player.http_header_fields = ['Authorization: ' + headers.get('Authorization')]