In one of my previous posts I wrote about learning up-and-coming programming languages and listed a few I was particularly interested in. One of these languages was Python, and in the last few weeks I spent a couple of hours getting familiar with the language and the built-in class library. Being an avid Eclipse user I installed PyDev, which was a great help with its content assist and syntax checking.
However, I prefer learning by doing, so after a while I started thinking about a real-life problem to solve with Python. Being a fan of the XBMC cross-platform media center application — which can be extended with Python scripts — and the SoundCloud music sharing website — which exposes a nicely designed RESTful API — I decided to develop a music plugin for XBMC to access music shared on SoundCloud.
In the first post of this multi-part series I will provide an overview of the documentation and tools available at the time of writing. Stay tuned for the next parts, where I will go into more detail and post some actual code. The outline of things to come:
- Part 1: Documentation and tools
- Part 2: The anatomy of an XBMC plugin
- Part 3: Accessing public resources on SoundCloud
- Part 4: Putting it all together
SoundCloud API
A quick glance at the SoundCloud API page on GitHub revealed an existing Python API wrapper, but unfortunately it wasn’t compatible with XBMC’s built-in Python 2.4 runtime. This meant that I had to roll my own, which proved to be fairly easy once I hunted down the required third-party dependencies, like simplejson, httplib2 and oauth2. I haven’t had the time yet to dig into SoundCloud’s OAuth-based authentication, so for the first version I decided to provide access to publicly available resources only, and implement authentication, favorite tracks, followed/follower users, etc. in a future iteration.
The SoundCloud API documentation is very detailed and well-structured. SoundCloud even provides a web console with plenty of examples for experimenting with the API to see how it responds to various requests. This is just awesome, every RESTful web service should provide one of these; it is a lot more tangible than API documentation, and easier than firing up curl or a full-fledged web browser and copying example URLs from the documentation. After hacking together a quick and dirty Python command-line client, I was ready to integrate it with XBMC.
XBMC Plugin Development
The XBMC plugin development HOW-TO is not very well organized and is missing some details. I had to do a fair amount of googling and bookmarking to get a complete picture of how plugins hook into the application and what the best practices are. The most helpful resources I could find were the following:
- The single most important resource is the Python module documentation, which is unfortunately not very easy to find. Here you can find all the classes and methods exposed to Python scripts and plugins by XBMC.
- Since I was using PyDev for development I was very happy to find this excellent tutorial on how to debug XBMC plugins with PyDev.
- When preparing for this blog post I stumbled upon a PyDev script, which provides content assist for XBMC modules. This is necessary, because the XBMC modules are implemented in C++ and are exposed directly via the Python runtime in XBMC. This means, that PyDev has no .py files to work with when trying to determine the contents of a given module. I will try to get it working and update this post accordingly.
While I was digging into the idiosyncrasies of XBMC plugin development, the XBMC community started to prepare for the upcoming Dharma release, in which they made some changes to the add-on infrastructure, and extended the add-on developer documentation on their Wiki. I decided to target the upcoming release with my plugin, which turned out to require creating an addon.xml file and some minor tweaking of the code itself, but I will get to that in Part 2.
This concludes the first part of the series. In Part 2 I will go into more details on how to develop an XBMC plugin, provide some advice to prevent common pitfalls and show some simple code snippets.
1 Comments.