Archive for the Category Programming

 
 

Indrio Development Begins: iTunes, COM & Python

Indrio is the name or a road not too far form here. Indrio is also the code name for a little project I’m working on to help me learn Python. It involves talking to iTunes, over COM. This is easier than it sounds. The iTunes SDK documentation is well written, well organized and easy to understand. It’s an easy API to work with, thats the good news.

The bad news is that some of the cool stuff that iTunes is doing in the UI is not available through the COM interface. Of particular interest to me was the Party Shuffle playlist. You can add tracks to it but only at the end i.e. No “Play Next in Party Shuffle” via COM. You can’t determine how many previously played tracks are showing (unless your actually playing that playlist and work it out from the currently playing track). You can’t set the playlist that feeds into the party shuffle or any of the other parameters. These things are not blockers for what I wanted to do but they would have made things much nicer for users.

Then there is fun with ID’s. The docs say that all objects in iTunes support four script friendly functions to return the Source, Playlist, Track & Database ID’s respectively. If you have a problem accessing these functions its because the Source, Playlist and Track functions are declared to start with common letters; sourceID(), playlistID(), trackID(). The database ID function is capitalized as per the docs: TrackDatabaseID(). Also of interest, Python can handle the multiple return values of GetITObjectIDs() by turning them into an array. Score one for Python! Score another one for the Python COM browser which helped me track down the capitalization bug.

iTunes.GetITObjectByID() doesn’t work if all you have is the Database ID, which makes knowing that basically useless. To make GetITObjectID() work you need to know all 4 parameters. That isn’t exactly congruent with the docs. Supplying 0 to any of the parameters throws some sort of error.

The final twist is with Python. It supplies base types when a function returns a derived type over COM. So you have to cast the return type to the type you expected. This had me stumped for a while until I saw this Simon Brunning’s code. win32com.client.CastTo() is the magic bullet that fixes this. I wish there was some good docs for the Python COM interface.

Stay tunes for the next installment where I reveal even less about what Indrio might be or do or why you should care…

iTunes Folder Sync 0.2 Release

This version is a bit faster than the old one. It does the import in one batch so you get a nice progress bar in iTunes. Finally you can now edit the script to tell it where you store your music. This is the answer for people with complex music storage hierarchies that were not seeing new things being imported.

Download iTunes Folder Sync 0.2

Here is a link to how this script got started and how to use it. As always you need the Windows Scripting Host (aka wscript) installed and the .js extension set to be executed using \windows\system32\wscript.exe

These enhancements were made possible by Howard Darwin who did the beta testing and contributed ideas. He has a wish list for future enhancements that I would love to accommodate but I’m not sure that the iTunes SDK makes this practical with the WScript engine.

Quality Caymanian Website

Well at least the Caymanian Compass got it right. They were last to the web but their page is valid XHTML and valid CSS, bravo! The site is based on tables not CSS but thats a small nit pick compared to other sites like Cayman Net News and gov.ky where the errors number in the hundreds.

They had an off island firm (cyber-dynamics.com) code the site for them. It’s a proper news site with articles on their own pages etc. They still don’t pepper articles with the classifieds but perhaps that will come in the future.

Javascript for Popups = Bad

To my dismay I discovered that the Cayman Islands Government home page uses a very broken version of a java-script popup function, probably stolen from some 1998, 4 inch thick, ‘The Web For Beginners’ guide to HTML. It makes incorrect use of the DOM, this is either an error or was never tested by the developers. In any case the usability of the site is horrid and the code is sloppy at best. I sent them a bug report to the purported webmasters e-mail address two weeks ago. It detailed the problem and its solutions, as yet I have received no response.

I wont bother to regale you with a description of how livid it makes me as a technology professional to see my country misrepresented in this way. I will defer to Mr. Aaron Boodman, who already keeps a hit list for people who deserve execution for their negligence. His article details the problem and its very simple solution.

I have also found a way to make www.gov.ky your own personal bitch by rewriting their broken java-script on the fly using the fantastic greasemonkey plugin for Firefox (You do have Firefox, don’t you?).