Class TorrentInfo
-
Constructor Summary
ConstructorsConstructorDescriptionTorrentInfo(byte[] data) Load the torrent data and decode it inside the constructor, for convenience.TorrentInfo(File torrent) Load the torrent file and decode it inside the constructor, for convenience.TorrentInfo(MappedByteBuffer buffer) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHttpSeed(String url) Adds one url to the list of http seeds.voidaddHttpSeed(String url, String externAuth) Adds one url to the list of http seeds.voidAdds one url to the list of http seeds.voidThis is used when creating torrent.voidaddTracker(String url) Adds a tracker to the announce-list.voidaddTracker(String url, int tier) Adds a tracker to the announce-list.voidaddUrlSeed(String url) Adds one url to the list of url seeds.voidaddUrlSeed(String url, String externAuth) Adds one url to the list of url seeds.voidAdds one url to the list of url seeds.static TorrentInfobdecode(byte[] data) byte[]bencode()voidClear the internal list of trackers.This function is related to BEP38_ (mutable torrents).comment()Returns the comment associated with the torrent.longReturns the creation date of he torrent as time_t (`posix time`_).creator()Returns the creator string in the torrent.files()TheFileStorageobject contains the information on how to map the pieces to files.hashForPiece(int index) takes a piece-index and returns the 20-bytes sha1-hash for that piece and ``info_hash()`` returns the 20-bytes sha1-hash for the info-section of the torrent file.This function looks up keys from the info-dictionary of the loaded torrent file.returns the SHA1 info-hash of the torrent.booleanisI2p()Returns true if this is an i2p torrent.booleanisLoaded()booleanReturns true if this torrent is private.booleanisValid()Returns true if this torrent_info object has a torrent loaded.Generates a magnet URI from the specified torrent.mapBlock(int piece, long offset, int size) This function will map a piece index, a byte offset within that piece and a size (in bytes) into the corresponding files with offsets where that data for that piece is supposed to be stored.mapFile(int file, long offset, int size) This function will map a range in a specific file into a range in the torrent.name()returns the name of the torrent.nodes()If this torrent contains any DHT nodes, they are returned in their original form (host name and port number).intnumFiles()If you need index-access to files you can use this method to access files using indices.intThe total number of pieces.Returns the original (unmodified) file storage for this torrent.intThe number of byte for each piece.intpieceSize(int index) voidRemaps the file storage to a new file layout.voidrenameFile(int index, String newFilename) Renames a the file with the specified index to the new name.voidsetWebSeeds(List<WebSeedEntry> seeds) Replaces all web seeds with the ones specified in theseedslist.This function is related to BEP38_ (mutable torrents).swig()toEntry()longThe total number of bytes the torrent-file represents (all the files in it).trackers()Will return a sorted list with the trackers of this torrent info.webSeeds()Returns all url seeds and http seeds in the torrent.
-
Constructor Details
-
TorrentInfo
-
TorrentInfo
Load the torrent file and decode it inside the constructor, for convenience.This might not be the most suitable for applications that want to be able to report detailed errors on what might go wrong.
- Parameters:
torrent- the torrent file
-
TorrentInfo
public TorrentInfo(byte[] data) Load the torrent data and decode it inside the constructor, for convenience.This might not be the most suitable for applications that want to be able to report detailed errors on what might go wrong.
- Parameters:
data- the torrent data
-
TorrentInfo
-
-
Method Details
-
swig
- Returns:
- the native object
-
files
TheFileStorageobject contains the information on how to map the pieces to files.It is separated from the
TorrentInfoobject because when creating torrents a storage object needs to be created without having a torrent file. When renaming files in a storage, the storage needs to make its own copy of theFileStoragein order to make its mapping differ from the one in the torrent file.- Returns:
- the files storage
-
origFiles
Returns the original (unmodified) file storage for this torrent. This is used by the web server connection, which needs to request files with the original names. Filename may be changed usingrenameFile(int, String).- Returns:
- the original file storage
-
renameFile
Renames a the file with the specified index to the new name. The new filename is reflected by theFileStoragereturned byfiles()but not by the one returned byorigFiles().If you want to rename the base name of the torrent (for a multifile torrent), you can copy the
FileStorage(seefiles()andorigFiles()), change the name, and then useremapFiles(FileStorage).The
newFilenamecan both be a relative path, in which case the file name is relative to thesavePathof the torrent. If thenewFilenameis an absolute path then the file is detached from thesavePathof the torrent. In this case the file is not moved whenTorrentHandle.moveStorage(String, MoveFlags)is invoked.- Parameters:
index- the file index to renamenewFilename- the new file name
-
remapFiles
Remaps the file storage to a new file layout. This can be used to, for instance, download all data in a torrent to a single file, or to a number of fixed size sector aligned files, regardless of the number and sizes of the files in the torrent.The new specified
FileStoragemust have the exact same size as the current one.- Parameters:
f- the file storage
-
addTracker
Adds a tracker to the announce-list.- Parameters:
url- the tracker url
-
addTracker
Adds a tracker to the announce-list. Thetierdetermines the order in which the trackers are to be tried.- Parameters:
url- the tracker urltier- the tracker tier
-
trackers
Will return a sorted list with the trackers of this torrent info.Each announce entry contains a string, which is the tracker url, and a tier index. The tier index is the high-level priority. No matter which trackers that works or not, the ones with lower tier will always be tried before the one with higher tier number.
- Returns:
- the list of trackers
-
similarTorrents
This function is related to BEP38_ (mutable torrents). The vector returned from this correspond to the "similar" in the .torrent file. The info-hashes from within the info-dict and from outside of it are included.BEP38: http://www.bittorrent.org/beps/bep_0038.html
- Returns:
-
collections
This function is related to BEP38_ (mutable torrents). The vector returned from this correspond to the "collections" keys in the .torrent file. The collections from within the info-dict and from outside of it are included.BEP38: http://www.bittorrent.org/beps/bep_0038.html
- Returns:
-
clearTrackers
public void clearTrackers()Clear the internal list of trackers. -
addUrlSeed
Adds one url to the list of url seeds. Currently, the only transport protocol supported for the url is http.- Parameters:
url-- See Also:
-
addUrlSeed
Adds one url to the list of url seeds. Currently, the only transport protocol supported for the url is http.The
externAuthargument can be used for other authorization schemes than basic HTTP authorization. If set, it will override any username and password found in the URL itself. The string will be sent as the HTTP authorization header's value (without specifying "Basic").This is the same as calling
addUrlSeed(String, String, List)with an empty list.- Parameters:
url-externAuth-
-
addUrlSeed
Adds one url to the list of url seeds. Currently, the only transport protocol supported for the url is http.The
externAuthargument can be used for other authorization schemes than basic HTTP authorization. If set, it will override any username and password found in the URL itself. The string will be sent as the HTTP authorization header's value (without specifying "Basic").The
extraHeadersargument can be used to insert custom HTTP headers in the requests to a specific web seed.- Parameters:
url-externAuth-extraHeaders-
-
addHttpSeed
Adds one url to the list of http seeds. Currently, the only transport protocol supported for the url is http.- Parameters:
url-
-
addHttpSeed
Adds one url to the list of http seeds. Currently, the only transport protocol supported for the url is http.The
externAuthargument can be used for other authorization schemes than basic HTTP authorization. If set, it will override any username and password found in the URL itself. The string will be sent as the HTTP authorization header's value (without specifying "Basic").- Parameters:
url-externAuth-
-
addHttpSeed
Adds one url to the list of http seeds. Currently, the only transport protocol supported for the url is http.The
externAuthargument can be used for other authorization schemes than basic HTTP authorization. If set, it will override any username and password found in the URL itself. The string will be sent as the HTTP authorization header's value (without specifying "Basic").The
extraHeadersargument defaults to an empty list, but can be used to insert custom HTTP headers in the requests to a specific web seed.- Parameters:
url-externAuth-extraHeaders-
-
webSeeds
Returns all url seeds and http seeds in the torrent. Each entry is aWebSeedEntryand may refer to either a url seed or http seed.- Returns:
- the list of web seeds
-
setWebSeeds
Replaces all web seeds with the ones specified in theseedslist.- Parameters:
seeds- the list of web seeds
-
totalSize
public long totalSize()The total number of bytes the torrent-file represents (all the files in it).- Returns:
-
pieceLength
public int pieceLength()The number of byte for each piece.The difference between
pieceSize(int)andpieceLength()is thatpieceSize(int)takes the piece index as argument and gives you the exact size of that piece. It will always be the same aspieceLength()except in the case of the last piece, which may be smaller.- Returns:
-
numPieces
public int numPieces()The total number of pieces.- Returns:
-
infoHashV1
-
infoHashV2
-
infoHashType
-
numFiles
public int numFiles()If you need index-access to files you can use this method to access files using indices.- Returns:
-
mapBlock
This function will map a piece index, a byte offset within that piece and a size (in bytes) into the corresponding files with offsets where that data for that piece is supposed to be stored.- Parameters:
piece-offset-size-- Returns:
- See Also:
-
mapFile
This function will map a range in a specific file into a range in the torrent. Theoffsetparameter is the offset in the file, given in bytes, where 0 is the start of the file.The input range is assumed to be valid within the torrent.
offset + sizeis not allowed to be greater than the file size.indexmust refer to a valid file, i.e. it cannot be>= numFiles().- Parameters:
file-offset-size-- Returns:
- See Also:
-
isValid
public boolean isValid()Returns true if this torrent_info object has a torrent loaded.This is primarily used to determine if a magnet link has had its metadata resolved yet or not.
- Returns:
-
isPrivate
public boolean isPrivate()Returns true if this torrent is private. i.e., it should not be distributed on the trackerless network (the kademlia DHT).- Returns:
-
isI2p
public boolean isI2p()Returns true if this is an i2p torrent. This is determined by whether or not it has a tracker whose URL domain name ends with ".i2p". i2p torrents disable the DHT and local peer discovery as well as talking to peers over anything other than the i2p network.- Returns:
-
pieceSize
public int pieceSize(int index) -
hashForPiece
takes a piece-index and returns the 20-bytes sha1-hash for that piece and ``info_hash()`` returns the 20-bytes sha1-hash for the info-section of the torrent file.- Parameters:
index-- Returns:
-
isLoaded
public boolean isLoaded() -
name
returns the name of the torrent.the name is an UTF-8 encoded strings.
- Returns:
-
creationDate
public long creationDate()Returns the creation date of he torrent as time_t (`posix time`_). If there's no time stamp in the torrent file, a value of zero is returned.- Returns:
- the time
-
creator
Returns the creator string in the torrent. If there is no creator string it will return an empty string.- Returns:
- the creator
-
comment
Returns the comment associated with the torrent. If there's no comment, it will return an empty string.The comment is an UTF-8 encoded strings.
- Returns:
- the comment
-
nodes
-
addNode
This is used when creating torrent. Use this to add a known DHT node. It may be used, by the client, to bootstrap into the DHT network.- Parameters:
host-port-
-
info
This function looks up keys from the info-dictionary of the loaded torrent file. It can be used to access extension values put in the .torrent file. If the specified key cannot be found, it returns NULL.- Parameters:
key-- Returns:
-
makeMagnetUri
Generates a magnet URI from the specified torrent. If the torrent is invalid, null is returned.For more information about magnet links, see magnet-links_.
-
toEntry
-
bencode
public byte[] bencode() -
bdecode
-