Since introducing MTV networks into the Compendium, I happened across Yahoo’s excellent Music API, which offers up the Yahoo music video catalogue as part of the service. Good news, these are now available through the Compendium. This brings the total number of officially released music videos to over 60,000.
Well, almost… In combining the two content networks, I’ve had to be quite careful about what appears where, to whom and how. As I mentioned in a previous post about MTV Networks, video content comes from the most restricted datafeeds used on the Compendium, particularly regarding geographical location. Dependant on your location, and licensing, some videos may not be available.
When videos are loaded in an artist profile on the Compendium, an AJAX request invokes two simultaneous server-side requests to go off and retrieve videos from Y!Music and MTVN—this is cached. Once these are successfully retrieved, they are combined and then passed off for pre-filtering.
Filtering the video feeds involves three steps:
- Remove duplicate videos, based on the song title
- Remove videos that are not specifically by the artist or under the artist’s name, but may have been returned as part of the webservice search query
- Remove videos that are restricted either by geographical location or are not available for external embedding.
Geographical filtering is done with the help of the Net_GeoIP Pear package. This is OO version of the regular Pear GeoIP package that queries the flat Maxmind GeoIP databases. This returns geolocation information based on IP. It is still in beta, but appears completely stable. It can be installed from the command-line using:
$ pear config-set preferred_state beta $ pear install Net_GeoIP $ pear config-set preferred_state stable
Conveniently it uses a Singleton pattern to stop the flat database files being initialised multiple times within a script. However it is still by far the slowest data lookup in the Compendium. I wrapped my own lookup methods into another Singleton, and used
$_SESSION values to store country and city lookups. This prevent multiple database lookups happening, unless they change, since geolocation is used not only in Video feeds but also Events data lookups. Further improvements can be made by pushing the flat database files into memory or into a DBMS like MySQL.
With this geolocation data at hand, MTVN videos are filtered based on attributes in the returned dataset. Y!Music works slightly differently, in that each geographical location has it’s own base API address, returning videos only available in that region. So Y!Music is filtered at the source, rather than at the point of retrieval.
All these lookups are cached, and the AJAX lookups are bypassed when valid caches exist, meaning that videos are injected directly into the page when it renders.
If you’re in the US, UK, much or Europe and a few other places, you should see official music videos appearing for selected artists. If not, you’ll get Youtube results appearing.
The last, however, is US only. So to end this post on a high-note, here’s the excellent video by Raf Toro of My Brightest Diamond – Inside a Boy. In hi-def, courtesy of Vimeo (coming soon to the Compendium… perhaps):
If you find any bugs with the video feeds, please let me know.