Created
May 14, 2014 01:39
-
-
Save efatsi/c7b04f085890e6a7f842 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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