Python


Using python, it’s easy to get data from IMDb into your iTunes database.

You’ll need a few tools to get this working. appscript, py-IMDb and CocoaDialog. Install each of these, and for the latter, note where you store it. I’m not going to go through the code, as it is fairly well commented. If you can’t get it to work, leave a comment and I’ll see if I can help.

IMDB2iTunes.py

Note that you will need to save the file above, and rename it so it has a .py extension.

View Comments (10)   RSS Feed for Comments on this Post

I’ve consolidated all of my media onto my new Mac Mini, but didn’t really think some things through when I first did it. For instance, I put all of my video data in before transferring my music across. I’ve still kept a copy of my music on the laptop, for what it’s worth, but because I just copied files, then I lost all of my rating data.

I looked at a couple of solutions for transferring the ratings, the most promising was a semi-manual method of creating smart playlists, one for each rating.

That was too old-tech for me, so I came up with a solution that uses Remote Apple Events. Now, to make the code easier, I’m using python and appscript, so make sure you have both of those installed.

#! /usr/bin/python

import appscript

# Set up the two iTunes libraries.
local = appscript.app('itunes')
# You'll need to replace jens.local with your remote machine's name
remote = appscript.app(url='eppc://jens.local/itunes')

local.lib = local.playlists()[0].tracks()
remote.lib = remote.playlists()[0].tracks()

# Create a dictionary with all local track names/artists/albums

library = {}

for each in local.lib:
    key = each.name()+":"+each.artist()+":"+each.album()
    library[key] = each

# Iterate over every remote track.
# If it is in the local library, take the local rating and
#    apply that to the remote track.

for each in remote.lib:
    key = each.name()+":"+each.artist()+":"+each.album()
    print key,
    if library.has_key(key):
        each.rating.set(library[key].rating())
        print "rated."
    else:
        print "doesn't exist in local library"

That’s it. I’ve used this to transfer all of my ratings from local to remote iTunes. Granted, there is no check to see if I’ve got all of the local tracks on the remote machine - but that is mainly because I don’t have my Podcast library on the remote machine, and I hope (know?) I have all of the music, and that’s the stuff I care about.

Here’s a screenshot from my remote library.

View Comments (0)   RSS Feed for Comments on this Post

I’m going back to Uni next year, to complete a post-grad degree in Computer Science. This is a course that people without a background in Computing can enrol in, so I’ll be able to get a bit of credit towards some units, but not too much, since when I did part of a Computer Systems Engineering degree, Java wasn’t the language taught. Now, at all three Universities in Adelaide, it almost seems to be the only language being taught.

Just for my own personal gain, I’m also teaching myself Objective-C. This is the language used by Apple and third-party coders for most of the OS X application software. All of their APIs are available under Objective C, and Java, whilst still somewhat supported, doesn’t appear to be as high on Apple’s agenda as it is on the local Universities.

I’ve borrowed books in the past on Cocoa/ObjC, but never really made much progress. This time, having a laptop means I can actually do my learning on that, wherever I happen to be. In this coffee shop, for instance.

I’ve also found some handouts and example program “tests” at Stanford University, and have started to work through those. The first program, a simple conversion application for temperatures, was fairly simple, and I wrote that. I even managed to complete the extra credit sections, or at least two of them.

Psuedo-evidence (in that you can’t actually see this working):

(Note, the temperatures change to red when above a certain value, and to blue when below a certain value. Within the ‘normal’ range, they are black).

This wasn’t a programmatically onerous task, more about making sure you can connect up various components and have them affect one another.

Instead of doing the next task, I’m pretty confident I’ll be able to write the application I gave to my Year 12 students, a 9-letter word puzzle solver. It will be interesting to see if I can effectively re-implement the python version I’ve already written:

The only reason I really want to learn Obj-C is that it enables me to use a GUI design tool, rather than having to create the interface using coordinates. And packaging up python applications isn’t exactly fun, either.

And, after the 9-letter puzzle solver, I might reimplement a sudoku solver I wrote. Not sure if I have the python source code for that one. And I never wrote a GUI for it, either.

View Comments (0)   RSS Feed for Comments on this Post

Or Python3.0, as it is also known, has been released, or rather, the first alpha of it has.

It builds okay on OS X, although I’ll need to download some stuff to get it to build bsddb and readline, among other things. Since I use these two modules, I’ll get them at least.

There are lots of changes in python3.0, including integer division returning floats, and input() being what it should be (instead of having to use raw_input()). print has become a function, and a whole lot of other things have changed. In fact, programs are likely to not run under 3.0 without a rewrite.

I’ll keep 2.5 around for a while longer, methinks. Hell, I’ve still got 2.3 on here, just incase.

View Comments (0)   RSS Feed for Comments on this Post

Okay, I think I’ve found an appscript bug.

If you attempt to connect to a networked machine, such as doing:
>>> from appscript import *
>>> it = app(url=”eppc://user@machine.local/iTunes”)
>>> it.activate()
Which works fine if you have a password, fails if there is no password.  And the error reported is:

RuntimeError: Can’t get terminology for application (aem.Application(url=’eppc://user@machine.local/iTunes’)): CommandError -128: userCanceledErr

Just because I haven’t put in a password, doesn’t mean I have cancelled the operation.

I’m still working on a fix to get it to work.

View Comment (1)   RSS Feed for Comments on this Post

I came across a strange issue today. I have written a script that adds acronym tags to a post created in ecto, and another that adds the currently playing iTunes track, as nice links to iTMS.

However, the problem that arose is that the script wouldn’t run. I had the shebang line, and everything, but no joy.

Then I noticed that I have upgraded my python installation to 2.5, but for some reason the /usr/bin/python was still pointed at 2.3 - but my interpreter run from the bash shell, or from Komodo was 2.5. This itself wouldn’t be too much of an issue, except I was using appscript, and I had only installed appscript into the 2.5 Python installation library.

So, it was failing (way too silently, for my liking), and I couldn’t tell why.

All fixed now, though.

Fly Me AwaySupernatureGoldfrapp

View Comments (0)   RSS Feed for Comments on this Post

This is the best way I can find to test if an application is running under appscript:

try:
    app('System Events').processes['AppName']()
except:
    print 'Application AppName is not running'

I think it’s kinda neat. I’d like to know of a better method, but I looked pretty hard!

Burn Down The Mission (Live)Elton JohnLive In Australia

View Comments (3)   RSS Feed for Comments on this Post

Maybe I’m just being crazy, but I’m not really finding wxPython particularly pythonic. For instance, I’m trying to make a fairly simple application that has a SplitterWindow, and I seem to have to do a whole lot of sub-classing to actually get it to work. Feels more like Java than Python. Which I’m really not keen on doing.

NoticeGomezChillout Sessions 9

View Comments (4)   RSS Feed for Comments on this Post

bash:

mdls filename | grep FinderComment

AppleScript:

tell application "Finder"
    comment of file
end tell

python:

#!/usr/bin/pythonw
from appscript import *
path = '/Users/NAME/your/path/here'
comment = app('Finder').items[path.replace('/', ':')].comment.get()

View Comment (1)   RSS Feed for Comments on this Post

I’ve been working on a few little macros for Komodo. I’m planning to build a more cohesive set as I use the editor more.
(more…)

View Comment (1)   RSS Feed for Comments on this Post

« Previous PageNext Page »