2022-11-08 21:23:19 +02:00
|
|
|
import src.fw_api
|
2022-11-08 20:02:07 +02:00
|
|
|
from src.utils import download_track
|
2022-11-10 02:23:46 +02:00
|
|
|
from src.settings import get_config
|
2022-11-01 12:15:28 +02:00
|
|
|
from loguru import logger
|
2022-11-08 20:02:07 +02:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
2022-11-02 02:05:08 +02:00
|
|
|
import mpv
|
|
|
|
|
2022-11-08 20:02:07 +02:00
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
2022-11-09 14:47:57 +02:00
|
|
|
player = mpv.MPV()
|
2022-11-10 02:23:46 +02:00
|
|
|
player.ytdl = False # Prevent attempts load track with yt-dlp
|
|
|
|
player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic
|
2022-11-13 04:16:46 +02:00
|
|
|
show_like_button = get_config('show_like_button')
|
2022-11-08 20:02:07 +02:00
|
|
|
|
|
|
|
def set_http_header(headers=[]):
|
|
|
|
player.http_header_fields = headers
|
|
|
|
|
2022-11-09 11:49:33 +02:00
|
|
|
|
2022-11-08 20:37:43 +02:00
|
|
|
@logger.catch
|
2022-11-08 20:02:07 +02:00
|
|
|
def player_menu(header=None, storage={}):
|
|
|
|
while True:
|
|
|
|
try:
|
2022-11-13 04:16:46 +02:00
|
|
|
player_items_menu = ['Next', 'Prev', 'Pause',
|
|
|
|
'Download', 'Info']
|
|
|
|
if show_like_button:
|
|
|
|
player_items_menu.append('Like')
|
|
|
|
player_items_menu.extend(['Hide artist', 'Exit'])
|
|
|
|
|
|
|
|
select = fzf.prompt(player_items_menu, f"--header=\'{header}\'")[0]
|
2022-11-08 20:02:07 +02:00
|
|
|
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()
|
2022-11-13 04:16:46 +02:00
|
|
|
elif select == 'Like':
|
|
|
|
src.fw_api.favorite_track(storage.get(player.filename).get('id'))
|
2022-11-08 21:23:19 +02:00
|
|
|
elif select == 'Hide artist':
|
|
|
|
track = storage.get(player.filename)
|
|
|
|
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
2022-11-08 20:02:07 +02:00
|
|
|
elif select == 'Exit':
|
|
|
|
player.playlist_clear()
|
|
|
|
player.stop()
|
|
|
|
break
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
break
|
|
|
|
|