Compare commits

...

2 Commits

Author SHA1 Message Date
localhost_frssoft 2359ffe922 search in libraries menu 2023-08-03 00:29:11 +03:00
localhost_frssoft f4b029630d added related libraries track info 2023-08-03 00:18:48 +03:00
3 changed files with 31 additions and 6 deletions

View File

@ -274,6 +274,20 @@ def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
return r.json()
@logger.catch
def assigned_libraries_on_track(track_id, page=None, page_size=None, pg=None):
params = {
'page': page,
'page_size': page_size,
}
if pg:
r = current_instance.s.get(pg)
else:
r = current_instance.s.get(
f'https://{current_instance.instance}/api/v1/tracks/{track_id}/libraries', params=params)
return r.json()
@logger.catch
def get_tags(q=None, ordering='-creation_date', pg=None):
params = {

View File

@ -7,13 +7,13 @@ fzf = FzfPrompt()
@logger.catch
def libraries(pg=None, radio=False):
libs_res = list_libraries(pg=pg)
def libraries(pg=None, radio=False, search=None):
libs_res = list_libraries(pg=pg, q=search)
libs_count = libs_res.get('count')
libs_next = libs_res.get('next')
libs_prev = libs_res.get('previous')
libs = libs_res.get('results')
libraries_listing = []
libraries_listing = ['Search']
if libs_next:
libraries_listing.append('Next')
if libs_prev:
@ -37,9 +37,12 @@ def libraries(pg=None, radio=False):
lib_select = lib_select[0].split('.', 1)
if lib_select[0] == 'Next':
return libraries(pg=libs_next)
return libraries(pg=libs_next, search=search)
elif lib_select[0] == 'Prev':
return libraries(pg=libs_prev)
return libraries(pg=libs_prev, search=search)
elif lib_select[0] == 'Search':
q = input('Name of library:\n')
return libraries(search=q)
elif lib_select[0] == 'Add remote library':
print('Search a remote library (url\\fid):')
new_library = federate_remote_library(input().strip())

View File

@ -63,10 +63,18 @@ def track_info_output(track):
if k not in ('cover', 'uploads', 'listen_url', 'mbid', 'id', 'is_playable') and v is not None and v != []:
if isinstance(v, dict):
for i in ('title', 'name', 'fid'):
if v.get(i):
if v.get(i):
val_override = v.get(i)
output.append(f'{k}: {val_override}')
else:
output.append(f'{k}: {v}')
output.append('Related Libraries:')
try:
assigned_libs = src.fw_api.assigned_libraries_on_track(track['id'])['results']
for i in assigned_libs:
for prop in ('fid', 'name', 'description', 'creation_date'):
output.append(i.get(prop))
except:
output.append('Failed get related')
output = '\n'.join(output)
os.system(f'less <<EOF\n{output}\nEOF')