From f4b029630d30d423ba38b552d880c1c5bd48bed0 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 3 Aug 2023 00:18:48 +0300 Subject: [PATCH] added related libraries track info --- src/fw_api.py | 14 ++++++++++++++ src/utils.py | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/fw_api.py b/src/fw_api.py index 12c315f..1789fb0 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -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 = { diff --git a/src/utils.py b/src/utils.py index eacc30c..f66fe0a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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 <