When running ITunes under Mac OSX, you can use AppleScript to do all kinds of neat things. Under Windows you don’t have AppleScript, so Apple created a series of COM interfaces to allow programmatic access to ITunes and you music library (Microsoft has done the same things with Windows Media Player).
Back on topic. I’ve started to do some development with using the ITunes COM interface under Python. Having done my share of COM for C++, I was expecting the worst. But the Python COM bindings are really well done. If the COM object has a property, it appears in Python as a class member variable. If the COM object has a function, just call it like you would any Python function.
But not all is wine and roses… COM uses Unicode strings for all of its communications. Not a problem for Python as it is very happy with Unicode. But a problem when you try to print un-printable characters on the console. The offender in question: the single right quote. Not the apostrophe, but the single right quote. Subte difference. I tried many different ways to try and convert this extended character to something I could print (encoders, etc.) but ended up giving up. The only way I could get it to work was to go through every string I wanted to print and when it found a single right quote and replace it with the apostrophe.
The other problem that I ran into was how COM represents DATE objects. I wanted to compare two DATE objects to see which one was the most recent, but the obvious solution:
if (date1 > date2):
didn’t work. It turns out that you have to coerce each object into a float (the native COM representation for a DATE object) before you can compare them.
if (float(date1) > float(date2)):
Once I figured that out, things were pretty simple.
You can check out my scripts at my Wiki.