podcast.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package rss // import "miniflux.app/reader/rss"
  5. import "strings"
  6. // PodcastFeedElement represents iTunes and GooglePlay feed XML elements.
  7. // Specs:
  8. // - https://github.com/simplepie/simplepie-ng/wiki/Spec:-iTunes-Podcast-RSS
  9. // - https://developers.google.com/search/reference/podcast/rss-feed
  10. type PodcastFeedElement struct {
  11. ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>author"`
  12. Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>subtitle"`
  13. Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>summary"`
  14. PodcastOwner PodcastOwner `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd channel>owner"`
  15. GooglePlayAuthor string `xml:"http://www.google.com/schemas/play-podcasts/1.0 channel>author"`
  16. }
  17. // PodcastEntryElement represents iTunes and GooglePlay entry XML elements.
  18. type PodcastEntryElement struct {
  19. Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
  20. Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
  21. GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
  22. }
  23. // PodcastOwner represents contact information for the podcast owner.
  24. type PodcastOwner struct {
  25. Name string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd name"`
  26. Email string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd email"`
  27. }
  28. // Image represents podcast artwork.
  29. type Image struct {
  30. URL string `xml:"href,attr"`
  31. }
  32. // PodcastAuthor returns the author of the podcast.
  33. func (e *PodcastFeedElement) PodcastAuthor() string {
  34. author := ""
  35. switch {
  36. case e.ItunesAuthor != "":
  37. author = e.ItunesAuthor
  38. case e.GooglePlayAuthor != "":
  39. author = e.GooglePlayAuthor
  40. case e.PodcastOwner.Name != "":
  41. author = e.PodcastOwner.Name
  42. case e.PodcastOwner.Email != "":
  43. author = e.PodcastOwner.Email
  44. }
  45. return strings.TrimSpace(author)
  46. }
  47. // PodcastDescription returns the description of the podcast.
  48. func (e *PodcastEntryElement) PodcastDescription() string {
  49. description := ""
  50. switch {
  51. case e.GooglePlayDescription != "":
  52. description = e.GooglePlayDescription
  53. case e.Summary != "":
  54. description = e.Summary
  55. case e.Subtitle != "":
  56. description = e.Subtitle
  57. }
  58. return strings.TrimSpace(description)
  59. }