Entries Tagged 'iTunes' ↓
April 17th, 2007 — Ruby, WIN32OLE, iTunes
I wrote this one for my father as he has several audio tapes worth of MP3s to put into iTunes on Windows. It reads down through a directory structure for music files, using the nested directory names as metadata. It expects a nested directory structure as follows:
Root Dir
|- Artist Dirs
|- Album Dirs
|- Music files
Admittedly, this is my first usage of yield in anger. It hurt — but now my brain has been further fortified with vitamin Ruby.
Code follows…
Continue reading →
April 15th, 2007 — Ruby, Ruby on Rails, WIN32OLE, iTunes
Ok, I’ve been a bit compulsive about having artwork for my movies and music in iTunes since we got our AppleTV. Ok, maybe more than a bit.
Even so, this little Rails application should give you some idea of how simple it is. It uses Amazon’s web service (which, it turns out, I misjudged), to look up candidate artwork for each album and displays them to you. You simply click on the desired image (higher resolution is typically better) and it will insert that artwork into iTunes for each track in your album.
I won’t pretend that this is the cleanest implementation but it gets the job done. If any of you watching at home want to play along, you will also need ruby/amazon installed.
FYI: Amazon’s search engine may not resolve all of your album names. You may want to manually search Amazon, in the case of stubborn albums, to determine what Amazon calls the album. However, more often than not, this shouldn’t be a problem if you ripped using iTunes.
Finally, this program could be easily adapted for hunting down artwork for your movie collection as well.
Code follows:
Continue reading →
April 8th, 2007 — Amazon, Ruby, iTunes
I have a problem. Or rather my wife does. She loves the AppleTV but it’s difficult for her to find content for her to watch. Why? Because our video content, other than genre metadata (added by hand — blech!), contains no metadata! Once again, coding to the rescue.
The ingredients:
- Ruby (my language of choice du jour)
- ruby-amazon - Clients itself to Amazon’s web service to perform keyword searches. Major caveat: The search results are nowhere near as accurate as those provided on the Amazon web site. I found this surprising. Why this has not been made into a Winblows XP Media Center Edition 2005 so that the wifey can have her relatively stable Windows Media Center as opposed to our previously slightly less stable, although somewhat more hacker friendly, SageTV.
At the moment, the program fetches descriptions, years (from the DVD release date, sadly, and not the original movie release, and DVD cover artwork from Amazon.com). As Amazon’s web service provides spurious accuracy, the program prompts me to select from one of ten candidate Amazon products to use as a source of metadata for any given movie.
The obnoxious part? I have yet to figure out how to programatically add artwork to a movie (IITTrack.AddArtworkFromFile barfs all over me) even though I am fetching it from Amazon.
require 'amazon/search'
require 'pp'
require 'win32ole'
#require 'net/http'
require 'uri'
$AWS_KEY = 'XXXXXXXXXXXXXXXXXXXX' # bleeped out to protect the innocent
$ART_PATH = 'f:/movies/artwork/'
$app = WIN32OLE.new 'iTunes.Application'
exit if $app.nil?
$movies = $app.LibrarySource.Playlists.ItemByName 'Movies'
def find_dvd(title)
retval = []
req = Amazon::Search::Request.new $AWS_KEY
res = req.keyword_search(title, ‘dvd’)
i=1
res.products.each do |p|
puts “#{i}. #{p.product_name} (#{p.release_date})”
i+=1
end
print “>> ”
input = gets
if input.match /s/
return nil
end
input.match /(\\d+)/
res.products[$1.to_i - 1]
end
def get_artwork(movie_track, movie_meta)
response = Net::HTTP.get_response(URI.parse(movie_meta.image_url_large))
title = movie_track.Name
title.gsub! ‘:’, ‘-’
art_filename = “”
art_filename << $ART_PATH << title << ".jpg"
File.open( art_filename, 'wb') do |f|
f << response.body
f.flush
end
art_filename
end
def update_metadata_for(movie_track)
track = movie_track
meta = find_dvd movie_track.Name
if meta.nil?
return
end
if meta.release_date
meta.release_date.match /, (\\d+)$/
track.Year = $1
end
art_filename = get_artwork track, meta
if track.Artwork
puts track.Artwork
track.AddArtworkFromFile art_filename
end
if meta.product_description
meta.product_description.gsub!( /<(\\/?)(\\w+)>/, “”)
meta.product_description.gsub!( /\\s\\s.*/, “”)
puts meta.product_description
track.Description = meta.product_description
end
end
idx = 1
count = $movies.Tracks.Count
while idx <= count do
movie = $movies.Tracks.Item idx
puts movie.Name
if movie.Description == ""
update_metadata_for movie
end
idx += 1
end
March 25th, 2007 — AppleTV, iTunes
There is so little to say…
In terms of usability. it’s what a PC-to-TV interface should be. My wife, who is a far cry from the most tech literate of people, was ably navigating through most of our digital content in less than a minute.
But then I did say “most”…
The AppleTV supports MPEG-4 and h.264. Left out from this is support for any Microsoft formats and, more importantly, XviD and DivX. However, intrepid geeks are already busily hacking support into the AppleTV for both decoders and larger hard drives. That’s all well and good but talk to me once I can add these features without voiding my unit’s warranty.
As the AppleTV comes equipped with a 40GB drive, those of us with large-ish collections must stream content from iTunes. Is there a penalty? Only slightly. You can stream from up to five different iTunes libraries. Also, streaming start-up time, over an 802.11g network, takes on the order of a few seconds. Finally, fast forwarding and rewinding only works to the extent of the content buffered in memory — somewhere around 30 seconds to 2 minutes depending on the file size, I suppose.
All in all, I’m extremely pleased. It’s usable, makes my content portable, and now I can get to all of it through our 55″ widescreen LCD DLP TV.
Oh, and all of that preparation that I did a couple of weeks ago? So worth it.
March 11th, 2007 — Ruby, RubyOSA, 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
$itunessearchstr = “B5″
app = OSA.app(’iTunes’)
exit unless not app.nil?
movies = app.sources[0].playlists.find { |p| p.name == “Movies” }
tracks = movies.search $itunessearchstr
tracks.each do |track|
puts track.name
track.name.match /B5\s-\s(\d+)\s(.*)/
track.name = $2
track.tracknumber = $1.toi
track.artist = $show
track.album_artist = $show
track.album = $show
track.show = $show
track.episodeid = $1.toi
track.episodenumber = $1.toi
track.year = $year
track.season_number = 1
track.videokind = OSA::ITunes::EVDK::TVSHOW
end