podcast.go 2.4 KB

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