2015-03-27 17:16:50 +11:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2016-04-04 13:48:39 +10:00
|
|
|
"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"
|
2015-03-27 17:16:50 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-07-17 18:12:54 +10:00
|
|
|
tagflag.Parse(nil, tagflag.Description("reads a torrent file from stdin and writes out its magnet link to stdout"))
|
2016-04-04 13:48:39 +10:00
|
|
|
|
2015-03-27 17:16:50 +11:00
|
|
|
mi, err := metainfo.Load(os.Stdin)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error reading metainfo from stdin: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-09-20 18:39:07 +10:00
|
|
|
info, err := mi.UnmarshalInfo()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error unmarshalling info: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-04-03 08:51:46 -05:00
|
|
|
|
2016-08-26 20:29:05 +10:00
|
|
|
fmt.Fprintf(os.Stdout, "%s\n", mi.Magnet(info.Name, mi.HashInfoBytes()).String())
|
2015-03-27 17:16:50 +11:00
|
|
|
}
|