itunes.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package itunes // import "miniflux.app/v2/internal/reader/itunes"
  4. import "strings"
  5. // Specs: https://help.apple.com/itc/podcasts_connect/#/itcb54353390
  6. type ItunesChannelElement struct {
  7. ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
  8. ItunesBlock string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd block"`
  9. ItunesCategories []ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
  10. ItunesComplete string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd complete"`
  11. ItunesCopyright string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd copyright"`
  12. ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
  13. ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
  14. Keywords string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd keywords"`
  15. ItunesNewFeedURL string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd new-feed-url"`
  16. ItunesOwner ItunesOwnerElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd owner"`
  17. ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
  18. ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
  19. ItunesType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd type"`
  20. }
  21. func (i *ItunesChannelElement) GetItunesCategories() []string {
  22. var categories []string
  23. for _, category := range i.ItunesCategories {
  24. categories = append(categories, category.Text)
  25. if category.SubCategory != nil {
  26. categories = append(categories, category.SubCategory.Text)
  27. }
  28. }
  29. return categories
  30. }
  31. type ItunesItemElement struct {
  32. ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
  33. ItunesEpisode string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episode"`
  34. ItunesEpisodeType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episodeType"`
  35. ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
  36. ItunesDuration string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd duration"`
  37. ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
  38. ItunesSeason string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd season"`
  39. ItunesSubtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
  40. ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
  41. ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
  42. ItunesTranscript string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd transcript"`
  43. }
  44. type ItunesImageElement struct {
  45. Href string `xml:"href,attr"`
  46. }
  47. type ItunesCategoryElement struct {
  48. Text string `xml:"text,attr"`
  49. SubCategory *ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
  50. }
  51. type ItunesOwnerElement struct {
  52. Name string `xml:"name"`
  53. Email string `xml:"email"`
  54. }
  55. func (i *ItunesOwnerElement) String() string {
  56. var name string
  57. switch {
  58. case i.Name != "":
  59. name = i.Name
  60. case i.Email != "":
  61. name = i.Email
  62. }
  63. return strings.TrimSpace(name)
  64. }