mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-27 17:43:02 +00:00
Radio generator and other uncommited changes
This commit is contained in:
parent
e9a32e96ef
commit
0b5c9f0d02
@ -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)
|
||||
|
@ -1,6 +1,8 @@
|
||||
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):
|
||||
|
@ -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')]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user