$ ./imdb.rb "pee wee's big adventure" /tmp
$ cat /tmp/movie.nfo
http://www.imdb.com/title/tt0089791/
Last active
March 21, 2017 23:33
-
-
Save res0nat0r/203719 to your computer and use it in GitHub Desktop.
Grab the first imdb result from google and save it to an .nfo file
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mechanize' | |
require 'open-uri' | |
class Nfo | |
attr_reader :title, :dir , :doc | |
def initialize(title, dir) | |
@title = title | |
@dir = dir | |
end | |
def search | |
agent = Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' } | |
doc = agent.get("http://www.google.com/search?q=#{title}" + " imdb") | |
url = doc.link_with(:href => /imdb.com/).href + "\n" | |
file = File.open("#{dir}/movie.nfo", "w") unless File.exists?("#{dir}/movie.nfo") | |
if(file) | |
file.write(url) | |
file.close | |
else | |
puts "#{dir}/movie.nfo exists. Exiting..." | |
end | |
end | |
end | |
if $0 == __FILE__ | |
item = Nfo.new(ARGV[0], ARGV[1]) | |
item.search | |
end |
This file contains 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
#!/usr/bin/env ruby | |
require 'mechanize' | |
*args = ARGV | |
agent = Mechanize.new | |
page = agent.get('http://google.com/') | |
google_form = page.form('f') | |
google_form.q = "imdb #{args}" | |
page = agent.submit(google_form, google_form.buttons.first) | |
puts page.links_with(:text => /IMDb$/, :href => /imdb.com/).first.click.uri |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment