Skip to content

Instantly share code, notes, and snippets.

@HarHarLinks
Forked from ilevantis/Mixcloud RSSifier
Last active December 26, 2023 10:32
Show Gist options
  • Save HarHarLinks/db487ed0c1ad6c198cb282ff6d2ffe3b to your computer and use it in GitHub Desktop.
Save HarHarLinks/db487ed0c1ad6c198cb282ff6d2ffe3b to your computer and use it in GitHub Desktop.
Turn mixcloud streams into an RSS feed e.g. for mixcloud.com/<mixcloudstream>/playlists/<streamplaylist-if-there-is-one>/ go to mysite.com/mixcloud-rssifier/?fname=<mixcloudstream>&lname=<streamplaylist-if-there-is-one> to get an RSS feed of the stream or the playlist from the stream
<?php
header('Content-Type: application/rss+xml; charset=UTF-8');
// suck in the query string variables
$feed_name = htmlspecialchars($_GET['fname']);
$list_name = htmlspecialchars($_GET['lname']);
// compose the api urls + other stuff depending on presence of playlist
if(isset($_GET['lname'])) {
$json_url = 'http://api.mixcloud.com/'.$feed_name.'/playlists/'.$list_name.'/cloudcasts/';
$mcloud_url = 'https://www.mixcloud.com/'.$feed_name.'/playlists/'.$list_name.'/';
$feed_title = $feed_name.': '.$list_name;
} else {
$json_url = 'http://api.mixcloud.com/'.$feed_name.'/cloudcasts/';
$mcloud_url = 'https://www.mixcloud.com/'.$feed_name.'/';
$feed_title = $feed_name;
}
// suck in json from mixcloud and turn into an array
$json = file_get_contents($json_url);
$feed_array = json_decode($json, true);
?>
<?xml version="1.0" encoding="utf-8"?>
<rss version='2.0'>
<channel>
<title><?php echo $feed_array[name]; ?></title>
<link><?php echo $mcloud_url; ?></link>
<description><?php echo 'RSS feed for '.$feed_title.' on mixcloud.com'; ?></description>
<image>
<title><?php echo $feed_array[name]; ?></title>
<url><?php echo $feed_array[data][0][user][pictures][large]; ?></url>
<link><?php echo $mcloud_url; ?></link>
</image>
<?php
// item loop stuff goes here
foreach ($feed_array[data] as $feed_item) {
echo "<item>\n";
echo "<title>";
echo htmlentities($feed_item[name]);
echo "</title>\n";
echo "<link>";
echo $feed_item[url];
echo "</link>\n";
echo "<description>";
echo '<![CDATA[<img src="'.$feed_item[pictures][extra_large].'">]]>';
echo "</description>\n";
echo "<pubDate>";
$ptime = new DateTime($feed_item[created_time]);
echo $ptime->format('r');
echo "</pubDate>\n";
echo "</item>\n";
}
?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment