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

[BUG] Something dCan the project run directly? What I need is to get the metadata according to infohashoes not work as it should #195

Open 1083 opened 2 years ago

1083 commented 2 years ago

Can the project run directly? What I need is to get the metadata according to infohash

pyckle commented 2 years ago

Hi,

What version are you using? Are you trying to download just the metadata file, or the entire torrent? What exact error are you getting?

I just fixed a minor bug that broke magnet link downloads in the latest snapshot. https://github.com/atomashpolskiy/bt/pull/196

I will merge it once the CI passes.

1083 commented 2 years ago

At present, I only have infohash and hostname. port 。 Now I want to get the corresponding metadata. Which method do you need?

1083 commented 2 years ago

At present, I only have infohash and hostname. port 。 Now I want to get the corresponding metadata. Which method do you need?

pyckle commented 2 years ago

Hi, I think you'll need to write a bit of java code to do this.

First, create a torrent context with a Magnet URI. Some examples on how to do this: https://github.com/atomashpolskiy/bt/blob/master/examples/src/main/java/peertracker/Main.java https://github.com/atomashpolskiy/bt/blob/8fb42760859cc121639f9b66c71ba119348e0fd9/bt-tests/src/main/java/bt/it/fixture/LeecherPeer.java#L58

If the hostname/port you have are for a tracker, then you'll need to add it to the magnet URI. If the hostname/port you have are of a peer, the easiest way to bootstrap this peer is with a mock tracker. See: https://github.com/atomashpolskiy/bt/blob/master/examples/src/main/java/yourip/mock/MockTracker.java

When you build a torrent context, there is a callback for when the torrent is fetched: https://github.com/atomashpolskiy/bt/blob/8fb42760859cc121639f9b66c71ba119348e0fd9/bt-core/src/main/java/bt/TorrentClientBuilder.java#L202 You can write a callback method that writes the torrent to disk, and then stops the torrent.

@atomashpolskiy - perhaps this might be a good feature to have? When metadata is downloaded from a magnet link, have an option to persist it to disk.

atomashpolskiy commented 2 years ago

Create a MagnetUri object with the builder (both peer and tracker addresses can be supplied) https://github.com/atomashpolskiy/bt/blob/master/bt-core/src/main/java/bt/magnet/MagnetUri.java#L108

Feed this uri to the client being constructed https://github.com/atomashpolskiy/bt/blob/master/bt-core/src/main/java/bt/TorrentClientBuilder.java#L139

Set the callback to be invoked when the metadata has been fetched (can shutdown from inside the callback) https://github.com/atomashpolskiy/bt/blob/master/bt-core/src/main/java/bt/TorrentClientBuilder.java#L202

CLI client is a good example of how to construct clients overall https://github.com/atomashpolskiy/bt/blob/master/bt-cli/src/main/java/bt/cli/CliClient.java

On Wed, 20 Oct 2021, 07:49 pyckle, @.***> wrote:

Hi, I think you'll need to write a bit of java code to do this.

First, create a torrent context with a Magnet URI. Some examples on how to do this:

https://github.com/atomashpolskiy/bt/blob/master/examples/src/main/java/peertracker/Main.java

https://github.com/atomashpolskiy/bt/blob/8fb42760859cc121639f9b66c71ba119348e0fd9/bt-tests/src/main/java/bt/it/fixture/LeecherPeer.java#L58

If the hostname/port you have are for a tracker, then you'll need to add it to the magnet URI. If the hostname/port you have are of a peer, the easiest way to bootstrap this peer is with a mock tracker. See: https://github.com/atomashpolskiy/bt/blob/master/examples/src/main/java/yourip/mock/MockTracker.java

When you build a torrent context, there is a callback for when the torrent is fetched: https://github.com/atomashpolskiy/bt/blob/8fb42760859cc121639f9b66c71ba119348e0fd9/bt-core/src/main/java/bt/TorrentClientBuilder.java#L202 You can write a callback method that writes the torrent to disk, and then stops the torrent.

@atomashpolskiy https://github.com/atomashpolskiy - perhaps this might be a good feature to have? When metadata is downloaded from a magnet link, have an option to persist it to disk.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/atomashpolskiy/bt/issues/195#issuecomment-947348965, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4TJBQDU7TUY7XYB4YCX63UHZJ7RANCNFSM5GIMSJMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.