Created
January 31, 2012 17:44
-
-
Save dmerrick/1711798 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 '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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice