4 "github.com/anacrolix/torrent/metainfo"
5 "github.com/anacrolix/torrent/storage"
8 // Specifies a new torrent for adding to a client. There are helpers for magnet URIs and torrent
10 type TorrentSpec struct {
11 // The tiered tracker URIs.
13 InfoHash metainfo.Hash
15 // The name to use if the Name field from the Info isn't available.
20 // The chunk size to use for outbound requests. Defaults to 16KiB if not set.
22 Storage storage.ClientImpl
25 func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
26 m, err := metainfo.ParseMagnetURI(uri)
31 Trackers: [][]string{m.Trackers},
32 DisplayName: m.DisplayName,
34 Webseeds: m.Params["ws"],
35 // TODO: What's the parameter for DHT nodes or bootstrap peers in a magnet link?
40 func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) *TorrentSpec {
41 info, err := mi.UnmarshalInfo()
46 Trackers: mi.UpvertedAnnounceList(),
47 InfoHash: mi.HashInfoBytes(),
48 InfoBytes: mi.InfoBytes,
49 DisplayName: info.Name,
51 DhtNodes: func() (ret []string) {
52 ret = make([]string, len(mi.Nodes))
53 for _, node := range mi.Nodes {
54 ret = append(ret, string(node))