mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-25 23:31:27 +00:00
Some changes
Add radio by library (manual input) Add info about current track Smaller first loading radio Prefetching playlist by default
This commit is contained in:
parent
2daed6599b
commit
474235d9e2
|
@ -8,6 +8,7 @@ import time
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
audio_info = {}
|
||||||
|
|
||||||
def list_radios():
|
def list_radios():
|
||||||
radios = get_radios()
|
radios = get_radios()
|
||||||
|
@ -24,6 +25,7 @@ def list_radios():
|
||||||
view.append('Favourites')
|
view.append('Favourites')
|
||||||
view.append('Less listened')
|
view.append('Less listened')
|
||||||
view.append('Random')
|
view.append('Random')
|
||||||
|
view.append('Library')
|
||||||
view.append('Recently Added')
|
view.append('Recently Added')
|
||||||
|
|
||||||
selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1)
|
selected = fzf.prompt(view, f'--header \'Found {count} radios\'')[0].split('.', 1)
|
||||||
|
@ -31,6 +33,10 @@ def list_radios():
|
||||||
radio_load(id_radio, 'favorites')
|
radio_load(id_radio, 'favorites')
|
||||||
elif 'Random' in selected:
|
elif 'Random' in selected:
|
||||||
radio_load(id_radio, 'random')
|
radio_load(id_radio, 'random')
|
||||||
|
elif 'Library' in selected:
|
||||||
|
print('Input library address (ex. example@example.example): ')
|
||||||
|
lib_addr = input()
|
||||||
|
radio_load(None, 'actor-content', lib_addr, lib_addr)
|
||||||
elif 'Recently Added' in selected:
|
elif 'Recently Added' in selected:
|
||||||
radio_load(id_radio, 'recently-added')
|
radio_load(id_radio, 'recently-added')
|
||||||
elif 'Less listened' in selected:
|
elif 'Less listened' in selected:
|
||||||
|
@ -56,23 +62,22 @@ def radio_generator(radio_session_id):
|
||||||
|
|
||||||
radio_event_gen = threading.Event()
|
radio_event_gen = threading.Event()
|
||||||
|
|
||||||
def radio_load(id_radio=None, type_radio='custom', name=None):
|
def radio_load(id_radio=None, type_radio='custom', name=None, related_object=None):
|
||||||
requested_radio = {
|
requested_radio = {
|
||||||
'custom_radio': id_radio,
|
'custom_radio': id_radio,
|
||||||
'radio_type': type_radio,
|
'radio_type': type_radio,
|
||||||
'related_object_id': None
|
'related_object_id': related_object
|
||||||
}
|
}
|
||||||
radio_session_id = post_radio_session(requested_radio).get('id')
|
radio_session_id = post_radio_session(requested_radio).get('id')
|
||||||
for i in range(0, 5):
|
for i in range(0, 2):
|
||||||
radio_get_track(radio_session_id)
|
radio_get_track(radio_session_id)
|
||||||
|
|
||||||
player.playlist_pos = 0
|
|
||||||
radio_event_gen.set()
|
radio_event_gen.set()
|
||||||
radio_task = threading.Thread(target=radio_generator, args=(radio_session_id,), daemon=True)
|
radio_task = threading.Thread(target=radio_generator, args=(radio_session_id,), daemon=True)
|
||||||
radio_task.start()
|
radio_task.start()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
select = fzf.prompt(('Next', 'Prev', 'Pause', 'Download', 'Exit'), f"--header=\'Radio {name} playing...\'")[0]
|
select = fzf.prompt(('Next', 'Prev', 'Pause', 'Download', 'Info', 'Exit'), f"--header=\'Radio {name} playing...\'")[0]
|
||||||
if select == 'Next':
|
if select == 'Next':
|
||||||
radio_get_track(radio_session_id)
|
radio_get_track(radio_session_id)
|
||||||
player.playlist_next()
|
player.playlist_next()
|
||||||
|
@ -87,6 +92,18 @@ def radio_load(id_radio=None, type_radio='custom', name=None):
|
||||||
print('Downloading...')
|
print('Downloading...')
|
||||||
name_downloaded = download_track(player.filename)
|
name_downloaded = download_track(player.filename)
|
||||||
print(f'Downloaded: {name_downloaded}')
|
print(f'Downloaded: {name_downloaded}')
|
||||||
|
elif select == 'Info':
|
||||||
|
track = audio_info.get(player.filename)
|
||||||
|
for i in ('title', 'fid', 'license', 'album', 'artist'):
|
||||||
|
if i in ('album', 'artist'):
|
||||||
|
name_aa = track.get(i).get('name')
|
||||||
|
if not name_aa:
|
||||||
|
name_aa = track.get(i).get('title')
|
||||||
|
print(i + ': '+ name_aa)
|
||||||
|
key = track.get(i)
|
||||||
|
if key and isinstance(key, str):
|
||||||
|
print(i + ': ' + key)
|
||||||
|
input()
|
||||||
elif select == 'Exit':
|
elif select == 'Exit':
|
||||||
try:
|
try:
|
||||||
radio_event_gen.clear()
|
radio_event_gen.clear()
|
||||||
|
@ -109,6 +126,7 @@ def radio_get_track(radio_session_id):
|
||||||
else:
|
else:
|
||||||
track = radio_context.get('track')
|
track = radio_context.get('track')
|
||||||
listen_url = track.get('listen_url')
|
listen_url = track.get('listen_url')
|
||||||
player.playlist_append(concatinate_endpoint(listen_url))
|
audio_info[concatinate_endpoint(listen_url)] = track
|
||||||
|
player.loadfile(concatinate_endpoint(listen_url), 'append-play')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import mpv
|
import mpv
|
||||||
|
|
||||||
|
|
||||||
def mpv_log(loglevel, component, message):
|
def mpv_log(loglevel, component, message):
|
||||||
if loglevel == 'info':
|
if loglevel == 'info':
|
||||||
logger.info(f'{component} {message}')
|
logger.info(f'{component} {message}')
|
||||||
elif loglevel == 'error':
|
elif loglevel == 'error':
|
||||||
logger.error(f'{component} {message}')
|
logger.error(f'{component} {message}')
|
||||||
|
|
||||||
player = mpv.MPV(log_handler=mpv_log, ytdl=False)
|
player = mpv.MPV(log_handler=mpv_log, ytdl=False,
|
||||||
|
prefetch_playlist=True)
|
||||||
|
|
Loading…
Reference in a new issue