/
file.go
36 lines (31 loc) · 896 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package nzb
import (
"fmt"
"strings"
)
//File is a go struct representation of the nzb file elements. It contains the
//appropriate field tags and methods for deserialization
type File struct {
Poster string `xml:"poster,attr"`
Date int `xml:"date,attr"`
Subject string `xml:"subject,attr"`
Groups []string `xml:"groups>group,internalxml"`
Segments []Segment `xml:"segments>segment"`
}
//A Segment is a piece to be downloaded separately
type Segment struct {
Number int `xml:"number,attr"`
Bytes int `xml:"bytes,attr"`
ID string `xml:",innerxml"`
}
//Name returns the estimated filename that an NZB represents.
func (f *File) Name() (string, error) {
parts := strings.Split(f.Subject, `"`)
n := ""
if len(parts) > 1 {
n = strings.Replace(parts[1], "/", "-", -1)
} else {
return "", fmt.Errorf("could not parse subject")
}
return n, nil
}