Add play page in tracks menu

This commit is contained in:
localhost_frssoft 2022-12-17 04:16:36 +03:00
parent b835454f11
commit 6c5113abcc
2 changed files with 15 additions and 10 deletions

View file

@ -1,6 +1,6 @@
from src.fw_api import get_tracks, get_audio_file
from src.fw_tags import list_tags
from src.mpv_control import player, player_menu, track_url_to_uuid
from src.mpv_control import player, player_menu, track_url_to_uuid, play_track
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -12,7 +12,7 @@ def list_tracks(pg=None, search=None, tag=None):
tracks_next = tracks.get('next')
tracks_prev = tracks.get('previous')
tracks_results = tracks.get('results')
view = ['Search', 'Tags']
view = ['Search', 'Tags', 'Play this page']
if tracks_next:
view.append('Next page')
if tracks_prev:
@ -33,14 +33,9 @@ def list_tracks(pg=None, search=None, tag=None):
elif select == 'Tags':
select_tag = list_tags()
list_tracks(tag=select_tag)
elif select == 'Play this page':
for i in tracks_results:
play_track(track=i, multi=True)
else:
play_track(track=tracks_results[int(select)])
def play_track(track):
storage = {}
listen_url = get_audio_file(track['listen_url'], True)
storage[track_url_to_uuid(listen_url)] = track
player.loadfile(listen_url, 'append-play')
track_name = track.get('title')
player_menu(f"{track_name} playing...", storage)

View file

@ -104,3 +104,13 @@ def player_menu(header='', storage={}):
except KeyboardInterrupt:
break
def play_track(track, multi=False):
listen_url = src.fw_api.get_audio_file(track['listen_url'], True)
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
if multi:
player.loadfile(listen_url, 'append-play')
else:
player.loadfile(listen_url, 'append-play')
track_name = track.get('title')
player_menu(f"{track_name} playing...", player_fw_storage.storage)