Compare commits

...

2 commits

2 changed files with 23 additions and 15 deletions

View file

@ -45,7 +45,7 @@ def main():
menu.append('Sign in')
if support_message != '':
menu.append('Donate')
if not src.mpv_control.player.core_idle:
if src.mpv_control.player.playlist_playing_pos != -1:
menu.insert(0, 'Player')
ids = fzf.prompt(menu, f"--header={main_menu_header}")

View file

@ -1,5 +1,5 @@
from src.fw_api import get_favorires_tracks, get_audio_file
from src.mpv_control import player, player_menu, track_url_to_uuid
from src.mpv_control import player, player_menu, track_url_to_uuid, player_fw_storage
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -11,7 +11,7 @@ def list_favorites_tracks(pg=None, search=None, scope=None):
tracks_next = tracks.get('next')
tracks_prev = tracks.get('previous')
tracks_results = tracks.get('results')
view = ['Search', 'Limit by scope']
view = ['Search', 'Limit by scope', 'Play this page']
if tracks_next:
view.append('Next page')
if tracks_prev:
@ -22,15 +22,15 @@ def list_favorites_tracks(pg=None, search=None, scope=None):
track_name = i['track'].get('title')
who_user = i['user'].get('username')
view.append(f'{index}.{track_name} | liked: {who_user}')
select = fzf.prompt(view)[0].split('.', 1)[0]
if select == 'Next page':
select = fzf.prompt(view, '--multi')
if 'Next page' in select:
list_favorites_tracks(pg=tracks_next)
elif select == 'Prev page':
elif 'Prev page' in select:
list_favorites_tracks(pg=tracks_prev)
elif select == 'Search':
elif 'Search' in select:
print('Search by track:')
list_favorites_tracks(search=input())
elif select == 'Limit by scope':
elif 'Limit by scope' in select:
print('''
Limit the results to a given user or pod:
@ -43,14 +43,22 @@ Limit the results to a given user or pod:
''')
scope = input()
list_favorites_tracks(scope=scope, search=search)
elif 'Play this page' in select:
for i in tracks_results:
play_track(track=i['track'], multi=True)
elif len(select) > 1:
for i in select:
play_track(track=tracks_results[int(i.split('.', 1)[0])]['track'], multi=True)
else:
play_track(track=tracks_results[int(select)]['track'])
play_track(track=tracks_results[int(select[0].split('.', 1)[0])]['track'])
def play_track(track):
storage = {}
def play_track(track, multi=False):
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)
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)