mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-22 16:51:27 +00:00
Python branch funkwhale-cli
This commit is contained in:
parent
a336656398
commit
e9a32e96ef
18
funkwhale_cli.py
Normal file
18
funkwhale_cli.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from src.fw_radios import list_radios
|
||||||
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
|
||||||
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
menu = ('Radios', )
|
||||||
|
ids = fzf.prompt(menu)
|
||||||
|
|
||||||
|
selected = ids[0]
|
||||||
|
if selected == 'Radios':
|
||||||
|
list_radios()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
30
src/fw_api.py
Normal file
30
src/fw_api.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import requests, json, time
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
with open('.auth.json', 'rt') as f:
|
||||||
|
auth = json.loads(f.read())
|
||||||
|
|
||||||
|
instance = 'fw.ponychord.rocks'
|
||||||
|
headers= {
|
||||||
|
"Authorization": "Bearer " + auth.get('fw.ponychord.rocks')
|
||||||
|
}
|
||||||
|
|
||||||
|
def concatinate_endpoint(endpoint):
|
||||||
|
return 'https://' + instance + endpoint
|
||||||
|
|
||||||
|
# [FunkWhale radios]
|
||||||
|
def get_radios():
|
||||||
|
r = requests.get(f'https://{instance}/api/v1/radios/radios/', headers=headers)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def post_radio_session(requested_radio):
|
||||||
|
r = requests.post(f'https://{instance}/api/v1/radios/sessions/', json=requested_radio, headers=headers)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_track_radio(radio_session):
|
||||||
|
r = requests.post(f'https://{instance}/api/v1/radios/tracks/',json=radio_session, headers=headers)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
44
src/fw_radios.py
Normal file
44
src/fw_radios.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
|
def list_radios():
|
||||||
|
radios = get_radios()
|
||||||
|
count = radios.get('count')
|
||||||
|
|
||||||
|
results = radios.get('results')
|
||||||
|
view = []
|
||||||
|
for i in results:
|
||||||
|
index = results.index(i)
|
||||||
|
id_radio = i.get('id')
|
||||||
|
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')
|
||||||
|
radio_load(id_radio)
|
||||||
|
|
||||||
|
|
||||||
|
def radio_load(id_radio):
|
||||||
|
requested_radio = {
|
||||||
|
'custom_radio': id_radio,
|
||||||
|
'radio_type': 'custom',
|
||||||
|
'related_object_id': None
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
def radio_get_track(radio_session_id):
|
||||||
|
radio_context = get_track_radio({'session': radio_session_id})
|
||||||
|
track = radio_context.get('track')
|
||||||
|
listen_url = track.get('listen_url')
|
||||||
|
player.playlist_append(concatinate_endpoint(listen_url))
|
||||||
|
|
||||||
|
|
17
src/mpv_control.py
Normal file
17
src/mpv_control.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import mpv
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
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(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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue