atomashpolskiy / bt

BitTorrent library and client with DHT, magnet links, encryption and more
https://atomashpolskiy.github.io/bt/
Apache License 2.0
2.42k stars 381 forks source link

How to create own .torrent file without any external tools and using only BT lib #103

Open vikulin opened 5 years ago

vikulin commented 5 years ago

How to create own .torrent file without any external tools and using only BT lib. It would be great if anyone could add such example code.

IriaSomobu commented 4 years ago

Same question here. Found #92 so far, but that one about seeding, not torrent creation.

atomashpolskiy commented 4 years ago

Not possible atm, so you'll need to use an external tool. PRs welcome!

IriaSomobu commented 4 years ago

Found SO question, but generated file makes BT stop work with following error:

bt.BtException: Validation failed for torrent metainfo:
1. Standard torrent model: [properties are required: [announce, info]]
2. Standalone info dictionary model: [properties are mutually exclusive: [[length], [files]]; properties are required: [length, files]; properties are required: [piece length, pieces]]
    at bt.metainfo.MetadataService.buildTorrent(MetadataService.java:124)
    at bt.metainfo.MetadataService.fromUrl(MetadataService.java:90)
    at bt.TorrentClientBuilder.fetchTorrentFromUrl(TorrentClientBuilder.java:277)
    at bt.TorrentClientBuilder.lambda$buildProcessingContext$0(TorrentClientBuilder.java:237)
    at bt.processor.torrent.FetchTorrentStage.doExecute(FetchTorrentStage.java:36)
    at bt.processor.torrent.FetchTorrentStage.doExecute(FetchTorrentStage.java:25)
    at bt.processor.TerminateOnErrorProcessingStage.doExecute(TerminateOnErrorProcessingStage.java:38)
    at bt.processor.RoutingProcessingStage.execute(RoutingProcessingStage.java:39)
    at bt.processor.ChainProcessor.doExecute(ChainProcessor.java:112)
    at bt.processor.ChainProcessor.executeStage(ChainProcessor.java:96)
    at bt.processor.ChainProcessor.lambda$process$0(ChainProcessor.java:81)
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

UPD: qBittorrent successfully parses this generated file

atomashpolskiy commented 4 years ago

We're being conservative over the format of metainfo and validate against the following schema: bt-core/src/main/resources/metainfo.yml.

Perhaps, we can relax the requirement for the announce key to be present. For other properties, I need to check the contents of the file that you've generated. For instance, properties are required: [piece length, pieces] message looks like a valid reason to fail the parsing of metainfo, because without these properties we won't be able to download the data anyways. It's weird that qBittorrent accepts the file, but maybe I'm missing something.

Can you post the file?

IriaSomobu commented 4 years ago

Here you are: file.torrent.zip

atomashpolskiy commented 4 years ago

Try adding a bogus announce value.

atomashpolskiy commented 4 years ago

Yep, adding announce does the trick:

d8:announce8:http://a4:info...

So, there are three issues: