The Webfeed Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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