Skip to content

Instantly share code, notes, and snippets.

@efatsi
Created May 14, 2014 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efatsi/c7b04f085890e6a7f842 to your computer and use it in GitHub Desktop.
Save efatsi/c7b04f085890e6a7f842 to your computer and use it in GitHub Desktop.
require "selenium-webdriver"
require 'uri'
require 'redis'
uri = URI.parse(ENV["LETITSNOW_REDIS_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
def download_torrent(torrent)
puts "starting driver"
driver = Selenium::WebDriver.for :chrome
base_url = "http://kickass.to/usearch/"
target = base_url + URI.encode(torrent)
driver.navigate.to target
puts "downloading #{torrent} .torrent file"
driver.execute_script('$($(".imagnet")[0]).siblings().last()[0].click()')
sleep(5) #give torrent time to download
puts "shutting down driver"
driver.quit
end
while true do
puts "pinging Redis..."
if torrent = $redis.lpop("torrents")
download_torrent(torrent)
end
sleep(10)
# check redis for new torrent torrent names, download them
end
# Test this out maybe?
# with puts and connect it for a day
#
# $redis.subscribe('torrents') do |on|
# on.message do |channel, torrent|
# download_torrent(torrent)
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment