diff --git a/client.go b/client.go index d525b56f..430cb542 100644 --- a/client.go +++ b/client.go @@ -2250,8 +2250,9 @@ func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) { func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) { spec = &TorrentSpec{ - Trackers: mi.AnnounceList, - Info: &mi.Info, + Trackers: mi.AnnounceList, + Info: &mi.Info, + DisplayName: mi.Info.Name, } CopyExact(&spec.InfoHash, &mi.Info.Hash) return diff --git a/cmd/torrent-magnet/main.go b/cmd/torrent-magnet/main.go new file mode 100644 index 00000000..23a03757 --- /dev/null +++ b/cmd/torrent-magnet/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "os" + + "github.com/anacrolix/libtorgo/metainfo" + + "github.com/anacrolix/torrent" +) + +func main() { + mi, err := metainfo.Load(os.Stdin) + if err != nil { + fmt.Fprintf(os.Stderr, "error reading metainfo from stdin: %s", err) + os.Exit(1) + } + ts := torrent.TorrentSpecFromMetaInfo(mi) + m := torrent.Magnet{ + InfoHash: ts.InfoHash, + Trackers: func() (ret []string) { + for _, tier := range ts.Trackers { + for _, tr := range tier { + ret = append(ret, tr) + } + } + return + }(), + DisplayName: ts.DisplayName, + } + fmt.Fprintf(os.Stdout, "%s\n", m.String()) +}