class QuartzTorrent::Metainfo
Torrent metainfo structure. This is what’s usually found in .torrent files. This class generally follows the structure of the metadata format.
Attributes
announce[RW]
Announce URL of the tracker
announceList[RW]
comment[RW]
Comment
createdBy[RW]
Created By
creationDate[RW]
Creation date as a ruby Time object
encoding[RW]
The string encoding format used to generate the pieces part of the info dictionary in the .torrent metafile
info[RW]
A Metainfo::Info
object
infoHash[RW]
A 20-byte SHA1 hash of the value of the info key from the metainfo. This is neede when connecting to the tracker or to a peer.
Public Class Methods
createFromFile(path)
click to toggle source
Create a Metainfo
object from the named file.
# File lib/quartz_torrent/metainfo.rb, line 218 def self.createFromFile(path) result = File.open(path,"rb") do |io| result = self.createFromIO(io) end result end
createFromIO(io)
click to toggle source
Create a Metainfo
object from the passed IO.
# File lib/quartz_torrent/metainfo.rb, line 213 def self.createFromIO(io) self.createFromString(io.read) end
createFromString(data)
click to toggle source
Create a Metainfo
object from the passed bencoded string.
# File lib/quartz_torrent/metainfo.rb, line 182 def self.createFromString(data) logger = LogManager.getLogger("metainfo") decoded = BEncode.load(data, {:ignore_trailing_junk => 1}) logger.debug "Decoded torrent metainfo: #{decoded.inspect}" result = Metainfo.new result.createdBy = decoded['created by'] result.comment = decoded['comment'] result.creationDate = decoded['creation date'] if result.creationDate if !result.creationDate.is_a?(Integer) if result.creationDate =~ /^\d+$/ result.creationDate = result.creationDate.to_i else logger.warn "Torrent metainfo contained invalid date: '#{result.creationDate.class}'" result.creationDate = nil end end result.creationDate = Time.at(result.creationDate) if result.creationDate end result.encoding = decoded['encoding'] result.announce = decoded['announce'].strip result.announceList = decoded['announce-list'] result.info = Info.createFromBdecode(decoded['info']) result.infoHash = Digest::SHA1.digest( decoded['info'].bencode ) result end
new()
click to toggle source
# File lib/quartz_torrent/metainfo.rb, line 151 def initialize @info = nil @announce = nil @announceList = nil @creationDate = nil @comment = nil @createdBy = nil @encoding = nil end
valueOrException(v, msg)
click to toggle source
If ‘v’ is null, throw an exception. Otherwise return ‘v’.
# File lib/quartz_torrent/metainfo.rb, line 12 def self.valueOrException(v, msg) if ! v LogManager.getLogger("metainfo").error msg raise "Invalid torrent metainfo" end v end