## OC ReMix Albums Atom Feed

I've recently discovered the wonderful OverClocked ReMix thanks to the help of a friend (thank you for the suggestion ☺), and they have a bunch of cool albums you should totally listen to (my favourite so far is Esther's Dreams :D)!

To help keep up-to-date with the albums they release, I went looking for an RSS/Atom feed that I could subscribe to. Unfortunately, I didn't end up finding one - so I wrote a simple scraper to do the job for me, and I thought I'd share it on here. You can find it live over here.

The script itself uses my earlier atom.gen.php script, since I had it lying around. Here it is in full:

<?php

$settings = new stdClass();$settings->version = "0.1-alpha";
$settings->ocremix_url = "https://ocremix.org";$settings->album_url = "https://ocremix.org/albums/";
$settings->user_agent = "OCReMixAlbumsAtomFeedGenerator/$settings->version (https://starbeamrainbowlabs.com/labs/ocremix_atom/albums_atom.php; <webmaster@starbeamrainbowlabs.com> ) PHP/" . phpversion() . "+DOMDocument";
$settings->ignore_parse_errors = true;$settings->atom_gen_location = "./atom.gen.php";

// --------------------------------------------

require($settings->atom_gen_location); ini_set("user_agent",$settings->user_agent);
$ocremix_albums_html = file_get_contents($settings->album_url);

$ocremix_dom = new DOMDocument(); libxml_use_internal_errors($settings->ignore_parse_errors);
$ocremix_dom->loadHTML($ocremix_albums_html);

$ocremix_xpath = new DOMXPath($ocremix_dom);

$ocremix_albums =$ocremix_xpath->query(".//table[contains(concat(' ', normalize-space(./@class), ' '), ' data ')]//tr[contains(concat(' ', normalize-space(./@class), ' '), ' area-link ')]");

$ocremix_feed = new atomfeed();$ocremix_feed->title = "Albums | OC ReMix";
$ocremix_feed->id_uri =$settings->album_url;
$ocremix_feed->sq_icon_uri = "http://ocremix.org/favicon.ico";$ocremix_feed->addauthor("OverClocked ReMix", false, "https://ocremix.org/");
$ocremix_feed->addcategories([ "music", "remixes", "albums" ]); foreach ($ocremix_albums as $album) {$album_date = $album->childNodes[6]->textContent;$album_name = $album->childNodes[2]->childNodes[1]->textContent;$album_url = $album->childNodes[2]->childNodes[1]->attributes["href"]->textContent;$album_img_url = $album->childNodes[0]->childNodes[0]->attributes["src"]->textContent; // Make the urls absolute$album_url = $settings->ocremix_url .$album_url;
$album_img_url =$settings->ocremix_url .  $album_img_url;$content = "<p><a href='$album_url'><img src='$album_img_url' alt='$album_name' />$album_name</a> - released $album_date";$ocremix_feed->addentry(
$album_url,$album_name,
strtotime($album_date), "OverClocked ReMix",$content,
false,
[],
strtotime($album_date) ); } header("content-type: application/atom+xml"); echo($ocremix_feed->render());

Basically, I define a bunch of settings at the top for convenience (since I might end up changing them later). Then, I pull down the OcReMix albums page, extract the table of recent albums with a (not-so) tidy XPath query - since PHP's DOMDocument class doesn't seem to support anything else at a glance (yep, I used css-to-path to convert a CSS selector, since my XPath is a bit rusty and I was in a hurry :P).

Finally, I pull it apart to get a list of albums and their release dates - all of which goes straight into atom.gen.php and then straight out to the browser.