public final class TorrentInfo
extends java.lang.Object
Constructor and Description |
---|
TorrentInfo(java.io.File torrent)
Load the torrent file and decode it inside the constructor, for convenience.
|
TorrentInfo(java.nio.MappedByteBuffer buffer) |
TorrentInfo(torrent_info ti) |
Modifier and Type | Method and Description |
---|---|
void |
addHttpSeed(java.lang.String url)
Adds one url to the list of http seeds.
|
void |
addHttpSeed(java.lang.String url,
java.lang.String externAuth)
Adds one url to the list of http seeds.
|
void |
addHttpSeed(java.lang.String url,
java.lang.String externAuth,
java.util.List<Pair<java.lang.String,java.lang.String>> extraHeaders)
Adds one url to the list of http seeds.
|
void |
addNode(java.lang.String host,
int port)
This is used when creating torrent.
|
void |
addTracker(java.lang.String url)
Adds a tracker to the announce-list.
|
void |
addTracker(java.lang.String url,
int tier)
Adds a tracker to the announce-list.
|
void |
addUrlSeed(java.lang.String url)
Adds one url to the list of url seeds.
|
void |
addUrlSeed(java.lang.String url,
java.lang.String externAuth)
Adds one url to the list of url seeds.
|
void |
addUrlSeed(java.lang.String url,
java.lang.String externAuth,
java.util.List<Pair<java.lang.String,java.lang.String>> extraHeaders)
Adds one url to the list of url seeds.
|
static TorrentInfo |
bdecode(byte[] data) |
byte[] |
bencode() |
void |
clearTrackers()
Clear the internal list of trackers.
|
java.util.ArrayList<java.lang.String> |
collections()
This function is related to BEP38_ (mutable torrents).
|
java.lang.String |
comment()
returns the comment associated with the torrent.
|
int |
creationDate()
returns the creation date of
the torrent as time_t (`posix time`_).
|
java.lang.String |
creator()
returns the creator string in the torrent.
|
FileStorage |
files()
The
FileStorage object contains the information on
how to map the pieces to files. |
Sha1Hash |
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.
|
bdecode_node |
info(java.lang.String key)
This function looks up keys from the info-dictionary of the loaded
torrent file.
|
Sha1Hash |
infoHash()
returns the info-hash of the torrent.
|
boolean |
isI2p()
Returns true if this is an i2p torrent.
|
boolean |
isLoaded() |
boolean |
isMerkleTorrent()
Returns whether or not this is a merkle torrent.
|
boolean |
isPrivate()
Returns true if this torrent is private.
|
boolean |
isValid()
Returns true if this torrent_info object has a torrent loaded.
|
java.lang.String |
makeMagnetUri()
Generates a magnet URI from the specified torrent.
|
java.util.ArrayList<FileSlice> |
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.
|
PeerRequest |
mapFile(int file,
long offset,
int size)
This function will map a range in a specific file into a range in the torrent.
|
java.util.ArrayList<Sha1Hash> |
merkleTree()
Returns a copy to the merkle tree for this
torrent, if any.
|
void |
merkleTree(java.util.List<Sha1Hash> tree)
Copies the passed in merkle tree into the torrent info object.
|
java.lang.String |
name()
returns the name of the torrent.
|
java.util.ArrayList<Pair<java.lang.String,java.lang.Integer>> |
nodes()
If this torrent contains any DHT nodes, they are returned in
their original form (host name and port number).
|
int |
numFiles()
If you need index-access to files you can use this method
to access files using indices.
|
int |
numPieces()
The total number of pieces.
|
FileStorage |
origFiles()
Returns the original (unmodified) file storage for this torrent.
|
int |
pieceLength()
The number of byte for each piece.
|
int |
pieceSize(int index) |
void |
remapFiles(FileStorage f)
Remaps the file storage to a new file layout.
|
void |
renameFile(int index,
java.lang.String newFilename)
Renames a the file with the specified index to the new name.
|
void |
setWebSeeds(java.util.List<WebSeedEntry> seeds)
Replaces all web seeds with the ones specified in the
seeds list. |
java.util.ArrayList<Sha1Hash> |
similarTorrents()
This function is related to BEP38_ (mutable torrents).
|
torrent_info |
swig() |
Entry |
toEntry() |
long |
totalSize()
The total number of bytes the torrent-file represents (all the files in it).
|
java.util.ArrayList<AnnounceEntry> |
trackers()
Will return a sorted list with the trackers of this torrent info.
|
java.util.ArrayList<WebSeedEntry> |
webSeeds()
Returns all url seeds and http seeds in the torrent.
|
public TorrentInfo(torrent_info ti)
public TorrentInfo(java.io.File torrent)
This might not be the most suitable for applications that want to be able to report detailed errors on what might go wrong.
torrent
- public TorrentInfo(java.nio.MappedByteBuffer buffer)
public torrent_info swig()
public FileStorage files()
FileStorage
object contains the information on
how to map the pieces to files.
It is separated from the TorrentInfo
object 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 the FileStorage
in order
to make its mapping differ from the one in the torrent file.
public FileStorage origFiles()
renameFile(int, String)
.public void renameFile(int index, java.lang.String newFilename)
FileStorage
returned by files()
but not by the one returned by origFiles()
.
If you want to rename the base name of the torrent (for a multifile
torrent), you can copy the FileStorage
(see files()
and
origFiles()
), change the name, and then use
remapFiles(FileStorage)
.
The newFilename
can both be a relative path, in which case the
file name is relative to the savePath
of the torrent. If the
newFilename
is an absolute path (i.e. "is_complete(newFilename)
== true"), then the file is detached from the savePath
of the
torrent. In this case the file is not moved when
TorrentHandle.moveStorage(String, int)
is invoked.
index
- newFilename
- public void remapFiles(FileStorage f)
The new specified FileStorage
must have the exact same size as
the current one.
f
- public void addTracker(java.lang.String url)
url
- public void addTracker(java.lang.String url, int tier)
url
- tier
- public java.util.ArrayList<AnnounceEntry> trackers()
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.
public java.util.ArrayList<Sha1Hash> similarTorrents()
BEP38: http://www.bittorrent.org/beps/bep_0038.html
public java.util.ArrayList<java.lang.String> collections()
BEP38: http://www.bittorrent.org/beps/bep_0038.html
public void clearTrackers()
public void addUrlSeed(java.lang.String url)
url
- addHttpSeed(String, String)
public void addUrlSeed(java.lang.String url, java.lang.String externAuth)
The externAuth
argument 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.
url
- externAuth
- public void addUrlSeed(java.lang.String url, java.lang.String externAuth, java.util.List<Pair<java.lang.String,java.lang.String>> extraHeaders)
The externAuth
argument 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 extraHeaders
argument can be used to insert custom HTTP headers
in the requests to a specific web seed.
url
- externAuth
- extraHeaders
- public void addHttpSeed(java.lang.String url)
url
- public void addHttpSeed(java.lang.String url, java.lang.String externAuth)
The externAuth
argument 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").
url
- externAuth
- public void addHttpSeed(java.lang.String url, java.lang.String externAuth, java.util.List<Pair<java.lang.String,java.lang.String>> extraHeaders)
The externAuth
argument 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 extraHeaders
argument defaults to an empty list, but can be used to
insert custom HTTP headers in the requests to a specific web seed.
url
- externAuth
- extraHeaders
- public java.util.ArrayList<WebSeedEntry> webSeeds()
WebSeedEntry
and may refer to either a url seed or http seed.public void setWebSeeds(java.util.List<WebSeedEntry> seeds)
seeds
list.seeds
- public long totalSize()
public int pieceLength()
The difference between pieceSize(int)
and pieceLength()
is that
pieceSize(int)
takes the piece index as argument and gives you the exact size
of that piece. It will always be the same as pieceLength()
except in the case
of the last piece, which may be smaller.
public int numPieces()
public Sha1Hash infoHash()
public int numFiles()
public java.util.ArrayList<FileSlice> mapBlock(int piece, long offset, int size)
piece
- offset
- size
- FileSlice
public PeerRequest mapFile(int file, long offset, int size)
offset
parameter 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 + size
is not allowed to be greater than the file size. index
must refer to a valid file, i.e. it cannot be >= numFiles()
.
file
- offset
- size
- PeerRequest
public boolean isValid()
This is primarily used to determine if a magnet link has had its metadata resolved yet or not.
public boolean isPrivate()
public boolean isI2p()
public int pieceSize(int index)
public Sha1Hash hashForPiece(int index)
index
- public boolean isLoaded()
public java.util.ArrayList<Sha1Hash> merkleTree()
public void merkleTree(java.util.List<Sha1Hash> tree)
You need to set the merkle tree for a torrent that you've just created
(as a merkle torrent). The merkle tree is retrieved from the
merkleTree()
function, and need to be saved
separately from the torrent file itself. Once it's added to
libtorrent, the merkle tree will be persisted in the resume data.
tree
- public java.lang.String name()
the name is an UTF-8 encoded strings.
public int creationDate()
public java.lang.String creator()
public java.lang.String comment()
the comment is an UTF-8 encoded strings.
public java.util.ArrayList<Pair<java.lang.String,java.lang.Integer>> nodes()
public void addNode(java.lang.String host, int port)
host
- port
- public bdecode_node info(java.lang.String key)
key
- public boolean isMerkleTorrent()
public java.lang.String makeMagnetUri()
For more information about magnet links, see magnet-links_.
public Entry toEntry()
public byte[] bencode()
public static TorrentInfo bdecode(byte[] data)