Sha256: 68083ddc01960a354cb94831c288840d5dc8943857360dcab58e8341fa535eba
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
require 'pathname' require 'fileutils' module FeedTorrents module Feed class Download include LogFunctions def initialize(title, link, timeout, directory) @title, @link, @timeout, @directory = title, link, timeout, directory end def process if FeedTorrents.configuration.filter_testing? puts "Would have downloaded torrent for '#{@title}' (#{torrent_link})".bold.cyan else info "Downloading torrent for '#{@title}' (#{torrent_link})" http = EM::HttpRequest.new(torrent_link, inactivity_timeout: @timeout).get fh = File.new(file,'wb') http.stream { |chunk| fh.write chunk } http.errback do error "failure retrieving torrent for '#{@title}' (#{torrent_link})" error "error: #{http.error}" end http.callback do info "Downloading torrent for #{@title} completed" fh.close FeedTorrents.store.persist(@link) FeedTorrents::Mail.new.send_email("Downloaded torrent #{@title}") end end end private def torrent_link @torrent_link ||= determine_link end def determine_link if is_magnet? MagnetURI.new(@link).reflektor_link else @link end end def is_magnet? @link =~ /^magnet:\?/ end def file dir = Pathname.new(@directory).expand_path FileUtils.mkdir_p(dir) unless dir.exist? dir.join("#{@title}.torrent") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
feed_torrents-0.2.0 | lib/feed_torrents/feed/download.rb |