-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
131 lines (120 loc) · 4.69 KB
/
types.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package types
import (
"encoding/xml"
"fmt"
"time"
)
// RSS is the root element of podcast's RSS feed, denoting the namespaces and
// the version of the protocol.
type RSS struct {
XMLName xml.Name `xml:"rss"`
Version RSSVersion `xml:",attr"`
NamespaceAtom NSBool `xml:",attr"`
NamespaceContent NSBool `xml:",attr"`
NamespaceGooglePlay NSBool `xml:",attr"`
NamespaceITunes NSBool `xml:",attr"`
NamespacePodcast NSBool `xml:",attr"`
NamespacePSC NSBool `xml:",attr"`
Channel Channel
}
type NSBool bool
func (isPresent *NSBool) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
if isPresent == nil {
return xml.Attr{}, nil
}
if !*isPresent {
return xml.Attr{}, nil
}
switch name.Local {
case "NamespaceAtom":
return xml.Attr{Name: xml.Name{Local: "xmlns:atom"}, Value: NamespaceAtom}, nil
case "NamespaceContent":
return xml.Attr{Name: xml.Name{Local: "xmlns:content"}, Value: NamespaceContent}, nil
case "NamespaceGooglePlay":
return xml.Attr{Name: xml.Name{Local: "xmlns:googleplay"}, Value: NamespaceGooglePlay}, nil
case "NamespaceITunes":
return xml.Attr{Name: xml.Name{Local: "xmlns:itunes"}, Value: NamespaceITunes}, nil
case "NamespacePodcast":
return xml.Attr{Name: xml.Name{Local: "xmlns:podcast"}, Value: NamespacePodcast}, nil
case "NamespacePSC":
return xml.Attr{Name: xml.Name{Local: "xmlns:psc"}, Value: NamespacePSC}, nil
default:
return xml.Attr{}, fmt.Errorf("unrecognised attribute name \"%s\"", name.Local)
}
}
// Channel represents the podcast's feed.
type Channel struct {
XMLName xml.Name `xml:"channel"`
Copyright *string `xml:"copyright"`
Description *Description `xml:"description"`
Generator *string `xml:"generator"`
Language *string `xml:"language"`
LastBuildDate *Date `xml:"lastBuildDate"`
Link *string `xml:"link"`
Title *string `xml:"title"`
AtomLink *AtomLink `xml:"atom:link"`
ContentEncoded *ContentEncoded
ITunesAuthor *string `xml:"itunes:author"`
ITunesCategories []ITunesCategory
ITunesExplicit *bool `xml:"itunes:explicit"`
ITunesImage *ITunesImage
ITunesNewFeedURL *string `xml:"itunes:new-feed-url"`
ITunesOwner *ITunesOwner
ITunesType *string `xml:"itunes:type"`
PodcastFundings []PodcastFunding
PodcastGUID *PodcastGUID `xml:"podcast:guid"`
PodcastLocation *PodcastLocation
PodcastLocked *PodcastLocked
PodcastMedium *PodcastMedium `xml:"podcast:medium"`
PodcastPersons []PodcastPerson
PodcastPodping *PodcastPodping
PodcastPublisher *PodcastPublisher
PodcastRemoteItems []PodcastRemoteItem
PodcastSingleItem *PodcastSingleItem
PodcastTXTs []PodcastTXT
PodcastTrailers []PodcastTrailer
PodcastValue *PodcastValue
PodcastLiveItems []PodcastLiveItem
Items []Item
}
// Item represents episode of a podcast.
type Item struct {
XMLName xml.Name `xml:"item"`
Description *Description `xml:"description"`
Enclosure *Enclosure
GUID *GUID
Link *string `xml:"link"`
PubDate *Date `xml:"pubDate"`
Title *string `xml:"title"`
ContentEncoded *ContentEncoded
ITunesDuration *ITunesDuration `xml:"itunes:duration"`
ITunesEpisodeNumber *int64 `xml:"itunes:episode"`
ITunesEpisodeType *string `xml:"itunes:episodeType"`
ITunesExplicit *bool `xml:"itunes:explicit"`
ITunesImage *ITunesImage
ITunesSeasonNumber *int64 `xml:"itunes:season"`
PodcastAlternateEnclosures []PodcastAlternateEnclosure
PodcastChapters *PodcastChapters
PodcastEpisode *PodcastEpisode
PodcastISRC *PodcastISRC
PodcastLocation *PodcastLocation
PodcastPersons []PodcastPerson
PodcastSeason *PodcastSeason
PodcastSoundbites []PodcastSoundbite
PodcastTXTs []PodcastTXT
PodcastTranscripts []PodcastTranscript
PodcastValue *PodcastValue
PSCChapters *PSCChapters
}
// Date is used to format the publish date of an episode.
type Date time.Time
func (pd Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
t := time.Time(pd)
v := t.Format("Mon, 02 Jan 2006 15:04:05 GMT")
return e.EncodeElement(v, start)
}
func (pd Date) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
t := time.Time(pd)
v := t.Format("Mon, 02 Jan 2006 15:04:05 GMT")
return xml.Attr{Name: name, Value: v}, nil
}