Skip to content

Instantly share code, notes, and snippets.

@itayadler
Created October 17, 2013 21:08
Show Gist options
  • Save itayadler/7032229 to your computer and use it in GitHub Desktop.
Save itayadler/7032229 to your computer and use it in GitHub Desktop.
A simple Ruby script I wrote to download the IMDB Plain Text DB. Simply save it as a file with executable permissions and it will hopefully work.
#!/usr/bin/env ruby --disable-gems
# vim: set ft=ruby:
require 'net/ftp'
require 'benchmark'
#Consts
IMDB_FTP_HOST = 'ftp.fu-berlin.de'
IMDB_FTP_DATA_PATH = '/pub/misc/movies/database'
README = <<-README
This is a simple Ruby script that downloads the entire IMDB Plain Text DB into a specified folder.
If no arguments are passed to it, the DB will be downloaded to the current directory.
The first argument passed to it can be the full path where the DB will be saved into.
Written by Itay Adler (@itayad)
README
if ARGV[0].nil?
target_path = File.expand_path(__FILE__)
elsif ARGV[0] == '-h'
puts README
exit(1)
else
target_path = ARGV[0]
end
puts 'Connecting to IMDB FTP'
imdb_ftp = Net::FTP.new(IMDB_FTP_HOST)
imdb_ftp.login
imdb_ftp.chdir(IMDB_FTP_DATA_PATH)
files_to_download = imdb_ftp.nlst('*.gz')
puts "Downloading IMDB DB files to #{target_path}"
time = Benchmark.realtime do
files_to_download.each do |file|
puts "Downloading #{file}"
imdb_ftp.getbinaryfile(file, "#{target_path}/#{file}")
puts "Finished downloading #{file}"
end
end
puts "Finished downloading IMDB DB in #{time/60} minutes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment