Ruby + RubyOSA = No more hand-jamming metadata in iTunes!

Having a Mac and a lot of DVDs, I happen to be quite fond of Handbrake. However, how is one supposed to organize all of this video within iTunes for inevitable use on an AppleTV, I ask you?

Videos imported into iTunes 7 automatically register as “Movies”. So how do you handle TVShows? By changing/adding metadata to each of the populated fields on these screens:



That’s a whole lot of metadata! Sure, you can update all of the metadata by hand but, really, who has the time?

So I wrote some code.

With RubyOSA, the world of AppleScript is now available to Ruby developers – without the trama of learning AppleScript!

If you can understand the code below, you should be able to figure out how to tweak it ever so slightly as necessary to have it manipulate your media of choice.

require 'rubygems'
require 'rbosa'

$show = "Babylon 5"
$year = 1994
$itunes_search_str = "B5"

app ='iTunes')
exit unless not app.nil?
movies = app.sources[0].playlists.find { |p| == "Movies" }

tracks = $itunes_search_str
tracks.each do |track|

  puts /B5\\s-\\s(\\d+)\\s(.*)/ = $2
  track.track_number = $1.to_i
  track.artist = $show
  track.album_artist = $show
  track.album = $show = $show
  track.episode_id = $1.to_i
  track.episode_number = $1.to_i
  track.year = $year
  track.season_number = 1

  track.video_kind = OSA::ITunes::EVDK::TV_SHOW

Posted by evan on Sunday, March 11, 2007

blog comments powered by Disqus