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.
19 // The combination of the "xs" and "as" fields in magnet links, for now.
22 // The chunk size to use for outbound requests. Defaults to 16KiB if not set.
24 Storage storage.ClientImpl
27 func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
28 m, err := metainfo.ParseMagnetURI(uri)
33 Trackers: [][]string{m.Trackers},
34 DisplayName: m.DisplayName,
36 Webseeds: m.Params["ws"],
37 Sources: append(m.Params["xs"], m.Params["as"]...),
38 // TODO: What's the parameter for DHT nodes or bootstrap peers in a magnet link?
43 func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) *TorrentSpec {
44 info, err := mi.UnmarshalInfo()
49 Trackers: mi.UpvertedAnnounceList(),
50 InfoHash: mi.HashInfoBytes(),
51 InfoBytes: mi.InfoBytes,
52 DisplayName: info.Name,
54 DhtNodes: func() (ret []string) {
55 ret = make([]string, len(mi.Nodes))
56 for _, node := range mi.Nodes {
57 ret = append(ret, string(node))