2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "xmlx"
|
|
|
|
|
|
|
|
func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
|
2010-05-23 14:21:30 +00:00
|
|
|
channels := doc.SelectNodes("", "channel")
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, node := range channels {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch := Channel{}
|
|
|
|
ch.Title = node.GetValue("", "title")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list := node.SelectNodes("", "link")
|
|
|
|
ch.Links = make([]Link, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Links[i].Href = v.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Description = node.GetValue("", "description")
|
|
|
|
ch.Language = node.GetValue("", "language")
|
|
|
|
ch.Copyright = node.GetValue("", "copyright")
|
|
|
|
ch.ManagingEditor = node.GetValue("", "managingEditor")
|
|
|
|
ch.WebMaster = node.GetValue("", "webMaster")
|
|
|
|
ch.PubDate = node.GetValue("", "pubDate")
|
|
|
|
ch.LastBuildDate = node.GetValue("", "lastBuildDate")
|
|
|
|
ch.Docs = node.GetValue("", "docs")
|
|
|
|
|
|
|
|
list = node.SelectNodes("", "category")
|
|
|
|
ch.Categories = make([]Category, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Categories[i].Domain = v.GetAttr("", "domain")
|
|
|
|
ch.Categories[i].Text = v.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
n := node.SelectNode("", "generator")
|
2009-11-23 12:46:12 +00:00
|
|
|
if n != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Generator = Generator{}
|
|
|
|
ch.Generator.Text = n.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.TTL = node.GetValuei("", "ttl")
|
|
|
|
ch.Rating = node.GetValue("", "rating")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes("", "hour")
|
|
|
|
ch.SkipHours = make([]int, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.SkipHours[i] = int(v.GetValuei("", "hour"))
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes("", "days")
|
|
|
|
ch.SkipDays = make([]int, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.SkipDays[i] = mapDay(v.Value)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if n = node.SelectNode("", "image"); n != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Image.Title = n.GetValue("", "title")
|
|
|
|
ch.Image.Url = n.GetValue("", "url")
|
|
|
|
ch.Image.Link = n.GetValue("", "link")
|
|
|
|
ch.Image.Width = n.GetValuei("", "width")
|
|
|
|
ch.Image.Height = n.GetValuei("", "height")
|
|
|
|
ch.Image.Description = n.GetValue("", "description")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if n = node.SelectNode("", "cloud"); n != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Cloud = Cloud{}
|
|
|
|
ch.Cloud.Domain = n.GetAttr("", "domain")
|
|
|
|
ch.Cloud.Port = n.GetAttri("", "port")
|
|
|
|
ch.Cloud.Path = n.GetAttr("", "path")
|
|
|
|
ch.Cloud.RegisterProcedure = n.GetAttr("", "registerProcedure")
|
|
|
|
ch.Cloud.Protocol = n.GetAttr("", "protocol")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if n = node.SelectNode("", "textInput"); n != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.TextInput = Input{}
|
|
|
|
ch.TextInput.Title = n.GetValue("", "title")
|
|
|
|
ch.TextInput.Description = n.GetValue("", "description")
|
|
|
|
ch.TextInput.Name = n.GetValue("", "name")
|
|
|
|
ch.TextInput.Link = n.GetValue("", "link")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes("", "item")
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, item := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
i := Item{}
|
|
|
|
i.Title = item.GetValue("", "title")
|
|
|
|
i.Description = item.GetValue("", "description")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes("", "link")
|
|
|
|
i.Links = make([]Link, 0)
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
lnk := Link{}
|
|
|
|
lnk.Href = v.Value
|
2010-12-17 20:57:48 +00:00
|
|
|
i.Links = append(i.Links, lnk)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if n = item.SelectNode("", "author"); n != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
i.Author = Author{}
|
|
|
|
i.Author.Name = n.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
i.Comments = item.GetValue("", "comments")
|
|
|
|
i.Guid = item.GetValue("", "guid")
|
|
|
|
i.PubDate = item.GetValue("", "pubDate")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list := item.SelectNodes("", "category")
|
|
|
|
i.Categories = make([]Category, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for li, lv := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
i.Categories[li].Domain = lv.GetAttr("", "domain")
|
|
|
|
i.Categories[li].Text = lv.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = item.SelectNodes("", "enclosure")
|
|
|
|
i.Enclosures = make([]Enclosure, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for li, lv := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
i.Enclosures[li].Url = lv.GetAttr("", "url")
|
|
|
|
i.Enclosures[li].Length = lv.GetAttri64("", "length")
|
|
|
|
i.Enclosures[li].Type = lv.GetAttr("", "type")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
src := item.SelectNode("", "source")
|
2009-11-23 12:46:12 +00:00
|
|
|
if src != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
i.Source = Source{}
|
|
|
|
i.Source.Url = src.GetAttr("", "url")
|
|
|
|
i.Source.Text = src.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
ch.Items = append(ch.Items, i)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
this.Channels = append(this.Channels, ch)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func mapDay(day string) int {
|
|
|
|
switch day {
|
2010-05-23 14:21:30 +00:00
|
|
|
case "Monday":
|
|
|
|
return 1
|
|
|
|
case "Tuesday":
|
|
|
|
return 2
|
|
|
|
case "Wednesday":
|
|
|
|
return 3
|
|
|
|
case "Thursday":
|
|
|
|
return 4
|
|
|
|
case "Friday":
|
|
|
|
return 5
|
|
|
|
case "Saturday":
|
|
|
|
return 6
|
|
|
|
case "Sunday":
|
|
|
|
return 7
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
2010-05-23 14:21:30 +00:00
|
|
|
return 1
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|