Skip to content

Instantly share code, notes, and snippets.

@antonio
Created October 25, 2012 10:19
Show Gist options
  • Save antonio/3951832 to your computer and use it in GitHub Desktop.
Save antonio/3951832 to your computer and use it in GitHub Desktop.
Automatically rename movies according to XBMC standards (adapt to your needs)
#!/usr/bin/env ruby
require 'osdb'
require 'fileutils'
server = OSDb::Server.new(
:host => 'api.opensubtitles.org',
:path => '/xml-rpc',
:timeout => 90,
:useragent => "SubDownloader 2.0.10" # register useragent ? WTF ? too boring.
)
Dir.glob(ARGV[0]).each do |filename|
movie = OSDb::Movie.new filename
movie_data = server.check_movie_hash(movie.hash)['data'][movie.hash]
next if movie_data.empty?
movie_filename = "#{movie_data["MovieName"]} (#{movie_data["MovieYear"]})"
movie_destination_path = "/media/data/Films/#{movie_filename.gsub('/', '-')}"
FileUtils.mkdir movie_destination_path unless File.exists?(movie_destination_path)
FileUtils.mv(filename, "#{movie_destination_path}/#{File.basename(filename)}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment