Last active
August 14, 2024 12:04
-
-
Save ilevantis/88f1f646b59c62f0466d 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
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
<?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><?php echo $feed_array[data][0][user][pictures][large]; ?></image> | |
<?php | |
// item loop stuff goes here | |
foreach ($feed_array[data] as $feed_item) { | |
echo "<item>\n"; | |
echo "<title>"; | |
echo $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>"; | |
echo $feed_item[created_time]; | |
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
Hi, first of all thanks for publishing this. The parsing seems to work well, however I stumbled over my feed reader not accepting it.
https://validator.w3.org/feed/check.cgi tells me:
&
) in the title tag in the feed i am trying, supposedly that's what borks my readerI have addressed these issues in my fork: https://gist.github.com/HarHarLinks/db487ed0c1ad6c198cb282ff6d2ffe3b