Fixed rutracker after changing stucture of the atom file of theirs own
This commit is contained in:
+56
-30
@@ -1,35 +1,61 @@
|
||||
package resource
|
||||
|
||||
import "encoding/xml"
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RutrackerAtomTopic represents the atom feed of a rutracker forum subsection.
|
||||
type RutrackerAtomTopic struct {
|
||||
XMLName xml.Name `xml:"feed"`
|
||||
Text string `xml:",chardata"`
|
||||
Xmlns string `xml:"xmlns,attr"`
|
||||
ID string `xml:"id"`
|
||||
Link struct {
|
||||
Text string `xml:",chardata"`
|
||||
Href string `xml:"href,attr"`
|
||||
} `xml:"link"`
|
||||
Updated string `xml:"updated"`
|
||||
Title string `xml:"title"`
|
||||
Entry []struct {
|
||||
Text string `xml:",chardata"`
|
||||
ID string `xml:"id"`
|
||||
Link struct {
|
||||
Text string `xml:",chardata"`
|
||||
Href string `xml:"href,attr"`
|
||||
} `xml:"link"`
|
||||
Updated string `xml:"updated"`
|
||||
Title string `xml:"title"`
|
||||
Author struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
} `xml:"author"`
|
||||
Category struct {
|
||||
Text string `xml:",chardata"`
|
||||
Term string `xml:"term,attr"`
|
||||
Label string `xml:"label,attr"`
|
||||
} `xml:"category"`
|
||||
} `xml:"entry"`
|
||||
XMLName xml.Name `xml:"feed"`
|
||||
Xmlns string `xml:"xmlns,attr"`
|
||||
ID string `xml:"id"`
|
||||
Link []AtomLink `xml:"link"`
|
||||
Updated string `xml:"updated"`
|
||||
Title string `xml:"title"`
|
||||
Entry []RutrackerAtomEntry `xml:"entry"`
|
||||
}
|
||||
|
||||
// AtomLink is a generic atom link element. An entry contains two links:
|
||||
// a topic page link (no rel) and a magnet link (rel="enclosure").
|
||||
type AtomLink struct {
|
||||
Href string `xml:"href,attr"`
|
||||
Rel string `xml:"rel,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
}
|
||||
|
||||
type RutrackerAtomEntry struct {
|
||||
ID string `xml:"id"`
|
||||
Link []AtomLink `xml:"link"`
|
||||
Updated string `xml:"updated"`
|
||||
Title string `xml:"title"`
|
||||
Author struct {
|
||||
Name string `xml:"name"`
|
||||
} `xml:"author"`
|
||||
Category struct {
|
||||
Term string `xml:"term,attr"`
|
||||
Label string `xml:"label,attr"`
|
||||
} `xml:"category"`
|
||||
}
|
||||
|
||||
// PageLink returns the link to the topic page (the one without rel attribute).
|
||||
func (e RutrackerAtomEntry) PageLink() (AtomLink, bool) {
|
||||
for _, l := range e.Link {
|
||||
if l.Rel == "" {
|
||||
return l, true
|
||||
}
|
||||
}
|
||||
return AtomLink{}, false
|
||||
}
|
||||
|
||||
// TopicId extracts the topic id from the entry id tag: "tag:rto.feed,2026-08-29:/t/5702203".
|
||||
func (e RutrackerAtomEntry) TopicId() (int, error) {
|
||||
const marker = ":/t/"
|
||||
i := strings.LastIndex(e.ID, marker)
|
||||
if i < 0 {
|
||||
return 0, fmt.Errorf("unexpected entry id format: %s", e.ID)
|
||||
}
|
||||
return strconv.Atoi(e.ID[i+len(marker):])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user