Compare commits

..

No commits in common. "92a52dd2b8b0847faa851e3c59bb289330d42cd3" and "3f700b6b8fcd0a2fdac653fcc1ebcbfe72b88e59" have entirely different histories.

View File

@ -10,25 +10,23 @@ with open('instances') as instances:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='funkwlplay', prog='funkwhale playlist',
description='Create playlist from query or just random playlist tracks from funkwhale instances') description='Create playlist from query or just random playlist tracks from funkwhale instances')
parser.add_argument('-s', '--search', help='This global search on funkwhale instances, it matches artists, albums, tracks, etc...') parser.add_argument('-s', '--search')
parser.add_argument('-t', '--tag', help='This tag search, use this as genre search') parser.add_argument('-t', '--tag')
parser.add_argument('-i', '--instance', help='Specify instance, by default search on all instances in instances file') parser.add_argument('-i', '--instance')
parser.add_argument('-r', '--recursion', type=int, default=0, help='Use recursion if instance contain more than 50 tracks') parser.add_argument('-r', '--recursion', type=int, default=0)
parser.add_argument('-d', '--depth', type=int, default=5, help='Depth of recursion, default is 5 pages, 250 tracks') parser.add_argument('-d', '--depth', type=int, default=5)
args = parser.parse_args() args = parser.parse_args()
if args.instance: if args.instance:
instances = [args.instance] instances = [args.instance]
def create_playlist_file(track_list): def create_playlist_file(track_list):
filename = 'playlist.m3u8' with open('playlist.m3u8', 'w') as file:
with open(filename, 'w') as file:
file.write('#EXTM3U\n') file.write('#EXTM3U\n')
for i in track_list: for i in track_list:
file.write('\n' + i) file.write('\n' + i)
print(f'Playlist saved as {filename}')
def filter_tracks(tracks): def filter_tracks(tracks):
@ -76,12 +74,9 @@ def filter_tracks(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, tracks = requests.get(f'https://{instance}/api/v1/tracks', params={'tag': tag, 'q': query,
'local': True, 'playable': True, 'local': True, 'playable': True,
'ordering': 'random'}, timeout=10) 'ordering': 'random'}, timeout=10).json()
r.raise_for_status()
tracks = r.json()
count = tracks['count'] count = tracks['count']
print(f'found {count} tracks on {instance}') print(f'found {count} tracks on {instance}')
if recursion == 1: if recursion == 1: