2015-03-27 06:16:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-04-07 16:15:25 +00:00
|
|
|
"flag"
|
2015-03-27 06:16:50 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent"
|
2015-04-29 14:31:34 +00:00
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
2015-03-27 06:16:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2015-04-07 16:15:25 +00:00
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() != 0 {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", "torrent-magnet: unexpected positional arguments")
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
2015-03-27 06:16:50 +00:00
|
|
|
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())
|
|
|
|
}
|