package meta // see also: https://en.wikipedia.org/wiki/Torrent_file import ( "fmt" "io/ioutil" "time" "dim13.org/btget/bencode" ) type Nodes map[string]int // Host:Port type Torrent struct { Announce string `bencode:"announce"` AnnounceList [][]string `bencode:"announce-list,optional"` // BEP-0012 Comment string `bencode:"comment,optional"` CreatedBy string `bencode:"created by,optional"` CreationDate time.Time `bencode:"creation date,optional"` Encoding string `bencode:"encoding,optional"` HTTPSeeds []string `bencode:"httpseeds,optional"` // BEP-0017 Info Info `bencode:"info"` //Nodes Nodes `bencode:"nodes"` // BEP-0005 //URLList []string `bencode:"url-list,optional"` } func (t Torrent) String() string { s := fmt.Sprintf("announce: %s\n", t.Announce) s += fmt.Sprintf("comment: %s\n", t.Comment) s += fmt.Sprintf("date: %s\n", t.CreationDate) s += fmt.Sprintf("%v", t.Info) s += fmt.Sprintf("info hash: %x", t.Info.Hash()) return s } func New(fname string) (Torrent, error) { var tor Torrent body, err := ioutil.ReadFile(fname) if err != nil { return Torrent{}, err } _, err = bencode.Unmarshal(body, &tor) return tor, err }