The Webfeed Flutter package for Appeto SDK.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

104 řádky
3.3 KiB

  1. import 'package:webfeed/domain/itunes/itunes_category.dart';
  2. import 'package:webfeed/domain/itunes/itunes_episode_type.dart';
  3. import 'package:webfeed/domain/itunes/itunes_image.dart';
  4. import 'package:webfeed/domain/itunes/itunes_owner.dart';
  5. import 'package:webfeed/domain/itunes/itunes_type.dart';
  6. import 'package:webfeed/util/xml.dart';
  7. import 'package:xml/xml.dart';
  8. class Itunes {
  9. final String author;
  10. final String summary;
  11. final bool explicit;
  12. final String title;
  13. final String subtitle;
  14. final ItunesOwner owner;
  15. final List<String> keywords;
  16. final ItunesImage image;
  17. final List<ItunesCategory> categories;
  18. final ItunesType type;
  19. final String newFeedUrl;
  20. final bool block;
  21. final bool complete;
  22. final int episode;
  23. final int season;
  24. final Duration duration;
  25. final ItunesEpisodeType episodeType;
  26. Itunes({
  27. this.author,
  28. this.summary,
  29. this.explicit,
  30. this.title,
  31. this.subtitle,
  32. this.owner,
  33. this.keywords,
  34. this.image,
  35. this.categories,
  36. this.type,
  37. this.newFeedUrl,
  38. this.block,
  39. this.complete,
  40. this.episode,
  41. this.season,
  42. this.duration,
  43. this.episodeType,
  44. });
  45. factory Itunes.parse(XmlElement element) {
  46. if (element == null) {
  47. return null;
  48. }
  49. var episodeStr = findElementOrNull(element, 'itunes:episode')?.text?.trim();
  50. var seasonStr = findElementOrNull(element, 'itunes:season')?.text?.trim();
  51. var durationStr =
  52. findElementOrNull(element, 'itunes:duration')?.text?.trim();
  53. return Itunes(
  54. author: findElementOrNull(element, 'itunes:author')?.text?.trim(),
  55. summary: findElementOrNull(element, 'itunes:summary')?.text?.trim(),
  56. explicit: parseBoolLiteral(element, 'itunes:explicit'),
  57. title: findElementOrNull(element, 'itunes:title')?.text?.trim(),
  58. subtitle: findElementOrNull(element, 'itunes:subtitle')?.text?.trim(),
  59. owner: ItunesOwner.parse(findElementOrNull(element, 'itunes:owner')),
  60. keywords: findElementOrNull(element, 'itunes:keywords')
  61. ?.text
  62. ?.split(',')
  63. ?.map((keyword) => keyword.trim())
  64. ?.toList(),
  65. image: ItunesImage.parse(findElementOrNull(element, 'itunes:image')),
  66. categories: findAllDirectElementsOrNull(element, 'itunes:category')
  67. .map((ele) => ItunesCategory.parse(ele))
  68. .toList(),
  69. type: newItunesType(findElementOrNull(element, 'itunes:type')),
  70. newFeedUrl:
  71. findElementOrNull(element, 'itunes:new-feed-url')?.text?.trim(),
  72. block: parseBoolLiteral(element, 'itunes:block'),
  73. complete: parseBoolLiteral(element, 'itunes:complete'),
  74. episode: episodeStr == null ? null : int.parse(episodeStr),
  75. season: seasonStr == null ? null : int.parse(seasonStr),
  76. duration: durationStr == null ? null : _parseDuration(durationStr),
  77. episodeType: newItunesEpisodeType(
  78. findElementOrNull(element, 'itunes:episodeType')),
  79. );
  80. }
  81. static Duration _parseDuration(String s) {
  82. var hours = 0;
  83. var minutes = 0;
  84. var seconds = 0;
  85. var parts = s.split(':');
  86. if (parts.length > 2) {
  87. hours = int.parse(parts[parts.length - 3]);
  88. }
  89. if (parts.length > 1) {
  90. minutes = int.parse(parts[parts.length - 2]);
  91. }
  92. seconds = int.parse(parts[parts.length - 1]);
  93. return Duration(
  94. hours: hours,
  95. minutes: minutes,
  96. seconds: seconds,
  97. );
  98. }
  99. }