mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-14 03:43:18 +00:00
69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
import src.fw_api
|
|
from src.utils import download_track
|
|
from loguru import logger
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
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()
|
|
|
|
list_options = dir(player)
|
|
if 'ytdl' in list_options:
|
|
player.ytdl = False
|
|
if 'prefetch_playlist' in list_options:
|
|
player.prefetch_playlist = True
|
|
|
|
|
|
def set_http_header(headers=[]):
|
|
player.http_header_fields = headers
|
|
|
|
|
|
@logger.catch
|
|
def player_menu(header=None, storage={}):
|
|
while True:
|
|
try:
|
|
select = fzf.prompt(('Next', 'Prev', 'Pause', 'Download', 'Info', 'Hide artist', 'Exit'), f"--header=\'{header}\'")[0]
|
|
if select == 'Next':
|
|
player.playlist_next()
|
|
elif select == 'Prev':
|
|
player.playlist_prev()
|
|
elif select == 'Pause':
|
|
if player.pause:
|
|
player.pause = False
|
|
else:
|
|
player.pause = True
|
|
elif select == 'Download':
|
|
print('Downloading...')
|
|
name_downloaded = download_track(player.filename)
|
|
print(f'Downloaded: {name_downloaded}')
|
|
elif select == 'Info':
|
|
track = storage.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 == 'Hide artist':
|
|
track = storage.get(player.filename)
|
|
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
|
elif select == 'Exit':
|
|
player.playlist_clear()
|
|
player.stop()
|
|
break
|
|
except KeyboardInterrupt:
|
|
break
|
|
|