FedP2P/cmd/torrent-magnet/main.go

28 lines
600 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"github.com/anacrolix/tagflag"
2019-08-21 18:58:40 +08:00
2015-04-29 22:31:34 +08:00
"github.com/anacrolix/torrent/metainfo"
)
func main() {
tagflag.Parse(nil, tagflag.Description("reads a torrent file from stdin and writes out its magnet link to stdout"))
mi, err := metainfo.Load(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading metainfo from stdin: %s", err)
os.Exit(1)
}
info, err := mi.UnmarshalInfo()
if err != nil {
fmt.Fprintf(os.Stderr, "error unmarshalling info: %s", err)
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "%s\n", mi.Magnet(info.Name, mi.HashInfoBytes()).String())
}