2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
2018-02-22 08:20:54 +00:00
|
|
|
import xmlx "git.dnix.de/an/go-pkg-xmlx"
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2011-11-02 15:51:04 +00:00
|
|
|
func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
|
2010-05-23 14:21:30 +00:00
|
|
|
ns := "http://www.w3.org/2005/Atom"
|
|
|
|
channels := doc.SelectNodes(ns, "feed")
|
2010-12-17 23:25:16 +00:00
|
|
|
|
2013-12-05 13:08:41 +00:00
|
|
|
var foundChannels []*Channel
|
2010-12-17 23:25:16 +00:00
|
|
|
var ch *Channel
|
|
|
|
var i *Item
|
|
|
|
var tn *xmlx.Node
|
|
|
|
var list []*xmlx.Node
|
|
|
|
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, node := range channels {
|
2013-12-05 13:08:41 +00:00
|
|
|
ch = new(Channel)
|
|
|
|
foundChannels = append(foundChannels, ch)
|
2010-12-17 23:25:16 +00:00
|
|
|
|
2011-05-11 15:40:56 +00:00
|
|
|
ch.Title = node.S(ns, "title")
|
|
|
|
ch.LastBuildDate = node.S(ns, "updated")
|
|
|
|
ch.Id = node.S(ns, "id")
|
|
|
|
ch.Rights = node.S(ns, "rights")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-12-17 23:25:16 +00:00
|
|
|
list = node.SelectNodes(ns, "link")
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Links = make([]Link, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2011-05-11 15:40:56 +00:00
|
|
|
ch.Links[i].Href = v.As("", "href")
|
|
|
|
ch.Links[i].Rel = v.As("", "rel")
|
|
|
|
ch.Links[i].Type = v.As("", "type")
|
|
|
|
ch.Links[i].HrefLang = v.As("", "hreflang")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 23:25:16 +00:00
|
|
|
if tn = node.SelectNode(ns, "subtitle"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.SubTitle = SubTitle{}
|
2011-05-11 15:40:56 +00:00
|
|
|
ch.SubTitle.Type = tn.As("", "type")
|
2013-09-30 05:23:51 +00:00
|
|
|
ch.SubTitle.Text = tn.GetValue()
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if tn = node.SelectNode(ns, "generator"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Generator = Generator{}
|
2011-05-11 15:40:56 +00:00
|
|
|
ch.Generator.Uri = tn.As("", "uri")
|
|
|
|
ch.Generator.Version = tn.As("", "version")
|
2013-09-30 05:23:51 +00:00
|
|
|
ch.Generator.Text = tn.GetValue()
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if tn = node.SelectNode(ns, "author"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Author = Author{}
|
2011-05-11 15:40:56 +00:00
|
|
|
ch.Author.Name = tn.S("", "name")
|
|
|
|
ch.Author.Uri = tn.S("", "uri")
|
|
|
|
ch.Author.Email = tn.S("", "email")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes(ns, "entry")
|
2010-12-17 23:25:16 +00:00
|
|
|
|
|
|
|
for _, item := range list {
|
|
|
|
i = new(Item)
|
2011-05-11 15:40:56 +00:00
|
|
|
i.Title = item.S(ns, "title")
|
|
|
|
i.Id = item.S(ns, "id")
|
2015-07-26 21:04:53 +00:00
|
|
|
i.PubDate = item.S(ns, "published")
|
|
|
|
i.Updated = item.S(ns, "updated")
|
2011-05-11 15:40:56 +00:00
|
|
|
i.Description = item.S(ns, "summary")
|
2010-12-17 23:25:16 +00:00
|
|
|
|
|
|
|
links := item.SelectNodes(ns, "link")
|
|
|
|
for _, lv := range links {
|
2012-02-29 09:48:17 +00:00
|
|
|
if lv.As(ns, "rel") == "enclosure" {
|
2010-12-17 23:25:16 +00:00
|
|
|
enc := new(Enclosure)
|
2011-05-11 15:40:56 +00:00
|
|
|
enc.Url = lv.As("", "href")
|
|
|
|
enc.Type = lv.As("", "type")
|
2010-12-17 23:25:16 +00:00
|
|
|
i.Enclosures = append(i.Enclosures, enc)
|
2009-11-23 12:46:12 +00:00
|
|
|
} else {
|
2010-12-17 23:25:16 +00:00
|
|
|
lnk := new(Link)
|
2011-05-11 15:40:56 +00:00
|
|
|
lnk.Href = lv.As("", "href")
|
|
|
|
lnk.Rel = lv.As("", "rel")
|
|
|
|
lnk.Type = lv.As("", "type")
|
|
|
|
lnk.HrefLang = lv.As("", "hreflang")
|
2010-12-17 23:25:16 +00:00
|
|
|
i.Links = append(i.Links, lnk)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-17 23:25:16 +00:00
|
|
|
list = item.SelectNodes(ns, "contributor")
|
|
|
|
for _, cv := range list {
|
2011-05-11 15:40:56 +00:00
|
|
|
i.Contributors = append(i.Contributors, cv.S("", "name"))
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 23:48:21 +00:00
|
|
|
list = item.SelectNodes(ns, "category")
|
|
|
|
for _, cv := range list {
|
|
|
|
cat := new(Category)
|
|
|
|
cat.Domain = ""
|
|
|
|
cat.Text = cv.As("", "term")
|
|
|
|
i.Categories = append(i.Categories, cat)
|
|
|
|
}
|
|
|
|
|
2010-12-17 23:25:16 +00:00
|
|
|
if tn = item.SelectNode(ns, "content"); tn != nil {
|
|
|
|
i.Content = new(Content)
|
2011-05-11 15:40:56 +00:00
|
|
|
i.Content.Type = tn.As("", "type")
|
|
|
|
i.Content.Lang = tn.S("xml", "lang")
|
|
|
|
i.Content.Base = tn.S("xml", "base")
|
2013-09-30 05:23:51 +00:00
|
|
|
i.Content.Text = tn.GetValue()
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
2013-11-28 09:23:49 +00:00
|
|
|
|
2013-03-27 19:05:18 +00:00
|
|
|
if tn = item.SelectNode(ns, "author"); tn != nil {
|
2013-11-28 09:23:49 +00:00
|
|
|
i.Author = Author{}
|
|
|
|
i.Author.Name = tn.S(ns, "name")
|
|
|
|
i.Author.Uri = tn.S(ns, "uri")
|
|
|
|
i.Author.Email = tn.S(ns, "email")
|
|
|
|
}
|
2010-12-17 23:25:16 +00:00
|
|
|
|
|
|
|
ch.Items = append(ch.Items, i)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-05 13:08:41 +00:00
|
|
|
this.Channels = foundChannels
|
2009-11-23 12:46:12 +00:00
|
|
|
return
|
|
|
|
}
|