Libraries filter now avalaible in artists, albums, tracks

This commit is contained in:
localhost_frssoft 2022-12-29 23:14:28 +03:00
parent 8fa1773807
commit dae0516052
6 changed files with 81 additions and 17 deletions

View File

@ -1,5 +1,6 @@
import src.fw_artists
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.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
@ -9,13 +10,13 @@ fzf = FzfPrompt()
@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')
albums_next = None
albums_prev = None
play_artist_albums = False
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)
albums_next = albums.get('next')
albums_prev = albums.get('previous')
@ -25,7 +26,7 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
else:
play_artist_albums = True
albums_results = albums
view = ['Search']
view = ['Search', 'Library']
if play_artist_albums:
view.append('Play all')
if albums_next:
@ -50,6 +51,9 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
elif select == 'Search':
print('Search by albums: ')
list_albums(search=input())
elif select == 'Library':
select_lib = libraries()
list_albums(library=select_lib)
elif select == 'Play all':
if artist:
src.fw_artists.play_artist(artist)

View File

@ -88,7 +88,7 @@ def get_audio_file(track_uuid, listen_url=False, download=False,
@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):
'''This function get tracks by params'''
params = {
@ -98,6 +98,7 @@ def get_tracks(page=None, q=None, artist=None, album=None,
'album': album,
'tag': tag,
'favourites': favourites,
'library': library,
'include_channels': include_channels
}
if pg:
@ -126,13 +127,15 @@ def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, p
@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'''
params = {
'page': page,
'q': q,
'artist': artist,
'album': album,
'library': library,
'favourites': favourites,
'refresh': refresh
}
@ -145,12 +148,13 @@ def get_artists(page=None, q=None, artist=None, album=None, favourites=None, ref
@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'''
params = {
'page': page,
'q': q,
'artist': artist,
'library': library,
'include_channels': include_channels,
'refresh': refresh
}
@ -245,6 +249,25 @@ def federate_search_by_url(object):
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
def record_track_in_history(track_id):
params = {

View File

@ -1,5 +1,6 @@
from src.fw_api import get_artists, get_tracks, get_audio_file
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 pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -8,12 +9,12 @@ fzf = FzfPrompt()
@logger.catch
def list_artists(pg=None, search=None):
artists = get_artists(q=search, pg=pg)
def list_artists(pg=None, search=None, library=None):
artists = get_artists(q=search, library=library, pg=pg)
artists_next = artists.get('next')
artists_prev = artists.get('previous')
artists_results = artists.get('results')
view = ['Search']
view = ['Search', 'Library']
if artists_next:
view.append('Next page')
if artists_prev:
@ -31,6 +32,9 @@ def list_artists(pg=None, search=None):
elif select == 'Search':
print('Search by artist:')
list_artists(search=input())
elif select == 'Library':
select_lib = libraries()
list_artists(library=select_lib)
else:
albums = artists_results[int(select)].get('albums')
if albums:

View File

@ -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 loguru import logger
import time
fzf = FzfPrompt()
@logger.catch
def libraries(pg=None):
def libraries(pg=None, radio=False):
libs_res = list_libraries(pg=pg)
libs_count = libs_res.get('count')
libs_next = libs_res.get('next')
@ -17,6 +18,9 @@ def libraries(pg=None):
libraries_listing.append('Next')
if libs_prev:
libraries_listing.append('Prev')
if radio == False:
libraries_listing.append('Add remote library')
for lib_i in libs:
index = libs.index(lib_i)
lib_name = lib_i.get('name')
@ -28,8 +32,33 @@ def libraries(pg=None):
return libraries(pg=libs_next)
elif lib_select[0] == '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:
lib_addr = lib_select[0]
lib_name = lib_select[1]
lib_uuid = libs[int(lib_addr)].get('uuid')
return None, 'library', lib_name, lib_uuid
lib_uuid = libs[int(lib_addr)]['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

View File

@ -45,7 +45,7 @@ def list_radios():
elif 'Random' in selected:
radio_load(id_radio, 'random', name='totally random')
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)
elif 'Users' in selected:
libs = list_libraries()['results']

View File

@ -1,5 +1,6 @@
from src.fw_api import get_tracks, get_audio_file
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 pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -8,12 +9,12 @@ fzf = FzfPrompt()
@logger.catch
def list_tracks(pg=None, search=None, tag=None):
tracks = get_tracks(q=search, pg=pg, tag=tag)
def list_tracks(pg=None, search=None, tag=None, library=None):
tracks = get_tracks(q=search, pg=pg, tag=tag, library=library)
tracks_next = tracks.get('next')
tracks_prev = tracks.get('previous')
tracks_results = tracks.get('results')
view = ['Search', 'Tags', 'Play this page']
view = ['Search', 'Tags', 'Library', 'Play this page']
if tracks_next:
view.append('Next page')
if tracks_prev:
@ -34,6 +35,9 @@ def list_tracks(pg=None, search=None, tag=None):
elif select == 'Tags':
select_tag = list_tags()
list_tracks(tag=select_tag)
elif select == 'Library':
select_lib = libraries()
list_tracks(library=select_lib)
elif select == 'Play this page':
for i in tracks_results:
play_track(track=i, multi=True)