[non-perl] Hacking iPhoto via SQLite

ChrisDolan on 2009-08-14T02:33:23

(a very off-topic SQL exercise follows...)

Apple's iPhoto 2009 has a very cool face recognition feature where it will show you faces and prompt you to enter names. When it finds resemblances, it will suggest names for you to confirm or reject.

When it's wrong, it makes for funny little screenshots you can send to friends: "Haha, cute girl! You look like an older heavier man!"

But once you reject the match, you can't undo or get it back in any other way. Luckily, iPhoto stores ALL of its metadata in a collection of SQLite databases. So, in the particular case that I linked above I was able to undo by telling the database not to ignore the marked mismatches from IMG_0095.JPG:

% osascript -e 'tell application "iPhoto" to quit'
% cd "Pictures/iPhoto Library"
% sqlite3 iPhotoMain.db
sqlite> select photoKey,relativePath from SqFileImage,SqFileInfo where sqFileInfo=SqFileInfo.primaryKey and relativePath like '%IMG_0095.JPG';
110|Data/2003/Roll 15/IMG_0095.jpg
110|Originals/2003/Roll 15/IMG_0095.JPG
3666|Data/2006/Apr 25, 2006/IMG_0095.jpg
3666|Originals/2006/Apr 25, 2006/IMG_0095.JPG
sqlite> .exit
% sqlite3 face.db
sqlite> update similar_faces set ignore=0 where image_key=110;
sqlite> .exit
% open -a iPhoto.app


Even more off-topic SQLite goodness...

bart on 2009-08-16T13:19:30

I found one of the best/easiest ways to browse and edit data in SQLite files is... using the Firefox browser. With the SQLite Manager extension.

It's insane, but Firefox uses SQLite intensely for its own purpose, and what this Firefox extension does is tapping into this potential.

Re:Even more off-topic SQLite goodness...

ChrisDolan on 2009-08-24T04:05:58

Wow! What a great extension! Thanks for the recommendation. This advice alone justifies my blog posting. :-)