From c1d53370b2459e67e82cb4a986f630dd7cd975a5 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 24 Jul 2024 17:36:00 +0300 Subject: [PATCH] add recursive get tracks --- funkwlplay.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/funkwlplay.py b/funkwlplay.py index b4ad315..cfd4411 100644 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -14,6 +14,7 @@ parser = argparse.ArgumentParser( parser.add_argument('-s', '--search') parser.add_argument('-t', '--tag') parser.add_argument('-i', '--instance') +parser.add_argument('-r', '--recursion', type=int, default=0) args = parser.parse_args() if args.instance: instances = [args.instance] @@ -49,10 +50,24 @@ def filter_tracks(tracks): tracks_stor.append(i) -def search_tracks_on_instance(instance, tag='', query=''): +def search_tracks_on_instance(instance, tag='', query='', recursion=args.recursion): tracks = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query, 'local': True, 'playable': True, 'ordering': 'random'}, timeout=10).json() + count = tracks['count'] + print(f'found {count} tracks on {instance}') + if recursion == 1: + recursion_limit = 0 + while tracks['next']: + try: + if recursion_limit >= 5: + break + new_tracks = requests.get(tracks['next']).json() + tracks['results'] += new_tracks['results'] + tracks['next'] = new_tracks['next'] + recursion_limit += 1 + except Exception as E: + print(E) tracks_replacer = [] for track in tracks['results']: track['listen_url'] = f'https://{instance}' + track['listen_url']