mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-15 06:29:21 +02:00
Libraries filter now avalaible in artists, albums, tracks
This commit is contained in:
parent
8fa1773807
commit
dae0516052
|
@ -1,5 +1,6 @@
|
||||||
import src.fw_artists
|
import src.fw_artists
|
||||||
from src.fw_api import get_artists, get_tracks, get_albums, get_audio_file
|
from src.fw_api import get_artists, get_tracks, get_albums, get_audio_file
|
||||||
|
from src.fw_libraries import libraries
|
||||||
from src.settings import get_config
|
from src.settings import get_config
|
||||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
@ -9,13 +10,13 @@ fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None, refresh=False):
|
def list_albums(albums=None, pg=None, search=None, artist=None, library=None, include_channels=None, refresh=False):
|
||||||
show_artist_name_in_albums = get_config('show_artist_name_in_albums')
|
show_artist_name_in_albums = get_config('show_artist_name_in_albums')
|
||||||
albums_next = None
|
albums_next = None
|
||||||
albums_prev = None
|
albums_prev = None
|
||||||
play_artist_albums = False
|
play_artist_albums = False
|
||||||
if not albums:
|
if not albums:
|
||||||
albums = get_albums(q=search, artist=artist,
|
albums = get_albums(q=search, artist=artist, library=library,
|
||||||
include_channels=include_channels, refresh=refresh, pg=pg)
|
include_channels=include_channels, refresh=refresh, pg=pg)
|
||||||
albums_next = albums.get('next')
|
albums_next = albums.get('next')
|
||||||
albums_prev = albums.get('previous')
|
albums_prev = albums.get('previous')
|
||||||
|
@ -25,7 +26,7 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
|
||||||
else:
|
else:
|
||||||
play_artist_albums = True
|
play_artist_albums = True
|
||||||
albums_results = albums
|
albums_results = albums
|
||||||
view = ['Search']
|
view = ['Search', 'Library']
|
||||||
if play_artist_albums:
|
if play_artist_albums:
|
||||||
view.append('Play all')
|
view.append('Play all')
|
||||||
if albums_next:
|
if albums_next:
|
||||||
|
@ -50,6 +51,9 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
|
||||||
elif select == 'Search':
|
elif select == 'Search':
|
||||||
print('Search by albums: ')
|
print('Search by albums: ')
|
||||||
list_albums(search=input())
|
list_albums(search=input())
|
||||||
|
elif select == 'Library':
|
||||||
|
select_lib = libraries()
|
||||||
|
list_albums(library=select_lib)
|
||||||
elif select == 'Play all':
|
elif select == 'Play all':
|
||||||
if artist:
|
if artist:
|
||||||
src.fw_artists.play_artist(artist)
|
src.fw_artists.play_artist(artist)
|
||||||
|
|
|
@ -88,7 +88,7 @@ def get_audio_file(track_uuid, listen_url=False, download=False,
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_tracks(page=None, q=None, artist=None, album=None,
|
def get_tracks(page=None, q=None, artist=None, album=None, library=None,
|
||||||
tag=None, favourites=None, include_channels=None, pg=None):
|
tag=None, favourites=None, include_channels=None, pg=None):
|
||||||
'''This function get tracks by params'''
|
'''This function get tracks by params'''
|
||||||
params = {
|
params = {
|
||||||
|
@ -98,6 +98,7 @@ def get_tracks(page=None, q=None, artist=None, album=None,
|
||||||
'album': album,
|
'album': album,
|
||||||
'tag': tag,
|
'tag': tag,
|
||||||
'favourites': favourites,
|
'favourites': favourites,
|
||||||
|
'library': library,
|
||||||
'include_channels': include_channels
|
'include_channels': include_channels
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
|
@ -126,13 +127,15 @@ def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, p
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, refresh=False, pg=None):
|
def get_artists(page=None, q=None, artist=None, album=None,
|
||||||
|
library=None, favourites=None, refresh=False, pg=None):
|
||||||
'''This function get artists by params'''
|
'''This function get artists by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
'album': album,
|
'album': album,
|
||||||
|
'library': library,
|
||||||
'favourites': favourites,
|
'favourites': favourites,
|
||||||
'refresh': refresh
|
'refresh': refresh
|
||||||
}
|
}
|
||||||
|
@ -145,12 +148,13 @@ def get_artists(page=None, q=None, artist=None, album=None, favourites=None, ref
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_albums(page=None, q=None, artist=None, include_channels=None, refresh=False, pg=None):
|
def get_albums(page=None, q=None, artist=None, library=None, include_channels=None, refresh=False, pg=None):
|
||||||
'''This function get artists by params'''
|
'''This function get artists by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
|
'library': library,
|
||||||
'include_channels': include_channels,
|
'include_channels': include_channels,
|
||||||
'refresh': refresh
|
'refresh': refresh
|
||||||
}
|
}
|
||||||
|
@ -245,6 +249,25 @@ def federate_search_by_url(object):
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def federate_remote_library(fid):
|
||||||
|
'''Fetch remote library for follow and scan'''
|
||||||
|
params = {
|
||||||
|
'fid': fid
|
||||||
|
}
|
||||||
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/federation/libraries/fetch', json=params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def scan_remote_library(uuid):
|
||||||
|
'''Scan remote library'''
|
||||||
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}')
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def record_track_in_history(track_id):
|
def record_track_in_history(track_id):
|
||||||
params = {
|
params = {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from src.fw_api import get_artists, get_tracks, get_audio_file
|
from src.fw_api import get_artists, get_tracks, get_audio_file
|
||||||
from src.fw_albums import list_albums
|
from src.fw_albums import list_albums
|
||||||
|
from src.fw_libraries import libraries
|
||||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
@ -8,12 +9,12 @@ fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_artists(pg=None, search=None):
|
def list_artists(pg=None, search=None, library=None):
|
||||||
artists = get_artists(q=search, pg=pg)
|
artists = get_artists(q=search, library=library, pg=pg)
|
||||||
artists_next = artists.get('next')
|
artists_next = artists.get('next')
|
||||||
artists_prev = artists.get('previous')
|
artists_prev = artists.get('previous')
|
||||||
artists_results = artists.get('results')
|
artists_results = artists.get('results')
|
||||||
view = ['Search']
|
view = ['Search', 'Library']
|
||||||
if artists_next:
|
if artists_next:
|
||||||
view.append('Next page')
|
view.append('Next page')
|
||||||
if artists_prev:
|
if artists_prev:
|
||||||
|
@ -31,6 +32,9 @@ def list_artists(pg=None, search=None):
|
||||||
elif select == 'Search':
|
elif select == 'Search':
|
||||||
print('Search by artist:')
|
print('Search by artist:')
|
||||||
list_artists(search=input())
|
list_artists(search=input())
|
||||||
|
elif select == 'Library':
|
||||||
|
select_lib = libraries()
|
||||||
|
list_artists(library=select_lib)
|
||||||
else:
|
else:
|
||||||
albums = artists_results[int(select)].get('albums')
|
albums = artists_results[int(select)].get('albums')
|
||||||
if albums:
|
if albums:
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
from src.fw_api import list_libraries
|
from src.fw_api import list_libraries, federate_remote_library, scan_remote_library
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
import time
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def libraries(pg=None):
|
def libraries(pg=None, radio=False):
|
||||||
libs_res = list_libraries(pg=pg)
|
libs_res = list_libraries(pg=pg)
|
||||||
libs_count = libs_res.get('count')
|
libs_count = libs_res.get('count')
|
||||||
libs_next = libs_res.get('next')
|
libs_next = libs_res.get('next')
|
||||||
|
@ -17,6 +18,9 @@ def libraries(pg=None):
|
||||||
libraries_listing.append('Next')
|
libraries_listing.append('Next')
|
||||||
if libs_prev:
|
if libs_prev:
|
||||||
libraries_listing.append('Prev')
|
libraries_listing.append('Prev')
|
||||||
|
if radio == False:
|
||||||
|
libraries_listing.append('Add remote library')
|
||||||
|
|
||||||
for lib_i in libs:
|
for lib_i in libs:
|
||||||
index = libs.index(lib_i)
|
index = libs.index(lib_i)
|
||||||
lib_name = lib_i.get('name')
|
lib_name = lib_i.get('name')
|
||||||
|
@ -28,8 +32,33 @@ def libraries(pg=None):
|
||||||
return libraries(pg=libs_next)
|
return libraries(pg=libs_next)
|
||||||
elif lib_select[0] == 'Prev':
|
elif lib_select[0] == 'Prev':
|
||||||
return libraries(pg=libs_prev)
|
return libraries(pg=libs_prev)
|
||||||
|
elif lib_select[0] == 'Add remote library':
|
||||||
|
print('Search a remote library (url\\fid):')
|
||||||
|
new_library = federate_remote_library(input())
|
||||||
|
if new_library.get('detail'):
|
||||||
|
logger.error(new_library['detail'])
|
||||||
|
return
|
||||||
|
if new_library.get('count') > 0:
|
||||||
|
print('Library found')
|
||||||
|
one_lib = new_library['results'][0]
|
||||||
|
scan = scan_remote_library(one_lib['uuid'])
|
||||||
|
if scan.get('detail'):
|
||||||
|
logger.error(scan['detail'])
|
||||||
|
return
|
||||||
|
status = scan['status']
|
||||||
|
if status == 'scheduled':
|
||||||
|
print(f'Scanning {status}. Please wait few minutes for scan and open libraries menu again')
|
||||||
|
else:
|
||||||
|
print(f'Scan is {status}')
|
||||||
|
time.sleep(3)
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
lib_addr = lib_select[0]
|
lib_addr = lib_select[0]
|
||||||
lib_name = lib_select[1]
|
lib_name = lib_select[1]
|
||||||
lib_uuid = libs[int(lib_addr)].get('uuid')
|
lib_uuid = libs[int(lib_addr)]['uuid']
|
||||||
return None, 'library', lib_name, lib_uuid
|
lib_fid = libs[int(lib_addr)]['fid']
|
||||||
|
if radio:
|
||||||
|
return None, 'library', f'{lib_name}\n{lib_fid}', lib_uuid
|
||||||
|
else:
|
||||||
|
return lib_uuid
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ def list_radios():
|
||||||
elif 'Random' in selected:
|
elif 'Random' in selected:
|
||||||
radio_load(id_radio, 'random', name='totally random')
|
radio_load(id_radio, 'random', name='totally random')
|
||||||
elif 'Libraries' in selected:
|
elif 'Libraries' in selected:
|
||||||
id_radio, type_radio, name_radio, related_obj = libraries()
|
id_radio, type_radio, name_radio, related_obj = libraries(radio=True)
|
||||||
radio_load(id_radio, type_radio, name_radio, related_obj)
|
radio_load(id_radio, type_radio, name_radio, related_obj)
|
||||||
elif 'Users' in selected:
|
elif 'Users' in selected:
|
||||||
libs = list_libraries()['results']
|
libs = list_libraries()['results']
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from src.fw_api import get_tracks, get_audio_file
|
from src.fw_api import get_tracks, get_audio_file
|
||||||
from src.fw_tags import list_tags
|
from src.fw_tags import list_tags
|
||||||
|
from src.fw_libraries import libraries
|
||||||
from src.mpv_control import player, player_menu, track_url_to_uuid, play_track
|
from src.mpv_control import player, player_menu, track_url_to_uuid, play_track
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
@ -8,12 +9,12 @@ fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_tracks(pg=None, search=None, tag=None):
|
def list_tracks(pg=None, search=None, tag=None, library=None):
|
||||||
tracks = get_tracks(q=search, pg=pg, tag=tag)
|
tracks = get_tracks(q=search, pg=pg, tag=tag, library=library)
|
||||||
tracks_next = tracks.get('next')
|
tracks_next = tracks.get('next')
|
||||||
tracks_prev = tracks.get('previous')
|
tracks_prev = tracks.get('previous')
|
||||||
tracks_results = tracks.get('results')
|
tracks_results = tracks.get('results')
|
||||||
view = ['Search', 'Tags', 'Play this page']
|
view = ['Search', 'Tags', 'Library', 'Play this page']
|
||||||
if tracks_next:
|
if tracks_next:
|
||||||
view.append('Next page')
|
view.append('Next page')
|
||||||
if tracks_prev:
|
if tracks_prev:
|
||||||
|
@ -34,6 +35,9 @@ def list_tracks(pg=None, search=None, tag=None):
|
||||||
elif select == 'Tags':
|
elif select == 'Tags':
|
||||||
select_tag = list_tags()
|
select_tag = list_tags()
|
||||||
list_tracks(tag=select_tag)
|
list_tracks(tag=select_tag)
|
||||||
|
elif select == 'Library':
|
||||||
|
select_lib = libraries()
|
||||||
|
list_tracks(library=select_lib)
|
||||||
elif select == 'Play this page':
|
elif select == 'Play this page':
|
||||||
for i in tracks_results:
|
for i in tracks_results:
|
||||||
play_track(track=i, multi=True)
|
play_track(track=i, multi=True)
|
||||||
|
|
Loading…
Reference in New Issue