Created
October 18, 2022 22:46
-
-
Save squigglezworth/82b95d8b3bf64f723019d203d3e225bf to your computer and use it in GitHub Desktop.
Python script for generating playlists for di.fm & the other AudioAddict sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, os, requests, random | |
parser = argparse.ArgumentParser(description='Create PLS files for di.fm & friends streaming sites') | |
parser.add_argument('key', help='Listening key from di.fm or any other site in the network') | |
parser.add_argument('--directory', help='Generate playlists in this directory') | |
group1 = parser.add_argument_group('Sites', "Specify which sites to generate playlists for, or none to generate for all sites") | |
group1.add_argument('--di', help='di.fm', action='store_true') | |
group1.add_argument('--classical', help='ClassicalRadio.com', action='store_true') | |
group1.add_argument('--jazz', help='JAZZRADIO.com', action='store_true') | |
group1.add_argument('--radio', help='RadioTunes.com', action='store_true') | |
group1.add_argument('--rock', help='ROCKRADIO.com', action='store_true') | |
group1.add_argument('--zen', help='ZenRadio.com', action='store_true') | |
args = parser.parse_args() | |
if args.directory: os.chdir(args.directory) | |
channels, networks = list(), list() | |
nets = requests.get('https://api.audioaddict.com/v1/networks').json() | |
if args.di: networks += list(filter(lambda n: n['name'] == 'DI.FM', nets)) | |
if args.classical: networks += list(filter(lambda n: n['name'] == 'ClassicalRadio.com', nets)) | |
if args.jazz: networks += list(filter(lambda n: n['name'] == 'JAZZRADIO.com', nets)) | |
if args.zen: networks += list(filter(lambda n: n['name'] == 'ZenRadio.com', nets)) | |
if args.radio: networks += list(filter(lambda n: n['name'] == 'RadioTunes', nets)) | |
if args.rock: networks += list(filter(lambda n: n['name'] == 'ROCKRADIO.COM', nets)) | |
if not networks: networks = nets | |
for n in networks: | |
url = n['listen_url'].replace('listen', f'prem{random.randint(1,4)}') | |
channels += [(f"{n['name']} - {x['name']}", f"{url}:80/{x['key']}") for x in requests.get(f"{n['listen_url']}/channels").json()] | |
for c in channels: | |
with open(f"{c[0]}.pls",'w') as f: | |
f.write(f'''[playlist] | |
File1={c[1]}?{args.key} | |
Title1={c[0]} | |
NumberOfEntries=1 | |
''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment