Adding Spotify links to BBC Radio playlists, via RDFa, using Greasemonkey and rdfQuery

·

This is a Greasemonkey script that

  1. Uses rdfQuery to read the RDFa from radio tracklist pages on bbc.co.uk/programmes:
    $('#segments')
      .rdf()
        .prefix('mo', 'http://purl.org/ontology/mo/')
        .prefix('foaf', 'http://xmlns.com/foaf/0.1/')
        .prefix('dc', 'http://purl.org/dc/terms/')
        .where('?track a mo:Track')
        .where('?track foaf:maker ?artist')
        .where('?track dc:title ?trackTitle')
        .where('?artist a mo:MusicArtist')
        .where('?artist foaf:name ?artistName') // not quite working yet (rdfQuery bug)
        .each(function(i, bindings, triples) {
           doSomething();
        });
  2. Looks up that track using the Spotify metadata API:
    http://ws.spotify.com/search/1/track.xml?q=artist:"' + encodeURIComponent(artistName) + '"+track:"' + encodeURIComponent(trackTitle) + '"'

    (when MusicBrainz ID searches are working better in Spotify, could use those instead)

  3. Replaces the artist name and track title of found tracks with Spotify links, and adds a Spotify link for the album on which the track was found.

Try it on one of these pages: