Skip to content

Instantly share code, notes, and snippets.

@cintrzyk
Created October 30, 2012 13:58
Show Gist options
  • Save cintrzyk/3980317 to your computer and use it in GitHub Desktop.
Save cintrzyk/3980317 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
def expected_date? (str)
DateTime.strptime(str, '%d, %B, %Y') > Date.today-7
end
def get_page (number)
begin
Nokogiri::HTML(open('http://eztv.it/page_'+number.to_s))
rescue Exception => e
puts "ERROR: #{e}"
nil
end
end
def title_match? (title, expected_title)
if /#{expected_title}/.match(title) or /#{expected_title}/.match(title.downcase)
return true
else
return false
end
end
def puts_movie (title, date, link)
puts "Title:\t\t #{title} \nAdded:\t\t #{date} \nMagnet link:\t #{link}\n\n\n"
end
current_page = 0
next_page = true
if ARGV[0]
expected_title = ARGV[0]
end
while next_page do
page = get_page(current_page)
if page.nil?
next_page = false
break
end
table = page.css('table.forum_header_border')[5]
if !table.nil?
table.css('tr').each do |row|
if row['class'] == "forum_space_border"
@date = row.css('b')[0].content.to_s.strip
if !expected_date?(@date)
next_page = false
break
end
elsif row['class'] == "forum_header_border"
title = row.css('td')[1].content.to_s.strip
link = row.css('td')[2].child.values[0]
if expected_title
if title_match?(title, expected_title)
puts_movie(title, @date, link)
end
else
puts_movie(title, @date, link)
end
end
end
else
puts"ERROR: table not found"
next_page = false
break
end
current_page+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment