itunes.go 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 (
  5. "iter"
  6. "strings"
  7. )
  8. // Specs: https://help.apple.com/itc/podcasts_connect/#/itcb54353390
  9. type ItunesChannelElement struct {
  10. ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
  11. ItunesBlock string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd block"`
  12. ItunesCategories []ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
  13. ItunesComplete string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd complete"`
  14. ItunesCopyright string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd copyright"`
  15. ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
  16. ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
  17. Keywords string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd keywords"`
  18. ItunesNewFeedURL string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd new-feed-url"`
  19. ItunesOwner ItunesOwnerElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd owner"`
  20. ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
  21. ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
  22. ItunesType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd type"`
  23. }
  24. func (i *ItunesChannelElement) ItunesCategoriesSeq() iter.Seq[string] {
  25. return func(yield func(string) bool) {
  26. for _, category := range i.ItunesCategories {
  27. for text := range category.All() {
  28. if !yield(text) {
  29. return
  30. }
  31. }
  32. }
  33. }
  34. }
  35. type ItunesItemElement struct {
  36. ItunesAuthor string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd author"`
  37. ItunesEpisode string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episode"`
  38. ItunesEpisodeType string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd episodeType"`
  39. ItunesExplicit string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd explicit"`
  40. ItunesDuration string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd duration"`
  41. ItunesImage ItunesImageElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd image"`
  42. ItunesSeason string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd season"`
  43. ItunesSubtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
  44. ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
  45. ItunesTitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd title"`
  46. ItunesTranscript string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd transcript"`
  47. }
  48. type ItunesImageElement struct {
  49. Href string `xml:"href,attr"`
  50. }
  51. type ItunesCategoryElement struct {
  52. Text string `xml:"text,attr"`
  53. SubCategory *ItunesCategoryElement `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd category"`
  54. }
  55. // All returns iterator for all category names including every nested [ItunesCategoryElement.SubCategory].
  56. func (cat *ItunesCategoryElement) All() iter.Seq[string] {
  57. return func(yield func(string) bool) {
  58. for ; cat != nil; cat = cat.SubCategory {
  59. text := strings.TrimSpace(cat.Text)
  60. if text == "" {
  61. continue
  62. }
  63. if !yield(text) {
  64. return
  65. }
  66. }
  67. }
  68. }
  69. type ItunesOwnerElement struct {
  70. Name string `xml:"name"`
  71. Email string `xml:"email"`
  72. }
  73. func (i *ItunesOwnerElement) String() string {
  74. var name string
  75. switch {
  76. case i.Name != "":
  77. name = i.Name
  78. case i.Email != "":
  79. name = i.Email
  80. }
  81. return strings.TrimSpace(name)
  82. }