2
0
mirror of synced 2025-02-24 14:48:27 +00:00

28 lines
600 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"github.com/anacrolix/tagflag"
2019-08-21 20:58:40 +10:00
2015-04-30 00:31:34 +10: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())
}