Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created January 31, 2012 17:44
Show Gist options
  • Select an option

  • Save dmerrick/1711798 to your computer and use it in GitHub Desktop.

Select an option

Save dmerrick/1711798 to your computer and use it in GitHub Desktop.
require 'cgi'
require 'open-uri'
class TorrentManager
def initialize
# configuration options
@list_file = "torrents.txt"
@watch_dir = File.expand_path "~/watch"
unless File.exists? @list_file
puts "#{@list_file} file is missing."
exit 2
end
unless File.directory? @watch_dir
puts "#{@watch_dir} directory is missing."
exit 2
end
end
def get_remote_torrent_list
@remote_torrents = File.open(@list_file).read.split
end
def download_torrent_files
@remote_torrents.each do |torrent|
puts "Downloading #{torrent}"
download torrent
end
end
def run
get_remote_torrent_list
download_torrent_files
end
private
def download(url)
local_file = File.join(@watch_dir, File.basename(url))
# this was way easier than doing it in ruby
`/opt/local/bin/wget -q -O #{local_file} #{url}`
end
end
if $0 == __FILE__
tm = TorrentManager.new
tm.run
end
@DemitryT
Copy link
Copy Markdown

DemitryT commented Feb 1, 2012

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment