jasonkarns
3/10/2012 - 6:13 PM

Rename your movie folders.

Rename your movie folders.

require 'rubygems'
require 'cgi'
require 'json'

movies = Dir.open(".").select do |f|
  File.directory?(f) && !f.match(/\..*/)
end

movies.each do |movie|
  print "."
  info = JSON.parse(`curl -s http://www.imdbapi.com/?t=#{CGI.escape(movie)}`)
  best_name = "#{info['Title']} (#{info['Year']})"
  unless movie.gsub(/(\S)-/,'\1:') == best_name
    puts "\n#{movie} should be renamed to: #{best_name}"
    #File.rename(movie, best_name)
  end
end