mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2025-02-21 08:10:32 +00:00
Compare commits
No commits in common. "200deac9a693c0986bb7f700234f0922adb590e0" and "92a52dd2b8b0847faa851e3c59bb289330d42cd3" have entirely different histories.
200deac9a6
...
92a52dd2b8
14
README.md
14
README.md
@ -1,20 +1,6 @@
|
|||||||
# funkwlplay
|
# 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_
|
[1]**Warning:** may content _unofficial instances_
|
||||||
**Warning 2:** This software not userfriendly. Maybe developerfriendly.
|
**Warning 2:** This software not userfriendly. Maybe developerfriendly.
|
||||||
|
@ -34,12 +34,13 @@ def create_playlist_file(track_list):
|
|||||||
def filter_tracks(tracks):
|
def filter_tracks(tracks):
|
||||||
def remove_unreach_tracks(track):
|
def remove_unreach_tracks(track):
|
||||||
try:
|
try:
|
||||||
r = requests.head(track['listen_url'], timeout=2, headers={'Content-Encoding': 'gzip'})
|
r = requests.head(track['listen_url'], timeout=1)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return 1
|
return 1
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
|
||||||
|
before = len(tracks)
|
||||||
res = [executor.submit(remove_unreach_tracks, track) for track in tracks]
|
res = [executor.submit(remove_unreach_tracks, track) for track in tracks]
|
||||||
concurrent.futures.wait(res)
|
concurrent.futures.wait(res)
|
||||||
avalaible = []
|
avalaible = []
|
||||||
@ -48,6 +49,8 @@ def filter_tracks(tracks):
|
|||||||
if is_avalaible == 1:
|
if is_avalaible == 1:
|
||||||
avalaible.append(track)
|
avalaible.append(track)
|
||||||
tracks = avalaible
|
tracks = avalaible
|
||||||
|
after = before - len(tracks)
|
||||||
|
print(f'-{after} unreach tracks')
|
||||||
|
|
||||||
Path('filter_tags').touch()
|
Path('filter_tags').touch()
|
||||||
Path('filter_artists').touch()
|
Path('filter_artists').touch()
|
||||||
@ -60,7 +63,7 @@ def filter_tracks(tracks):
|
|||||||
|
|
||||||
with open('filter_raw_urls') as raw_urls_file:
|
with open('filter_raw_urls') as raw_urls_file:
|
||||||
block_raw_urls = raw_urls_file.read().strip().split('\n')
|
block_raw_urls = raw_urls_file.read().strip().split('\n')
|
||||||
filtred_tracks = []
|
|
||||||
for i in tracks:
|
for i in tracks:
|
||||||
if [tag.lower() for tag in i['tags']] in block_tags:
|
if [tag.lower() for tag in i['tags']] in block_tags:
|
||||||
continue
|
continue
|
||||||
@ -68,15 +71,14 @@ def filter_tracks(tracks):
|
|||||||
continue
|
continue
|
||||||
if i['listen_url'].lower() in block_raw_urls:
|
if i['listen_url'].lower() in block_raw_urls:
|
||||||
continue
|
continue
|
||||||
filtred_tracks.append(i)
|
tracks_stor.append(i)
|
||||||
return filtred_tracks
|
|
||||||
|
|
||||||
|
|
||||||
def search_tracks_on_instance(instance, tag='', query='', recursion=args.recursion):
|
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,
|
r = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query,
|
||||||
'local': True, 'playable': True,
|
'local': True, 'playable': True,
|
||||||
'ordering': 'random', 'scope': 'all'},
|
'ordering': 'random'}, timeout=10)
|
||||||
timeout=10, headers={'Content-Encoding': 'gzip'})
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
tracks = r.json()
|
tracks = r.json()
|
||||||
|
|
||||||
@ -109,16 +111,10 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
|
|||||||
for idx, instance in enumerate(instances):
|
for idx, instance in enumerate(instances):
|
||||||
try:
|
try:
|
||||||
tracks = res[idx].result()
|
tracks = res[idx].result()
|
||||||
before_filter = len(tracks['results'])
|
filter_tracks(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:
|
except Exception as E:
|
||||||
print(E)
|
print(E)
|
||||||
for track in tracks_stor:
|
for track in tracks_stor:
|
||||||
artist, album, title, play_url, track_duration, fid = track['artist']['name'], track['album']['title'], track['title'], track['listen_url'], track.get('duration'), track['fid']
|
artist, album, title, play_url = track['artist']['name'], track['album']['title'], track['title'], track['listen_url']
|
||||||
if not track_duration:
|
playlist_files.append(f'#EXTINF:-1,{artist} - {album} - {title}\n{play_url}')
|
||||||
track_duration = -1
|
|
||||||
playlist_files.append(f'#EXTINF:{track_duration},{artist} - {album} - {title} url="{fid}"\n{play_url}')
|
|
||||||
create_playlist_file(playlist_files)
|
create_playlist_file(playlist_files)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user