From eeb177c33512464cc42f636a77c058c2b4629302 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 13:38:32 +0300 Subject: [PATCH] added unreach tracks filter --- funkwlplay.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/funkwlplay.py b/funkwlplay.py index 4ec6b41..00e9fbb 100644 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -29,6 +29,26 @@ def create_playlist_file(track_list): def filter_tracks(tracks): + def remove_unreach_tracks(track): + try: + r = requests.head(track['listen_url'], timeout=1) + r.raise_for_status() + return 1 + except: + return 0 + with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor: + before = len(tracks) + res = [executor.submit(remove_unreach_tracks, track) for track in tracks] + concurrent.futures.wait(res) + avalaible = [] + for idx, track in enumerate(tracks): + is_avalaible = res[idx].result() + if is_avalaible == 1: + avalaible.append(track) + tracks = avalaible + after = before - len(tracks) + print(f'-{after} unreach tracks') + Path('filter_tags').touch() Path('filter_artists').touch() Path('filter_raw_urls').touch() @@ -51,6 +71,7 @@ def filter_tracks(tracks): tracks_stor.append(i) + 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,