]> Sergey Matveev's repositories - btrtrc.git/blob - cmd/torrent-magnet/main.go
3d4bf137da5503ff012d186bfb178ec2766e8708
[btrtrc.git] / cmd / torrent-magnet / main.go
1 package main
2
3 import (
4         "fmt"
5         "os"
6
7         "github.com/anacrolix/tagflag"
8         "github.com/anacrolix/torrent/metainfo"
9 )
10
11 func main() {
12         tagflag.Parse(nil, tagflag.Description("reads a torrent file from stdin and writes out its magnet link to stdout"))
13
14         mi, err := metainfo.Load(os.Stdin)
15         if err != nil {
16                 fmt.Fprintf(os.Stderr, "error reading metainfo from stdin: %s", err)
17                 os.Exit(1)
18         }
19         info, err := mi.UnmarshalInfo()
20         if err != nil {
21                 fmt.Fprintf(os.Stderr, "error unmarshalling info: %s", err)
22                 os.Exit(1)
23         }
24
25         fmt.Fprintf(os.Stdout, "%s\n", mi.Magnet(info.Name, mi.HashInfoBytes()).String())
26 }