2022-11-08 19:23:19 +00:00
|
|
|
import src.fw_api
|
2022-11-08 18:02:07 +00:00
|
|
|
from src.utils import download_track
|
2022-11-10 00:23:46 +00:00
|
|
|
from src.settings import get_config
|
2022-11-01 10:15:28 +00:00
|
|
|
from loguru import logger
|
2022-11-08 18:02:07 +00:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
2022-11-02 00:05:08 +00:00
|
|
|
import mpv
|
|
|
|
|
2022-11-08 18:02:07 +00:00
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
2022-11-09 12:47:57 +00:00
|
|
|
player = mpv.MPV()
|
2022-11-10 00:23:46 +00: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 02:16:46 +00:00
|
|
|
show_like_button = get_config('show_like_button')
|
2022-11-08 18:02:07 +00:00
|
|
|
|
2022-11-14 20:28:01 +00:00
|
|
|
|
|
|
|
class player_fw_storage:
|
|
|
|
storage = {}
|
|
|
|
|
|
|
|
|
2022-11-08 18:02:07 +00:00
|
|
|
def set_http_header(headers=[]):
|
|
|
|
player.http_header_fields = headers
|
|
|
|
|
2022-11-09 09:49:33 +00:00
|
|
|
|
2022-11-18 10:22:55 +00:00
|
|
|
def track_url_to_uuid(listen_url=None):
|
2022-11-18 15:57:25 +00:00
|
|
|
'''Attempt get uuid from track listen url or current playing url'''
|
2022-11-18 10:22:55 +00:00
|
|
|
if listen_url:
|
|
|
|
uuid = listen_url.split(r'/')[-2]
|
|
|
|
else:
|
2022-11-18 15:57:25 +00:00
|
|
|
uuid = player.stream_open_filename.split(r'/')[-2]
|
2022-11-18 10:22:55 +00:00
|
|
|
return uuid
|
|
|
|
|
|
|
|
|
2022-11-08 18:37:43 +00:00
|
|
|
@logger.catch
|
2022-11-14 20:28:01 +00:00
|
|
|
def player_menu(header='', storage={}):
|
|
|
|
player_fw_storage.storage = storage
|
2022-11-14 23:02:22 +00:00
|
|
|
player.volume = get_config("mpv_volume")
|
2022-11-08 18:02:07 +00:00
|
|
|
while True:
|
|
|
|
try:
|
2022-11-13 02:16:46 +00:00
|
|
|
player_items_menu = ['Next', 'Prev', 'Pause',
|
|
|
|
'Download', 'Info']
|
2022-11-29 18:56:33 +00:00
|
|
|
if player.pause:
|
|
|
|
player_items_menu[2] = 'Play'
|
|
|
|
else:
|
|
|
|
player_items_menu[2] = 'Pause'
|
2022-11-13 02:16:46 +00:00
|
|
|
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 18:02:07 +00:00
|
|
|
if select == 'Next':
|
|
|
|
player.playlist_next()
|
|
|
|
elif select == 'Prev':
|
|
|
|
player.playlist_prev()
|
2022-11-29 18:56:33 +00:00
|
|
|
elif select in ('Pause', 'Play'):
|
2022-11-08 18:02:07 +00:00
|
|
|
if player.pause:
|
|
|
|
player.pause = False
|
|
|
|
else:
|
|
|
|
player.pause = True
|
|
|
|
elif select == 'Download':
|
|
|
|
print('Downloading...')
|
2022-11-18 15:57:25 +00:00
|
|
|
name_downloaded = download_track(player.stream_open_filename)
|
2022-11-08 18:02:07 +00:00
|
|
|
print(f'Downloaded: {name_downloaded}')
|
|
|
|
elif select == 'Info':
|
2022-11-18 10:22:55 +00:00
|
|
|
track = storage.get(track_url_to_uuid())
|
|
|
|
for i in track.keys():
|
2022-11-08 18:02:07 +00:00
|
|
|
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 02:16:46 +00:00
|
|
|
elif select == 'Like':
|
2022-11-18 10:22:55 +00:00
|
|
|
src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
|
2022-11-08 19:23:19 +00:00
|
|
|
elif select == 'Hide artist':
|
2022-11-18 10:22:55 +00:00
|
|
|
track = storage.get(track_url_to_uuid())
|
2022-11-08 19:23:19 +00:00
|
|
|
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
2022-11-08 18:02:07 +00:00
|
|
|
elif select == 'Exit':
|
|
|
|
player.playlist_clear()
|
|
|
|
player.stop()
|
|
|
|
break
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
break
|
|
|
|
|