April 13, 2008 at 12:26 PM by Dr. Drang
On Friday, I started downloading video lectures from MIT’s Open Courseware project, expecting to put them on my iPhone at the next sync. Today I learned that the videos were tagged as Movies instead of TV Shows, which made the iPhone syncing process a little goofy. So I wrote a quick little AppleScript to fix the tagging which I thought others might find useful. Unless you plan to download this exact course, you’ll have to make some changes to the AppleScript, but I think those changes will be obvious.
The course I chose to start with is Physics I, Classical Mechanics1. The MIT Open Courseware has a section in the iTunes Store, and that’s where I went to download the lectures. They came in their own little playlist and automatically generated an enclosing “MIT” folder in my iTunes sidebar.
Unfortunately, as I mentioned, the lecture videos were classified as Movies rather than TV Shows, so they had to be individually selected to be sync’d with my iPhone. I thought that a series of videos like this is more naturally thought of as a TV Show with many individual episodes. Recategorizing them as a TV Show would:
- Allow me to sync them with the iPhone with a single click.
- Automatically remove the lectures I had already watched (assuming my TV Show syncing is set to “all unwatched”).
I could, of course, recategorize all 36 videos by going to the Video tab of Info window and making the appropriate changes.
But I’d have to do it 37 times for this lecture series and then about as many times again for every other lecture series I download. Better to make up a quick script that will work for this course and can be easily edited to work for other courses.
1: set ep to 0 2: tell application "iTunes" 3: repeat with lecture in the selection 4: set video kind of lecture to TV show 5: set show of lecture to "MIT Physics I: Classical Mechanics" 6: set season number of lecture to 1999 7: 8: -- strip the "Lecture" prefix from the name 9: set epname to name of lecture 10: set colon to offset of ":" in epname 11: if colon > 0 then 12: set lastChar to length of epname 13: set epname to (characters (colon + 2) thru lastChar of epname) as text 14: end if 15: 16: set episode ID of lecture to epname 17: set episode number of lecture to ep 18: set ep to ep + 1 19: end repeat 20: end tell
I call the script “Convert Lectures,” and it’s saved in
~/Library/Scripts/Applications/iTunes, which is where FastScripts can find it and make it readily available to me when iTunes is the active application. (Since iTunes has its own AppleScript menu, I could have saved it in
~/Library/iTunes/Scripts, which is where iTunes looks for scripts. I’m just more in the FastScripts habit now.)
The script expects all the lecture videos to be downloaded, in order, and selected. It then goes through all the selected videos and makes the appropriate changes. Line 4 is the most important--it turns the video from a Movie to a TV Show. Line 5 gives the notional TV show a name, and Line 6 sets the season number--which for a real TV show would be 1 or 2 or whatever--to the year in which the lectured were recorded.
Lines 8-16 give each lecture a “episode” name. Each video in the lecture series comes with a name, and except for the introduction, each name is of the form “Lecture nn: Topics.” Lines 9-14 strip away the “Lecture nn: ” prefix--if it’s there--and Line 16 puts the result in the “episode ID” property of the track.
The “ep” variable keeps a running count of the lectures and puts it into the “episode number” property. The count starts at zero because first video, the course introduction, is only a few minutes long and isn’t considered a real lecture. Apparently, iTunes doesn’t consider zero to be a legitimate episode number, because after running the script, the episode number of the course introduction was still blank.
If you want to use this script as a template for your own script:
- You’ll need to change Line 5.
- You’ll need to change Line 6 unless your series was also recorded in 1999.
- You’ll need to change Lines 8-16 unless your track names follow the same format as mine.
- You’ll need to change the starting value of “ep” on Line 1 unless your series also starts with a short introduction.
Although the title of this post mentions the iPhone, you could, of course, transfer the lectures to any video-enabled iPod. It just so happens that the only experience I have with avideo-enabled iPod is with my iPhone. The 36 videos from this course take up about 3.6 GB, which may or may not a big deal depending on the capacity of your iPod and how much other stuff you carry on it. Right now, I have the entire course on my iPhone, but if I were short on space, I’d use the little checkboxes next to the tracks and the “Sync only checked songs and videos” option in the iPhone summary view to control how much of the course would get uploaded.
This is a topic with which I am quite familiar; I’m expecting to learn more about the usefulness of this form of education than I am about the topic itself. If I enjoy the form and see it as a nice way of learning, I’ll move on to topics I know less about. ↩︎