-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpodcast.go
91 lines (79 loc) · 2.51 KB
/
podcast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"encoding/xml"
"time"
)
const (
pubDateFormat = "Mon, 2 Jan 2006 15:04:05 -0700"
)
type PodcastRss struct {
XMLName xml.Name `xml:"rss"`
XmlnsItunes string `xml:"xmlns:itunes,attr,omitempty"`
Version string `xml:"version,attr,omitempty"`
Channel PodcastChannel
}
type PodcastChannel struct {
XMLName xml.Name `xml:"channel"`
Title string `xml:"title,omitempty"`
Link string `xml:"link,omitempty"`
Language string `xml:"language,omitempty"`
Copyright string `xml:"copyright,omitempty"`
ITunesSubtitle string `xml:"itunes:subtitle,omitempty"`
ITunesAuthor string `xml:"itunes:author,omitempty"`
ITunesSummary string `xml:"itunes:summary,omitempty"`
Description string `xml:"description,omitempty"`
ITunesOwner struct {
ITunesName string `xml:"itunes:name,omitempty"`
ITunesEmail string `xml:"itunes:email,omitempty"`
} `xml:"itunes:owner,omitempty"`
ITunesImage struct {
Href string `xml:"href,attr,omitempty"`
} `xml:"itunes:image,omitempty"`
ITunesCategory struct {
Text string `xml:"text,attr,omitempty"`
} `xml:"itunes:category,omitempty"`
Items PodcastItems
}
type PodcastItem struct {
XMLName xml.Name `xml:"item"`
Title string `xml:"title,omitempty"`
ITunesAuthor string `xml:"itunes:author,omitempty"`
ITunesSubtitle string `xml:"itunes:subtitle,omitempty"`
ITunesSummary string `xml:"itunes:summary,omitempty"`
ITunesImage struct {
Href string `xml:"href,attr,omitempty"`
} `xml:"itunes:image,omitempty"`
Enclosure struct {
Url string `xml:"url,attr,omitempty"`
Length int `xml:"length,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
} `xml:"enclosure,omitempty"`
Guid string `xml:"guid,omitempty"`
PubDate PubDate `xml:"pubDate,omitempty"`
ITunesDuration string `xml:"itunes:duration,omitempty"`
}
type PodcastItems []PodcastItem
func (p PodcastItems) Len() int {
return len(p)
}
func (p PodcastItems) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p PodcastItems) Less(i, j int) bool {
return p[i].PubDate.Unix() <= p[j].PubDate.Unix()
}
type PubDate struct {
time.Time
}
func (p PubDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeToken(start)
e.EncodeToken(xml.CharData(p.Format(pubDateFormat)))
e.EncodeToken(xml.EndElement{start.Name})
return nil
}
func NewPodcastRss() *PodcastRss {
return &PodcastRss{
XmlnsItunes: "http://www.itunes.com/dtds/podcast-1.0.dtd",
Version: "2.0",
}
}