WP Soundcloud Auto Playmaker

::Edit Accepted into WordPress Repository::

I’ve been playing around with the Soundcloud API for a while now. Bizarrely, Soundcloud don’t publish RSS feeds for tracks so you can’t podcast them without a lot of faffing about. So I whipped together a Python web service (article to follow) to grab the JSON feeds from Soundcloud and parse them into RSS. This all worked nicely and I was able to turn any tracks I’ve uploaded into a Podcast. I could podcast groups and favourites also. Not just my own but anyone and everone elses also.

I thought it would be cool to plug this into wordpress so set about learning the plugin API and wrote a cool plugin that would grab any feed you specify and embed flash players for them into your site. This worked really well, but I wanted to create some paging for the widgets using Ajax, so that if a group or user had loads of tracks, you could specify how many you wanted returned and the widget would let you page through the results. This presented a bit of a problem as my python service returns XML rather than JSON so browser will detect the cross site request (wordpress site queries python service site which queries soundcloud and back again) and block it. I thought about creating a JSON feed from my site and I probably will but I haven’t got around to it yet. So instead I wrote a wrapper around the jQuery ajax calls which proxied through the Yahoo APIs which returned the XML wrapped in JSON. This worked well but was sufficiently head melting that I knew it was pointless releasing. In addition, it would require you to either install my Python service somewhere (which would require Apache with mod_python and mod_wsgi) or for you to use my server.

So, to that end, I rewrote the Python bits concerned with generating the player feed so now it’s all completely self contained.

All in all a very interesting exercise even if it did require writing more Php than anyone should ever have to.

I’m not going to write about the source or the implementation details as the code is all there to download. I think it’s implemented quite well as PHP programs go. I did my best to be neat and best practice’y but as the WordPress API was new to me and PHP, well, not sure that it has best practices..

I put a lot of effort in to making sure that the html produced will validate as XHTML 1.0/Strict which took a bit of work with the Flash embedding code but it should all be dandy now.

It’s not perfect but I’m not sure if I’ll do any more with it as it works for me. I’ll upload it to the WordPress plugin site and if I get any feedback or requests I’ll have a look at them.
As far as Soundcloud goes, a lot of interesting stuff to be done there but I’m going to stick with the Python side of things for now as the PHP side of things was beginning to destroy my soul. That being said, WordPress itself is a fine example of what amazing things you can do with PHP. Huge kudos to the Sordpress developers, they have a really nice framework there and I got to grips with the API in no time.

To get this working and figure out the plugin API, I had to browse the source code of a lot of other plugins and some of it was really frightening. No consistency, indenting was all over the place and the code was just unreadable. I think that’s the problem with PHP, it just makes it too easy to write awful code and there are too many people writing plugins that don’t know how to code properly.

Anyhoo… Enjoy

Plugin Details

This plugin will query the Soundcloud API for you directly and return a formatted player list for embedding in and page. You can query for users or groups and tracks or favourites. So, you can say, give me players for all of this groups tracks or, give me players for all of this users favourites etc. You can also specify a limit on the number of results and the widget will allow you page backwards and forwards through them.

Plugin will produce valid XHTML/Strict also (if that’s the kind of thing that gets you off..)

View of the admin screen

Widget Setup Screen

A view of the player as it looks in a sidebar widget

Widget DIsplayed in Sidebar

Have fun and let me know any features you would like added..

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This site is using OpenAvatar based on

Comment moderation is enabled. Your comment may take some time to appear.

The Periodic Something Else is Digg proof thanks to caching by WP Super Cache