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:

  1. Remove duplicate videos, based on the song title
  2. 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
  3. 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.

Once this filtering takes place, the resulting array is checked to see if it still contains any valid videos. If there are no videos available, an empty response is returned to the page. This return value causes the Compendium javascript to invoke another AJAX call to retrieve fallback content from Youtube. Youtube nearly always returns results from its catalogue of x million videos; but these still need a little bit of filtering and nudging to produce accurate results.

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.

Some examples:

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 DiamondInside a Boy. In hi-def, courtesy of Vimeo (coming soon to the Compendium… perhaps):

Inside A Boy from Rafa Toro on Vimeo.

If you find any bugs with the video feeds, please let me know.

Comments for "Compendium Videos now Triple Filtered for your Pleasure"

Commenting is now closed for this article

About

beardscratchers.com is a music-focused web experiment and creative-arts journal from London, England.

Subscribe/Syndicate

Categories

Previous Entries…

Journal content and design are © of Nick Skelton

built with web standards and a baseline.