From a9b3fddffe78b95b3ddd325f244ac68e6f13642c Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 17:52:15 +0300 Subject: [PATCH 1/8] improved filter count tracks --- funkwlplay.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/funkwlplay.py b/funkwlplay.py index 5332974..539961c 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -40,7 +40,6 @@ def filter_tracks(tracks): 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 = [] @@ -49,8 +48,6 @@ def filter_tracks(tracks): 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() @@ -63,7 +60,7 @@ def filter_tracks(tracks): with open('filter_raw_urls') as raw_urls_file: block_raw_urls = raw_urls_file.read().strip().split('\n') - + filtred_tracks = [] for i in tracks: if [tag.lower() for tag in i['tags']] in block_tags: continue @@ -71,7 +68,8 @@ def filter_tracks(tracks): continue if i['listen_url'].lower() in block_raw_urls: continue - tracks_stor.append(i) + filtred_tracks.append(i) + return filtred_tracks @@ -111,7 +109,11 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor: for idx, instance in enumerate(instances): try: tracks = res[idx].result() - filter_tracks(tracks['results']) + before_filter = len(tracks['results']) + filtred_tracks = filter_tracks(tracks['results']) + after_filter = before_filter - len(filtred_tracks) + print(f'{after_filter} tracks filtred on {instance}') + tracks_stor = filtred_tracks except Exception as E: print(E) for track in tracks_stor: From 61265cceb8720ec0a21f2d62085cd493a38de394 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 18:06:25 +0300 Subject: [PATCH 2/8] readme update --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3733357..c410179 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,20 @@ # funkwlplay -basic functional for create playlist tracks. Be simple as possible. No implement player and tui. Just bare cli solution. +basic functional for create playlist tracks. Be simple as possible. No implement player and tui. Just bare cli solution. +Random powered, good luck :3 + +Example usage: +``` +./funkwlplay.py # just get random tracks from instances + +./funkwlplay.py -s 'dance with the dead' # search on instances + +./funkwlplay.py -t house # search tag house on instances + +./funkwlplay.py -r 1 -d 10 -i funk.deko.cloud # get 10 pages random tracks from instance + +$YOUR_FAVORITE_PLAYER playlist.m3u8 # just plays tracks. Remember at this moment playlist will be rewriten after every call ./funkwlplay.py +``` [1]**Warning:** may content _unofficial instances_ **Warning 2:** This software not userfriendly. Maybe developerfriendly. From 89a8133de790874ffe34fe13b7d61d0269635f6d Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 19:00:21 +0300 Subject: [PATCH 3/8] get duration track if exists --- funkwlplay.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/funkwlplay.py b/funkwlplay.py index 539961c..35af3ab 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -72,7 +72,6 @@ def filter_tracks(tracks): return filtred_tracks - def search_tracks_on_instance(instance, tag='', query='', recursion=args.recursion): r = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query, 'local': True, 'playable': True, @@ -117,6 +116,8 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor: except Exception as E: print(E) for track in tracks_stor: - artist, album, title, play_url = track['artist']['name'], track['album']['title'], track['title'], track['listen_url'] - playlist_files.append(f'#EXTINF:-1,{artist} - {album} - {title}\n{play_url}') + artist, album, title, play_url, track_duration = track['artist']['name'], track['album']['title'], track['title'], track['listen_url'], track.get('duration') + if not track_duration: + track_duration = -1 + playlist_files.append(f'#EXTINF:{track_duration},{artist} - {album} - {title}\n{play_url}') create_playlist_file(playlist_files) From 0e6b7cccbf79bb03561b0335182377b3bf305349 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 19:32:34 +0300 Subject: [PATCH 4/8] add link to track in playlist --- funkwlplay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/funkwlplay.py b/funkwlplay.py index 35af3ab..9c014d3 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -116,8 +116,8 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor: except Exception as E: print(E) for track in tracks_stor: - artist, album, title, play_url, track_duration = track['artist']['name'], track['album']['title'], track['title'], track['listen_url'], track.get('duration') + artist, album, title, play_url, track_duration, fid = track['artist']['name'], track['album']['title'], track['title'], track['listen_url'], track.get('duration'), track['fid'] if not track_duration: track_duration = -1 - playlist_files.append(f'#EXTINF:{track_duration},{artist} - {album} - {title}\n{play_url}') + playlist_files.append(f'#EXTINF:{track_duration},{artist} - {album} - {title} url="{fid}"\n{play_url}') create_playlist_file(playlist_files) From 395800f2800f20713622daf73ba783f6a527c5cf Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 20:32:22 +0300 Subject: [PATCH 5/8] increase timeout for fetch track --- funkwlplay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funkwlplay.py b/funkwlplay.py index 9c014d3..ba65325 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -34,7 +34,7 @@ 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 = requests.head(track['listen_url'], timeout=2) r.raise_for_status() return 1 except: From 309e36db4358ae18bf3624ef523f03e47153919d Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 23:02:01 +0300 Subject: [PATCH 6/8] oopse, massive add instead replace --- funkwlplay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funkwlplay.py b/funkwlplay.py index ba65325..4dd44d9 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -112,7 +112,7 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor: filtred_tracks = filter_tracks(tracks['results']) after_filter = before_filter - len(filtred_tracks) print(f'{after_filter} tracks filtred on {instance}') - tracks_stor = filtred_tracks + tracks_stor += filtred_tracks except Exception as E: print(E) for track in tracks_stor: From bc2b7efdd97466e38a265ab80dff5bec4ad74d19 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 23:12:38 +0300 Subject: [PATCH 7/8] compressed request for speed up --- funkwlplay.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/funkwlplay.py b/funkwlplay.py index 4dd44d9..1570165 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -34,7 +34,7 @@ def create_playlist_file(track_list): def filter_tracks(tracks): def remove_unreach_tracks(track): try: - r = requests.head(track['listen_url'], timeout=2) + r = requests.head(track['listen_url'], timeout=2, headers={'Content-Encoding': 'gzip'}) r.raise_for_status() return 1 except: @@ -74,8 +74,9 @@ def filter_tracks(tracks): def search_tracks_on_instance(instance, tag='', query='', recursion=args.recursion): r = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query, - 'local': True, 'playable': True, - 'ordering': 'random'}, timeout=10) + 'local': True, 'playable': True, + 'ordering': 'random', 'scope': 'all'}, + timeout=10, headers={'Content-Encoding': 'gzip'}) r.raise_for_status() tracks = r.json() From 200deac9a693c0986bb7f700234f0922adb590e0 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 25 Jul 2024 23:23:32 +0300 Subject: [PATCH 8/8] tab --- funkwlplay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/funkwlplay.py b/funkwlplay.py index 1570165..3f37866 100755 --- a/funkwlplay.py +++ b/funkwlplay.py @@ -75,8 +75,8 @@ def filter_tracks(tracks): def search_tracks_on_instance(instance, tag='', query='', recursion=args.recursion): r = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query, 'local': True, 'playable': True, - 'ordering': 'random', 'scope': 'all'}, - timeout=10, headers={'Content-Encoding': 'gzip'}) + 'ordering': 'random', 'scope': 'all'}, + timeout=10, headers={'Content-Encoding': 'gzip'}) r.raise_for_status() tracks = r.json()