2022-11-18 15:57:25 +00:00
|
|
|
from src.fw_api import get_favorires_tracks, get_audio_file
|
2022-11-28 22:04:18 +00:00
|
|
|
from src.mpv_control import player, player_menu, track_url_to_uuid, player_fw_storage
|
2022-11-15 01:22:32 +00:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
|
|
|
@logger.catch
|
|
|
|
def list_favorites_tracks(pg=None, search=None, scope=None):
|
|
|
|
tracks = get_favorires_tracks(q=search, scope=scope, pg=pg)
|
|
|
|
tracks_next = tracks.get('next')
|
|
|
|
tracks_prev = tracks.get('previous')
|
|
|
|
tracks_results = tracks.get('results')
|
2022-11-28 22:04:18 +00:00
|
|
|
view = ['Search', 'Limit by scope', 'Play this page']
|
2022-11-15 01:22:32 +00:00
|
|
|
if tracks_next:
|
|
|
|
view.append('Next page')
|
|
|
|
if tracks_prev:
|
|
|
|
view.append('Prev page')
|
|
|
|
|
|
|
|
for i in tracks_results:
|
|
|
|
index = tracks_results.index(i)
|
|
|
|
track_name = i['track'].get('title')
|
|
|
|
who_user = i['user'].get('username')
|
|
|
|
view.append(f'{index}.{track_name} | liked: {who_user}')
|
2022-11-28 22:04:18 +00:00
|
|
|
select = fzf.prompt(view, '--multi')
|
|
|
|
if 'Next page' in select:
|
2022-11-15 01:22:32 +00:00
|
|
|
list_favorites_tracks(pg=tracks_next)
|
2022-11-28 22:04:18 +00:00
|
|
|
elif 'Prev page' in select:
|
2022-11-15 01:22:32 +00:00
|
|
|
list_favorites_tracks(pg=tracks_prev)
|
2022-11-28 22:04:18 +00:00
|
|
|
elif 'Search' in select:
|
2022-11-15 01:22:32 +00:00
|
|
|
print('Search by track:')
|
|
|
|
list_favorites_tracks(search=input())
|
2022-11-28 22:04:18 +00:00
|
|
|
elif 'Limit by scope' in select:
|
2022-11-15 01:22:32 +00:00
|
|
|
print('''
|
|
|
|
Limit the results to a given user or pod:
|
|
|
|
|
|
|
|
Use all (or do not specify the property to disable scope filtering)
|
|
|
|
Use me to retrieve content relative to the current user
|
|
|
|
Use subscribed to retrieve content in libraries you follow
|
|
|
|
Use actor:alice@example.com to retrieve content relative to the account `alice@example.com
|
|
|
|
Use domain:example.com to retrieve content relative to the domain `example.com
|
|
|
|
|
|
|
|
''')
|
|
|
|
scope = input()
|
|
|
|
list_favorites_tracks(scope=scope, search=search)
|
2022-11-28 22:04:18 +00:00
|
|
|
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)
|
2022-11-15 01:22:32 +00:00
|
|
|
else:
|
2022-11-28 22:04:18 +00:00
|
|
|
play_track(track=tracks_results[int(select[0].split('.', 1)[0])]['track'])
|
2022-11-15 01:22:32 +00:00
|
|
|
|
|
|
|
|
2022-11-28 22:04:18 +00:00
|
|
|
def play_track(track, multi=False):
|
2022-11-18 15:57:25 +00:00
|
|
|
listen_url = get_audio_file(track['listen_url'], True)
|
2022-11-28 22:04:18 +00:00
|
|
|
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)
|