1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Move iTunes and GooglePlay XML definitions to their own packages

This commit is contained in:
Frédéric Guillot 2024-03-11 21:43:27 -07:00
parent 9a637ce95e
commit f8e50947f2
4 changed files with 116 additions and 89 deletions

View file

@ -12,84 +12,6 @@ import (
var ErrInvalidDurationFormat = errors.New("rss: invalid duration format")
// PodcastFeedElement represents iTunes and GooglePlay feed XML elements.
// Specs:
// - https://github.com/simplepie/simplepie-ng/wiki/Spec:-iTunes-Podcast-RSS
// - https://support.google.com/podcast-publishers/answer/9889544
type PodcastFeedElement struct {
ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
PodcastOwner PodcastOwner `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd owner"`
GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 author"`
}
// PodcastEntryElement represents iTunes and GooglePlay entry XML elements.
type PodcastEntryElement struct {
ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
Duration string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd duration"`
PodcastOwner PodcastOwner `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd owner"`
GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 author"`
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
}
// PodcastOwner represents contact information for the podcast owner.
type PodcastOwner struct {
Name string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd name"`
Email string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd email"`
}
func (p *PodcastOwner) String() string {
var name string
switch {
case p.Name != "":
name = p.Name
case p.Email != "":
name = p.Email
}
return strings.TrimSpace(name)
}
// Image represents podcast artwork.
type Image struct {
URL string `xml:"href,attr"`
}
// PodcastAuthor returns the author of the podcast.
func (e *PodcastFeedElement) PodcastAuthor() string {
author := ""
switch {
case e.ItunesAuthor != "":
author = e.ItunesAuthor
case e.GooglePlayAuthor != "":
author = e.GooglePlayAuthor
case e.PodcastOwner.String() != "":
author = e.PodcastOwner.String()
}
return strings.TrimSpace(author)
}
// PodcastDescription returns the description of the podcast.
func (e *PodcastEntryElement) PodcastDescription() string {
description := ""
switch {
case e.GooglePlayDescription != "":
description = e.GooglePlayDescription
case e.Summary != "":
description = e.Summary
case e.Subtitle != "":
description = e.Subtitle
}
return strings.TrimSpace(description)
}
// normalizeDuration returns the duration tag value as a number of minutes
func normalizeDuration(rawDuration string) (int, error) {
var sumSeconds int