2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
2013-12-05 15:18:13 +00:00
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"io"
|
2014-03-25 03:01:26 +00:00
|
|
|
"time"
|
2013-12-05 15:18:13 +00:00
|
|
|
)
|
|
|
|
|
2009-11-23 12:46:12 +00:00
|
|
|
type Item struct {
|
|
|
|
// RSS and Shared fields
|
2010-05-23 14:21:30 +00:00
|
|
|
Title string
|
2010-12-17 23:25:16 +00:00
|
|
|
Links []*Link
|
2010-05-23 14:21:30 +00:00
|
|
|
Description string
|
|
|
|
Author Author
|
2010-12-17 23:25:16 +00:00
|
|
|
Categories []*Category
|
2010-05-23 14:21:30 +00:00
|
|
|
Comments string
|
2010-12-17 23:25:16 +00:00
|
|
|
Enclosures []*Enclosure
|
2013-11-28 09:22:09 +00:00
|
|
|
Guid *string
|
2014-03-25 02:58:36 +00:00
|
|
|
PubDate string
|
2010-12-17 23:25:16 +00:00
|
|
|
Source *Source
|
2009-11-23 12:46:12 +00:00
|
|
|
|
|
|
|
// Atom specific fields
|
2010-05-23 14:21:30 +00:00
|
|
|
Id string
|
2010-12-17 23:25:16 +00:00
|
|
|
Generator *Generator
|
2010-05-23 14:21:30 +00:00
|
|
|
Contributors []string
|
2010-12-17 23:25:16 +00:00
|
|
|
Content *Content
|
2015-07-26 21:04:53 +00:00
|
|
|
Updated string
|
2014-01-18 14:30:56 +00:00
|
|
|
|
2014-01-23 16:57:26 +00:00
|
|
|
Extensions map[string]map[string][]Extension
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
2013-12-05 15:04:00 +00:00
|
|
|
|
2014-03-25 02:58:36 +00:00
|
|
|
func (i *Item) ParsedPubDate() (time.Time, error) {
|
2014-03-25 03:01:26 +00:00
|
|
|
return parseTime(i.PubDate)
|
2014-03-25 02:58:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 15:04:00 +00:00
|
|
|
func (i *Item) Key() string {
|
|
|
|
switch {
|
|
|
|
case i.Guid != nil && len(*i.Guid) != 0:
|
|
|
|
return *i.Guid
|
|
|
|
case len(i.Id) != 0:
|
|
|
|
return i.Id
|
2014-03-25 02:58:36 +00:00
|
|
|
case len(i.Title) > 0 && len(i.PubDate) > 0:
|
|
|
|
return i.Title + i.PubDate
|
2013-12-05 15:18:13 +00:00
|
|
|
default:
|
|
|
|
h := md5.New()
|
|
|
|
io.WriteString(h, i.Description)
|
|
|
|
return string(h.Sum(nil))
|
2013-12-05 15:04:00 +00:00
|
|
|
}
|
|
|
|
}
|