mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-22 06:49:20 +02:00
Added view for favorites tracks
This commit is contained in:
parent
9139e0c78a
commit
e653cf27fe
|
@ -5,6 +5,7 @@ from src.fw_albums import list_albums
|
|||
from src.fw_tracks import list_tracks
|
||||
from src.fw_channels import list_channels
|
||||
from src.fw_playlists import list_playlists
|
||||
from src.fw_fav_tracks import list_favorites_tracks
|
||||
import src.settings as settings
|
||||
import src.mpv_control
|
||||
import json, sys
|
||||
|
@ -21,6 +22,7 @@ def main():
|
|||
'Tracks',
|
||||
'Channels',
|
||||
'Playlists',
|
||||
'Favorites',
|
||||
'Search',
|
||||
'Switch instance']
|
||||
if not s.headers.get('Authorization'):
|
||||
|
@ -42,6 +44,8 @@ def main():
|
|||
list_channels()
|
||||
if selected == 'Playlists':
|
||||
list_playlists()
|
||||
if selected == 'Favorites':
|
||||
list_favorites_tracks()
|
||||
if selected == 'Search':
|
||||
search_type = fzf.prompt(('Federated', 'All types'))[0]
|
||||
if search_type == 'Federated':
|
||||
|
|
|
@ -79,6 +79,21 @@ def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, incl
|
|||
r = s.get(f'https://{instance}/api/v1/tracks', params=params)
|
||||
return r.json()
|
||||
|
||||
@logger.catch
|
||||
def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None):
|
||||
'''This function get favorites tracks (not only for user)'''
|
||||
params = {
|
||||
'page': page,
|
||||
'q': q,
|
||||
'scope': scope,
|
||||
'include_channels': include_channels
|
||||
}
|
||||
if pg:
|
||||
r = s.get(pg)
|
||||
else:
|
||||
r = s.get(f'https://{instance}/api/v1/favorites/tracks/', params=params)
|
||||
return r.json()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, refresh=False, pg=None):
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
from src.fw_api import get_favorires_tracks, concatinate_endpoint
|
||||
from src.mpv_control import player, player_menu
|
||||
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')
|
||||
view = ['Search', 'Limit by scope']
|
||||
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}')
|
||||
select = fzf.prompt(view)[0].split('.', 1)[0]
|
||||
if select == 'Next page':
|
||||
list_favorites_tracks(pg=tracks_next)
|
||||
elif select == 'Prev page':
|
||||
list_favorites_tracks(pg=tracks_prev)
|
||||
elif select == 'Search':
|
||||
print('Search by track:')
|
||||
list_favorites_tracks(search=input())
|
||||
elif select == 'Limit by scope':
|
||||
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)
|
||||
else:
|
||||
play_track(track=tracks_results[int(select)]['track'])
|
||||
|
||||
|
||||
def play_track(track):
|
||||
storage = {}
|
||||
listen_url = concatinate_endpoint(track.get('listen_url'))
|
||||
storage[listen_url] = track
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
track_name = track.get('title')
|
||||
player_menu(f"{track_name} playing...", storage)
|
Loading…
Reference in New Issue