Skip to content

Instantly share code, notes, and snippets.

@GeordieP
Last active August 29, 2015 14:09
Show Gist options
  • Save GeordieP/47982f2294783dabee88 to your computer and use it in GitHub Desktop.
Save GeordieP/47982f2294783dabee88 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import json
import urllib.request
class Main:
def __init__(self):
num = 0;
# Output File Formatting Strings
pre = '#Name:Radio\n#Cursor:1\n#Summary:2 / 00:00:00:00 / 0 B\n#Flags:2047\n#Group:Radio|1\n'
outputString = pre
# Open main link, get a JSON object of retrieved data
data = urllib.request.urlopen('http://listen.di.fm/public1').read()
jsonData = json.loads(data.decode("utf8"))
# Loop through each channel
for obj in jsonData:
num+=1 # Keep track of number, used for track number display in AIMP
# Parse an object out of each channel's JSON data
data = urllib.request.urlopen(obj["playlist"]).read().decode("utf8").strip().splitlines()
# Add the URL and stream Title from the channel's object to the final output string
# MusicBee Version:
# outputString += '<outline text="'+ data[3].split('Title1=')[1].split('-')[1].strip().replace("&", "and") +' - DI" description="" category="'+ data[3].split('Title1=')[1].split('-')[1].strip().replace("&", "and") +'/AAC/64k/" type="link" url="'+ data[2].split('File1=')[1] +'" />\n'
# AIMP Version:
outputString += '#Track:'+ str(num) +'|'+ data[2].split('File1=')[1] +'||||Di - '+ data[3].split('Title1=')[1].split('-')[1].strip().replace("&", "and") +'|0|0|||0|0|0|\n'
outputFile = open("DigitallyImported.aimppl", "w+")
outputFile.write(outputString)
outputFile.close()
main = Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment