-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgopodcast.go
138 lines (115 loc) · 3.9 KB
/
gopodcast.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
132
133
134
135
136
137
138
//go:generate go run generate/main.go
package gopodcast
import (
"encoding/xml"
"io"
)
type feed struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
XMLNSContent string `xml:"xmlns:content,attr"`
XMLNSPodcast string `xml:"xmlns:podcast,attr"`
XMLNSAtom string `xml:"xmlns:atom,attr"`
XMLNSITunes string `xml:"xmlns:itunes,attr"`
Channel *Podcast `xml:"channel"`
}
var emptyFeed = &feed{
Version: "2.0",
XMLNSContent: "http://purl.org/rss/1.0/modules/content/",
XMLNSPodcast: "https://podcastindex.org/namespace/1.0",
XMLNSAtom: "http://www.w3.org/2005/Atom",
XMLNSITunes: "http://www.itunes.com/dtds/podcast-1.0.dtd",
}
type Podcast struct {
// PSP Required
AtomLink AtomLink `xml:"atom:link"`
Title string `xml:"title"`
Description Description `xml:"description"`
Link string `xml:"link"`
Language string `xml:"language"`
ITunesCategory []ITunesCategory `xml:"itunes:category"`
ITunesExplicit Bool `xml:"itunes:explicit"`
ITunesImage ITunesImage `xml:"itunes:image"`
// PSP Recommended
PodcastLocked *YesNo `xml:"podcast:locked,omitempty"`
PodcastGUID string `xml:"podcast:guid,omitempty"`
ITunesAuthor string `xml:"itunes:author,omitempty"`
// PSP Optional
Copyright string `xml:"copyright,omitempty"`
PodcastText *PodcastText `xml:"podcast:txt,omitempty"`
PodcastFunding *PodcastFunding `xml:"podcast:funding,omitempty"`
ITunesType string `xml:"itunes:type,omitempty"`
ITunesComplete *YesNo `xml:"itunes:complete,omitempty"`
// Other fields
// TODO other podcast index namespace fields
// TODO other itunes fields
Items []*Item `xml:"item"`
}
func (p *Podcast) WriteFeedXML(w io.Writer) error {
feed := emptyFeed
feed.Channel = p
_, err := w.Write([]byte(xml.Header))
if err != nil {
return err
}
return xml.NewEncoder(w).Encode(feed)
}
type AtomLink struct {
Href string `xml:"href,attr"`
Rel string `xml:"rel,attr"`
Type string `xml:"type,attr"`
}
type Description struct {
Text string `xml:",cdata"`
}
type ITunesCategory struct {
Text string `xml:"text,attr"`
SubCategory *ITunesCategory `xml:"itunes:category,omitempty"`
}
type ITunesImage struct {
Href string `xml:"href,attr"`
}
type PodcastText struct {
Purpose string `xml:"purpose,attr,omitempty"`
Text string `xml:",chardata"`
}
type PodcastFunding struct {
URL string `xml:"url,attr"`
Text string `xml:",chardata"`
}
type Item struct {
// PSP required
Title string `xml:"title"`
Enclosure Enclosure `xml:"enclosure"`
GUID ItemGUID `xml:"guid"`
// PSP Recommended
Link string `xml:"link,omitempty"`
PubDate *Time `xml:"pubDate,omitempty"`
Description *Description `xml:"description,omitempty"`
ITunesDuration string `xml:"itunes:duration,omitempty"`
ITunesImage *ITunesImage `xml:"itunes:image,omitempty"`
ITunesExplicit *Bool `xml:"itunes:explicit,omitempty"`
PodcastTranscript []PodcastTranscript `xml:"podcast:transcript,omitempty"`
// PSP Optional
ITunesEpisode string `xml:"itunes:episode,omitempty"`
ITunesSeason string `xml:"itunes:season,omitempty"`
ITunesEpisodeType string `xml:"itunes:episodeType,omitempty"`
ITunesBlock *YesNo `xml:"itunes:block,omitempty"`
// Other Fields
// TODO itunes, podcast index namespace
}
type Enclosure struct {
Length int64 `xml:"length,attr"`
Type string `xml:"type,attr"`
URL string `xml:"url,attr"`
}
type ItemGUID struct {
IsPermaLink *Bool `xml:"isPermaLink,attr,omitempty"`
Text string `xml:",chardata"`
}
type PodcastTranscript struct {
URL string `xml:"url,attr"`
Type string `xml:"type,attr"`
Rel string `xml:"rel,attr,omitempty"`
Language string `xml:"language,attr,omitempty"`
}