class QuartzTorrent::TorrentDataDelegate
Attributes
Torrent Metainfo.info struct. This is nil if the torrent has no metadata and we haven’t downloaded it yet (i.e. a magnet link).
How much of the metainfo info we have downloaded in bytes. This is only set when the state is :downloading_metainfo
Length of metainfo info in bytes. This is only set when the state is :downloading_metainfo
Recommended display name for this torrent.
State of the torrent. This may be one of :downloading_metainfo, :error, :checking_pieces, :running, :downloading_metainfo, or :deleted. The :deleted state indicates that the torrent that this TorrentDataDelegate
refers to is no longer being managed by the peer client.
Public Class Methods
Create a new TorrentDataDelegate
. This is meant to only be called internally.
# File lib/quartz_flow/mock_client.rb, line 125 def initialize @info = nil @infoHash = nil @recommendedName = nil @downloadRate = nil @uploadRate = nil @downloadRateDataOnly = nil @uploadRateDataOnly = nil @completedBytes = nil @peers = nil @state = nil @completePieceBitfield = nil @metainfoLength = nil @metainfoCompletedLength = nil @paused = nil end
Public Instance Methods
Convert to a hash. Also flattens some of the data into new fields.
# File lib/quartz_flow/wrappers.rb, line 65 def to_h result = {} ## Extra fields added by this method: # Length of the torrent result[:dataLength] = @info ? @info.dataLength : 0 # Percent complete pct = withCurrentAndTotalBytes{ |cur, total| (cur.to_f / total.to_f * 100.0).round 1 } result[:percentComplete] = pct # Time left secondsLeft = withCurrentAndTotalBytes do |cur, total| if @downloadRateDataOnly && @downloadRateDataOnly > 0 (total.to_f - cur.to_f) / @downloadRateDataOnly else 0 end end # Cap estimated time at 9999 hours secondsLeft = 35996400 if secondsLeft > 35996400 result[:timeLeft] = Formatter.formatTime(secondsLeft) ## Regular fields result[:info] = @info ? @info.to_h : nil result[:infoHash] = @infoHash result[:recommendedName] = @recommendedName result[:downloadRate] = @downloadRate result[:uploadRate] = @uploadRate result[:downloadRateDataOnly] = @downloadRateDataOnly result[:uploadRateDataOnly] = @uploadRateDataOnly result[:completedBytes] = @completedBytes result[:peers] = @peers.collect{ |p| p.to_h } result[:state] = @state #result[:completePieceBitfield] = @completePieceBitfield result[:metainfoLength] = @metainfoLength result[:metainfoCompletedLength] = @metainfoCompletedLength result[:paused] = @paused result[:queued] = @queued result[:uploadRateLimit] = @uploadRateLimit result[:downloadRateLimit] = @downloadRateLimit result[:ratio] = @ratio result[:uploadDuration] = @uploadDuration result[:bytesUploaded] = @bytesUploaded result[:bytesDownloaded] = @bytesDownloaded result[:alarms] = @alarms.collect{ |a| a.to_h } result end
Private Instance Methods
# File lib/quartz_flow/wrappers.rb, line 125 def calcEstimatedTime(torrent) # Time left = amount_left / download_rate # = total_size * (1-progress) / download_rate if torrentHandle.has_metadata && torrentHandle.status.download_rate.to_f > 0 secondsLeft = torrentHandle.info.total_size.to_f * (1 - torrentHandle.status.progress.to_f) / torrentHandle.status.download_rate.to_f Formatter.formatTime(secondsLeft) else "unknown" end end
# File lib/quartz_flow/wrappers.rb, line 114 def withCurrentAndTotalBytes if @info yield @completedBytes, @info.dataLength elsif @state == :downloading_metainfo && @metainfoCompletedLength && @metainfoLength yield @metainfoCompletedLength, @metainfoLength else 0 end end