mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-22 05:39:48 +00:00
Recently listenings
Favorites and Recently listening views added in one file
This commit is contained in:
parent
11dba2648d
commit
0677e0b863
@ -7,7 +7,7 @@ from src.fw_albums import list_albums
|
|||||||
from src.fw_tracks import list_tracks
|
from src.fw_tracks import list_tracks
|
||||||
from src.fw_channels import list_channels
|
from src.fw_channels import list_channels
|
||||||
from src.fw_playlists import list_playlists
|
from src.fw_playlists import list_playlists
|
||||||
from src.fw_fav_tracks import list_favorites_tracks
|
from src.fw_recents import list_fav_or_history
|
||||||
import src.settings as settings
|
import src.settings as settings
|
||||||
import src.mpv_control
|
import src.mpv_control
|
||||||
import json
|
import json
|
||||||
@ -44,6 +44,7 @@ def main():
|
|||||||
'Channels',
|
'Channels',
|
||||||
'Playlists',
|
'Playlists',
|
||||||
'Favorites',
|
'Favorites',
|
||||||
|
'Recently listened',
|
||||||
'Search',
|
'Search',
|
||||||
'Switch instance']
|
'Switch instance']
|
||||||
if not current_instance.s.headers.get('Authorization'):
|
if not current_instance.s.headers.get('Authorization'):
|
||||||
@ -68,7 +69,9 @@ def main():
|
|||||||
if selected == 'Playlists':
|
if selected == 'Playlists':
|
||||||
list_playlists()
|
list_playlists()
|
||||||
if selected == 'Favorites':
|
if selected == 'Favorites':
|
||||||
list_favorites_tracks()
|
list_fav_or_history()
|
||||||
|
if selected == 'Recently listened':
|
||||||
|
list_fav_or_history(is_history_view=True)
|
||||||
if selected == 'Search':
|
if selected == 'Search':
|
||||||
search_type = fzf.prompt(('Federated', 'All types'))[0]
|
search_type = fzf.prompt(('Federated', 'All types'))[0]
|
||||||
if search_type == 'Federated':
|
if search_type == 'Federated':
|
||||||
|
@ -123,7 +123,7 @@ def get_tracks(page=None, q=None, artist=None, album=None, library=None,
|
|||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None):
|
def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None):
|
||||||
'''This function get favorites tracks (not only for user)'''
|
'''Get favorites tracks (not only for user)'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
@ -138,6 +138,23 @@ def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, p
|
|||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def get_recently_listened(page=None, q=None, scope=None, include_channels=None, pg=None):
|
||||||
|
'''Get recently listened tracks (not only for user)'''
|
||||||
|
params = {
|
||||||
|
'page': page,
|
||||||
|
'q': q,
|
||||||
|
'scope': scope,
|
||||||
|
'include_channels': include_channels
|
||||||
|
}
|
||||||
|
if pg:
|
||||||
|
r = current_instance.s.get(pg)
|
||||||
|
else:
|
||||||
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/history/listenings', params=params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_artists(page=None, q=None, artist=None, album=None,
|
def get_artists(page=None, q=None, artist=None, album=None,
|
||||||
library=None, favourites=None, refresh=False, pg=None):
|
library=None, favourites=None, refresh=False, pg=None):
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
from src.fw_api import get_favorires_tracks, get_audio_file
|
|
||||||
from src.mpv_control import player, player_menu, track_url_to_uuid, player_fw_storage
|
|
||||||
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', 'Play this page']
|
|
||||||
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, '--multi')
|
|
||||||
if 'Next page' in select:
|
|
||||||
list_favorites_tracks(pg=tracks_next)
|
|
||||||
elif 'Prev page' in select:
|
|
||||||
list_favorites_tracks(pg=tracks_prev)
|
|
||||||
elif 'Search' in select:
|
|
||||||
print('Search by track:')
|
|
||||||
list_favorites_tracks(search=input())
|
|
||||||
elif 'Limit by scope' in select:
|
|
||||||
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)
|
|
||||||
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[0].split('.', 1)[0])]['track'])
|
|
||||||
|
|
||||||
|
|
||||||
def play_track(track, multi=False):
|
|
||||||
listen_url = 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)
|
|
Loading…
Reference in New Issue
Block a user