Skip to content

Commit

Permalink
add support for alternate enclosure
Browse files Browse the repository at this point in the history
  • Loading branch information
joksas committed Dec 2, 2023
1 parent fd921f4 commit 5f939ad
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 25 deletions.
25 changes: 25 additions & 0 deletions namespace_podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,28 @@ type PodcastPodping struct {
XMLName xml.Name `xml:"podcast:podping"`
UsesPodping *bool `xml:"usesPodping,attr"`
}

// PodcastAlternateEnclosure provides different versions of, or companion media to the main `<enclosure>` file.
// Read more at
// https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#alternate-enclosure
type PodcastAlternateEnclosure struct {
XMLName xml.Name `xml:"podcast:alternateEnclosure"`
Mimetype string `xml:"type,attr"`
Length *int64 `xml:"length,attr"`
Bitrate *float64 `xml:"bitrate,attr"`
Height *int64 `xml:"height,attr"`
LanguageCode *string `xml:"lang,attr"`
Title *string `xml:"title,attr"`
Rel *string `xml:"rel,attr"`
Default *bool `xml:"default,attr"`
Sources []PodcastSource
}

// PodcastSource defines a uri location for a `<podcast:alternateEnclosure>` media file.
// Read more at
// https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#source
type PodcastSource struct {
XMLName xml.Name `xml:"podcast:source"`
URI string `xml:"uri,attr"`
ContentType *string `xml:"contentType,attr"`
}
51 changes: 26 additions & 25 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,32 @@ type Channel struct {

// 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"`
PodcastChapters *PodcastChapters
PodcastEpisode *PodcastEpisode
PodcastISRC *PodcastISRC
PodcastLocation *PodcastLocation
PodcastPersons []PodcastPerson
PodcastSeason *PodcastSeason
PodcastSoundbites []PodcastSoundbite
PodcastTXTs []PodcastTXT
PodcastTranscripts []PodcastTranscript
PodcastValue *PodcastValue
PSCChapters *PSCChapters
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.
Expand Down
16 changes: 16 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ func TestMarshal(t *testing.T) {
Mimetype: "audio/mpeg",
Length: 2048,
},
PodcastAlternateEnclosures: []types.PodcastAlternateEnclosure{
{
Mimetype: "video/mp4",
Length: pointer[int64](7924786),
Bitrate: pointer(511276.52),
Height: pointer[int64](720),
Sources: []types.PodcastSource{
{
URI: "https://example.com/file-720.mp4",
},
},
},
},
GUID: &types.GUID{
GUID: "hello-again",
IsPermaLink: pointer(false),
Expand Down Expand Up @@ -438,6 +451,9 @@ func TestMarshal(t *testing.T) {
<itunes:episodeType>full</itunes:episodeType>
<itunes:explicit>false</itunes:explicit>
<itunes:image href="https://rssblue.com/@bookworm-podcast/hello-again/cover-art.png"></itunes:image>
<podcast:alternateEnclosure type="video/mp4" length="7924786" bitrate="511276.52" height="720">
<podcast:source uri="https://example.com/file-720.mp4"></podcast:source>
</podcast:alternateEnclosure>
<podcast:episode>3</podcast:episode>
<podcast:person role="guest" href="https://www.imdb.com/name/nm0427852888/" img="http://example.com/images/janedoe.jpg">Jane Doe</podcast:person>
<podcast:person role="guest" href="https://www.wikipedia/alicebrown" img="http://example.com/images/alicebrown.jpg">Alice Brown</podcast:person>
Expand Down

0 comments on commit 5f939ad

Please sign in to comment.