基本上我正在制作一个程序,可以通过使用许多api从电影中获取所有信息。它还从电影中下载。torrent文件。我想把这个下载到我的程序里,并且想使用torrent。唯一的问题是:我必须如何使用它?在阅读所有的安装或自述文件,它没有告诉我什么。我知道如何安装一个正常的库,但这有多个文件在多个地图等。
那么,第一个问题:你能简单地解释一下我如何一步一步地安装这个库吗?
第二个问题:你还能给我代码如何使用它下载与。torrent文件?
顺便说一句:如果有任何方法自动打开。torrent文件与qBittorrent,那么这将是唯一可接受的替代对我来说。
1)安装maven,查看如何使用maven启动一个快速的"Hello World"项目。一旦你掌握了它,添加
<dependency>
<groupId>com.turn</groupId>
<artifactId>ttorrent</artifactId>
<version>1.4</version>
</dependency>
到您的pom.xml
2)从你链接的页面:
// First, instantiate the Client object.
Client client = new Client(
// This is the interface the client will listen on (you might need something
// else than localhost here).
InetAddress.getLocalHost(),
// Load the torrent from the torrent file and use the given
// output directory. Partials downloads are automatically recovered.
SharedTorrent.fromFile(
new File("/path/to/your.torrent"),
new File("/path/to/output/directory")));
// You can optionally set download/upload rate limits
// in kB/second. Setting a limit to 0.0 disables rate
// limits.
client.setMaxDownloadRate(50.0);
client.setMaxUploadRate(50.0);
// At this point, can you either call download() to download the torrent and
// stop immediately after...
client.download();
// Or call client.share(...) with a seed time in seconds:
// client.share(3600);
// Which would seed the torrent for an hour after the download is complete.
// Downloading and seeding is done in background threads.
// To wait for this process to finish, call:
client.waitForCompletion();
// At any time you can call client.stop() to interrupt the download.