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
9 // magnet URIs and torrent metainfo files.
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.
17 // The chunk size to use for outbound requests. Defaults to 16KiB if not
20 Storage storage.ClientImpl
23 func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
24 m, err := metainfo.ParseMagnetURI(uri)
29 Trackers: [][]string{m.Trackers},
30 DisplayName: m.DisplayName,
36 func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) {
37 info := mi.UnmarshalInfo()
39 Trackers: mi.AnnounceList,
40 InfoBytes: mi.InfoBytes,
41 DisplayName: info.Name,
42 InfoHash: mi.HashInfoBytes(),
44 if spec.Trackers == nil && mi.Announce != "" {
45 spec.Trackers = [][]string{{mi.Announce}}