UPDATE: It appears the Mixcloud API no longer provides tracklisting data and the documentation provides no further information on how to attain it. Thanks to Andrew Duffy pointing this out.

A few weeks ago, Mixcloud – a fantastic website for hosting DJ mixes – implemented a new feature into their toolkit called Timestamper which allowed the publisher to stamp the time of tracks in mixes (intuitive name, eh?).

This morning, I realised if I could access that data from an API, I could automatically generate the bulk of a CUE file for a mix too.

It turns out you only have to prefix the URL on Mixcloud with api to access the raw data of a specific element.

For example, if you wanted the information of my latest mixshow Funky House Finesse 31, the URL for the JSON data would be:

http://api.mixcloud.com/onephatdj/funky-house-finesse-31

With this in mind, I put together a quick PHP script to compile the timestamp data into a CUE file:

<?php
function file_get_contents_utf8($fn) { 
  $content = file_get_contents($fn); 
  return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8', true)); 
}
function cue_time($secs) { 
  $minutes = floor($secs/60); 
  $seconds = $secs-($minutes*60); 
  return str_pad($minutes, 2, "0", STR_PAD_LEFT).':'. str_pad($seconds, 2, "0", STR_PAD_LEFT). ':00';
}

$data_url = 'http://api.mixcloud.com/onephatdj/funky-house-finesse-31/';
if($_GET['url']!='') {
  $data_url = str_replace('http://www.','http://api.',$_GET['url']);
}

$data = file_get_contents_utf8($data_url);
if($data!='') $json = json_decode($data);

echo '<code><pre>';

foreach($json->sections as $section) {

  $artist = $section->track->artist->name;
  $title = $section->track->name;
  $position = $section->position;
  $seconds = $section->start_time;

  echo '  TRACK ' . $position . ' AUDIO
    TITLE "' . $title . '"
    PERFORMER "' . $artist . '"
    INDEX 01 ' . cue_time($seconds) . '
'; 
}
echo '</pre></code>';
?>

It’s by no means perfect – for example, it could do with some more conditions to check if timestamp data is actually available – but it’s a start and you’re free to use it as you will.