mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Refactor RSS parser to use default namespace
This change avoid some limitations of the Go XML parser regarding XML namespaces
This commit is contained in:
parent
d3a85b049b
commit
9a637ce95e
6 changed files with 185 additions and 181 deletions
|
@ -15,21 +15,24 @@ 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://developers.google.com/search/reference/podcast/rss-feed
|
||||
// - https://support.google.com/podcast-publishers/answer/9889544
|
||||
type PodcastFeedElement struct {
|
||||
ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>author"`
|
||||
Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>subtitle"`
|
||||
Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>summary"`
|
||||
PodcastOwner PodcastOwner `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>owner"`
|
||||
GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 channel>author"`
|
||||
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 {
|
||||
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"`
|
||||
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
|
||||
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.
|
||||
|
@ -38,6 +41,19 @@ type PodcastOwner struct {
|
|||
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"`
|
||||
|
@ -52,10 +68,8 @@ func (e *PodcastFeedElement) PodcastAuthor() string {
|
|||
author = e.ItunesAuthor
|
||||
case e.GooglePlayAuthor != "":
|
||||
author = e.GooglePlayAuthor
|
||||
case e.PodcastOwner.Name != "":
|
||||
author = e.PodcastOwner.Name
|
||||
case e.PodcastOwner.Email != "":
|
||||
author = e.PodcastOwner.Email
|
||||
case e.PodcastOwner.String() != "":
|
||||
author = e.PodcastOwner.String()
|
||||
}
|
||||
|
||||
return strings.TrimSpace(author)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue