mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-18 13:13:01 +00:00
added unreach tracks filter
This commit is contained in:
parent
d47fe32516
commit
eeb177c335
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user