Sha256: c2980e7f01783d242f7f110166ae7dcab7df727da2986b7214656592972c2767
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 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(@title, @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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
feed_torrents-0.2.2 | lib/feed_torrents/feed/download.rb |
feed_torrents-0.2.1 | lib/feed_torrents/feed/download.rb |