Created
June 2, 2009 16:56
-
-
Save elight/122359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A windows script to lookup movie files in Wikipedia, find the entry for the film, | |
# and extract the film synopsis, download the film's poster, and stuff it in iTunes. | |
# It's a bit naive about over-loaded names at the moment but the simple hack to that is | |
# add "(film)" to the file name. | |
# We hate physical media in our house as my wife and I have a tendency to lose/destroy DVDs. | |
require 'rubygems' | |
require 'rbwikipedia' | |
require 'active_support' | |
$ART_PATH = 'G:\\movies\\artwork\\' | |
$app = WIN32OLE.new 'iTunes.Application' | |
exit if $app.nil? | |
$movies = $app.LibrarySource.Playlists.ItemByName 'Movies' | |
def update_metadata_for(movie_track) | |
track = movie_track | |
begin | |
film = Wikipedia::Film.get_by_title track.Name | |
rescue Exception => e | |
puts "Could not find information on Wikipedia for '#{track.Name}'"^M | |
puts e^M | |
puts e.backtrace | |
return | |
end | |
film.write_poster_to $ART_PATH | |
track.Artwork.Item(1).SetArtworkFromFile($ART_PATH + film.poster_img_hash[:filename]) | |
if film.synopsis | |
film.synopsis.gsub!( /<(\/?)(\w+)>/, "") | |
film.synopsis.gsub!( /\s\s.*/, "") | |
film.synopsis.gsub! "…", "..." | |
track.Description = film.synopsis | |
else | |
puts "No synopsis for #{track.Name}" | |
end | |
end | |
idx = 1 | |
count = $movies.Tracks.Count | |
while idx <= count do | |
movie = $movies.Tracks.Item idx | |
idx += 1 | |
if 20.minutes.ago < Time.parse(movie.DateAdded) | |
puts movie.Name | |
if movie.Description == "" | |
update_metadata_for movie | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment