Last active
December 22, 2015 23:09
-
-
Save raspi/6545224 to your computer and use it in GitHub Desktop.
Convert mixCloud set to .cue file
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
#!/bin/env python | |
# -*- coding: utf8 -*- | |
# raspi 2013 | |
# mixCloud set to .cue file | |
# version 0.0.1 | |
import os | |
import sys | |
import json | |
import urllib2 | |
import datetime | |
class mixCloudCue: | |
def __init__(self, url): | |
self.url = url | |
def download(self): | |
response = urllib2.urlopen(self.url) | |
self.data = response.read() | |
def getCue(self): | |
out = "" | |
jsondata = json.loads(self.data) | |
out += "REM " + jsondata["url"]+ "\r\n" | |
out += "REM " + jsondata["created_time"]+ "\r\n" | |
out += "PERFORMER \"" + jsondata["user"]["name"] + "\"\r\n" | |
out += "TITLE \"" + jsondata["name"] + "\"\r\n" | |
out += "FILE \"" + jsondata["name"] + ".mp3\" MP3\r\n" | |
for sect in jsondata["sections"]: | |
starttime = int(sect["start_time"]) | |
secs = starttime % 60 | |
mins = starttime // 60 | |
out += " TRACK " + str(sect["position"]).zfill(2) + " AUDIO\r\n" | |
out += " TITLE \"" + sect["track"]["name"] + "\"\r\n" | |
out += " PERFORMER \"" + sect["track"]["artist"]["name"] + "\"\r\n" | |
out += " INDEX 01 " + str(mins).zfill(2) + ":" + str(secs).zfill(2) + ":00\r\n" | |
return out | |
# example: | |
if __name__ == "__main__": | |
mc = mixCloudCue("http://api.mixcloud.com/DJSlingblade/dj-slingblade-at-the-perfect-times/") | |
mc.download() | |
cuedata = mc.getCue() | |
print cuedata.encode("utf-8") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment