@zhongdao
2020-08-24T20:29:43.000000Z
字数 4664
阅读 1520
未分类
How to generate a Torrent Magnet URI from a directory?
https://stackoverflow.com/questions/30294387/how-to-generate-a-torrent-magnet-uri-from-a-directory
There's no method exposed to create a magnet URI directly because such a link would be unusable!
Magnet links are hash identifiers that allow clients to retrieve a torrent file from the BitTorrent DHT network. However, they can only do so if there's at least one other client online (and with DHT enabled) that's downloading or seeding that torrent. If you generated a torrent within your application and generated a magnet link from that directly, nobody would ever have that torrent file, so it wouldn't be downloadable.
Long story short: Magnet links only really work for torrents that are created and seeded on a peer-to-peer basis. If you want to use a web seed, you'll need to offer the full torrent file for download by users.
What is “web seed”?
https://askubuntu.com/questions/313107/what-is-web-seed#:~:text=%5BWeb%20Seeds%20are%20the%5D%20location,contents%2C%20or%20existing%20web%20locations.
The purpose of this extension is to allow clients to join a swarm and complete a download without the need of downloading a .torrent file first. This extension instead allows clients to download the metadata from peers. It makes it possible to support magnet links, a link on a web page only containing enough information to join the swarm (the info hash).
magnet URI format
The magnet URI format is:
v1: magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>&x.pe=<peer-address>
v2: magnet:?xt=urn:btmh:<tagged-info-hash>&dn=<name>&tr=<tracker-url>&x.pe=<peer-address>
<peer-address>
A peer address expressed as hostname:port, ipv4-literal:port or [ipv6-literal]:port. This parameter can be included to initiate a direct metadata transfer between two clients while reducing the need for external peer sources. It should only be included if the client can discover its public IP address and determine its reachability. Note: Since no URI scheme identifier has been allocated for bittorrent xs= is not used for this purpose.
**If no tracker is specified, the client SHOULD use the DHT (BEP 0005) to acquire peers.**
Abstract
Using HTTP or FTP servers as seeds for BitTorrent downloads.
Rationale
Many websites that list a BitTorrent download also provide a HTTP or FTP URL for the same file. The files are identical. A WebSeeding BitTorrent client can download from either source, putting all the parts together into one complete file.
The HTTP or FTP server acts as a permanently unchoked seed.
rain torrent create
NAME:
rain torrent create - create new torrent file
USAGE:
rain torrent create [command options] [arguments...]
OPTIONS:
--file value, -f value include this file or directory in torrent
--out FILE, -o FILE save generated torrent to this FILE
--private, -p create torrent for private trackers
--piece-length value, -l value override default piece length. by default, piece length calculated automatically based on the total size of files. given in KB. must be multiple of 16. (default: 0)
--comment COMMENT, -c COMMENT add COMMENT to torrent
--tracker URL, -t URL add tracker URL
--webseed URL, -w URL add webseed URL
rain torrent create
NAME:
rain torrent create - create new torrent file
USAGE:
rain torrent create [command options] [arguments...]
OPTIONS:
--file value, -f value include this file or directory in torrent
--out FILE, -o FILE save generated torrent to this FILE
--private, -p create torrent for private trackers
--piece-length value, -l value override default piece length. by default, piece length calculated automatically based on the total size of files. given in KB. must be multiple of 16. (default: 0)
--comment COMMENT, -c COMMENT add COMMENT to torrent
--tracker URL, -t URL add tracker URL
--webseed URL, -w URL add webseed URL
NAME:
rain client - send rpc request to server
USAGE:
rain client command [command options] [arguments...]
COMMANDS:
Actions:
add add torrent or magnet
remove remove torrent
clean-database clean session database
add-peer add peer to torrent
add-tracker add tracker to torrent
announce announce to tracker
verify verify files
start start torrent
stop stop torrent
start-all start all torrents
stop-all stop all torrents
move move torrent to another server
Getters:
version server version
list list torrents
stats get stats of torrent
session-stats get stats of session
trackers get trackers of torrent
webseeds get webseed sources of torrent
peers get peers of torrent
torrent save torrent file
magnet get magnet link
Other:
console show client console
OPTIONS:
--url value URL of RPC server (default: "http://127.0.0.1:7246")
--timeout value request timeout (default: 10s)
--help, -h show help
rain torrent create -t http://bttracker.top:6969/announce -f tests -o tests.torrent
注意:
ll /data/dcp/tstdir5/gnome-software-0J8ZXZ/debconf.socket
srwxrwxrwx 1 tms tms 0 2月 25 2019 /data/dcp/tstdir5/gnome-software-0J8ZXZ/debconf.socket=
s文件会停止并提示:
rain torrent create -t http://bttracker.top:6969/announce -f /data/dcp/tstdir5 -o tstdir5.torrent
2020-08-23 18:54:21 CRITICAL [rain] main.go:482 open /data/dcp/tstdir5/gnome-software-0J8ZXZ/debconf.socket: no such device or address
rain torrent show -f tests.torrent
rain client add -t testonly_dirsend.torrent
注意确保 原文件路径 在位置上。