Itunes.parse constructor

Itunes.parse(
  1. XmlElement element,
  2. bool parseHtml
)

Parse constructor for the Itunes class, used when 'parsing' a feed

Implementation

factory Itunes.parse(XmlElement element, bool parseHtml) {
  final episodeStr =
      element.findElements('itunes:episode').firstOrNull?.innerText ?? '';
  final seasonStr =
      element.findElements('itunes:season').firstOrNull?.innerText ?? '';
  final durationStr =
      element.findElements('itunes:duration').firstOrNull?.innerText ?? '';
  return Itunes(
    author: element.findElements('itunes:author').firstOrNull?.innerText,
    summary: element
        .findElements('itunes:summary')
        .firstOrNull
        ?.parseText(parseHtml),
    explicit: parseBoolLiteral(element, 'itunes:explicit'),
    title: element
        .findElements('itunes:title')
        .firstOrNull
        ?.parseText(parseHtml),
    subtitle: element
        .findElements('itunes:subtitle')
        .firstOrNull
        ?.parseText(parseHtml),
    owner: element
        .findElements('itunes:owner')
        .map(ItunesOwner.parse)
        .firstOrNull,
    keywords: element
            .findElements('itunes:keywords')
            .firstOrNull
            ?.innerText
            .split(',')
            .map((keyword) => keyword.trim())
            .toList() ??
        [],
    image: element
        .findElements('itunes:image')
        .map(ItunesImage.parse)
        .firstOrNull,
    categories: element
        .findElements('itunes:category')
        .map(ItunesCategory.parse)
        .toList(),
    type: element.findElements('itunes:type').map(newItunesType).firstOrNull,
    newFeedUrl:
        element.findElements('itunes:new-feed-url').firstOrNull?.innerText,
    block: parseBoolLiteral(element, 'itunes:block'),
    complete: parseBoolLiteral(element, 'itunes:complete'),
    episode: episodeStr.isNotEmpty ? int.tryParse(episodeStr) : null,
    season: seasonStr.isNotEmpty ? int.tryParse(seasonStr) : null,
    duration: durationStr.isNotEmpty ? _parseDuration(durationStr) : null,
    episodeType: element
        .findElements('itunes:episodeType')
        .map(newItunesEpisodeType)
        .firstOrNull,
  );
}