17 "go.stargrave.org/rutrackerer"
21 doCSV := flag.Bool("csv", false, "Output CSV instead of gob")
23 br := bufio.NewReader(os.Stdin)
24 d := xml.NewDecoder(br)
27 var e xml.StartElement
34 e, ok = t.(xml.StartElement)
35 if ok && e.Name.Local == "torrents" {
39 var gobEnc *gob.Encoder
40 bufStdout := bufio.NewWriter(os.Stdout)
42 gobEnc = gob.NewEncoder(bufStdout)
44 emptyHash := make([]byte, sha1.Size)
45 var torrent *rutrackerer.Torrent
56 e, ok = t.(xml.StartElement)
66 c, ok = t.(xml.CharData)
68 panic("non-character data after title")
70 torrent.Title = string(c)
73 for _, attr = range e.Attr {
74 if attr.Name.Local != "hash" {
77 if len(attr.Value) != sha1.Size*2 {
78 panic("bad hash size")
80 _, err = hex.Decode(torrent.Hash[:], []byte(attr.Value))
88 if torrent.Title == "" {
94 if torrent.Size == 0 {
97 if bytes.Compare(torrent.Hash[:], emptyHash) == 0 {
101 fmt.Println(torrent.CSV())
103 if err = gobEnc.Encode(torrent); err != nil {
108 torrent = new(rutrackerer.Torrent)
109 for _, attr = range e.Attr {
110 switch attr.Name.Local {
112 torrent.Id, err = strconv.ParseInt(attr.Value, 10, 64)
116 torrent.Offset = d.InputOffset()
118 torrent.Registered, err = time.Parse(
119 "2006.01.02 15:04:05", attr.Value,
125 torrent.Size, err = strconv.ParseInt(attr.Value, 10, 64)
134 if err = bufStdout.Flush(); err != nil {