13 "github.com/dustin/go-humanize"
14 "go.stargrave.org/rutrackerer"
18 cmd := exec.Command("grep", append([]string{"-n"}, os.Args[1:]...)...)
19 grepStdin, err := cmd.StdinPipe()
23 grepStdout, err := cmd.StdoutPipe()
27 if err = cmd.Start(); err != nil {
30 var torrents []*rutrackerer.Torrent
31 gobDec := gob.NewDecoder(bufio.NewReader(os.Stdin))
32 if err = gobDec.Decode(&torrents); err != nil {
35 printer := make(chan struct{})
37 scanner := bufio.NewScanner(grepStdout)
41 var torrent *rutrackerer.Torrent
44 i = strings.IndexByte(t, ':')
45 i, err = strconv.Atoi(t[:i])
49 torrent = torrents[i-1]
53 https://rutracker.org/forum/viewtopic.php?t=%d
54 magnet:?xt=urn:btih:%s
57 torrent.Registered.Format("2006-01-02T15:04:05"),
58 humanize.IBytes(uint64(torrent.Size)),
61 strings.ToUpper(hex.EncodeToString(torrent.Hash[:])),
64 if err = scanner.Err(); err != nil {
69 for _, t := range torrents {
70 if _, err = grepStdin.Write([]byte(t.Title + "\n")); err != nil {
76 if err = cmd.Wait(); err != nil {