-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96d7964
commit 9a84376
Showing
14 changed files
with
157 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:webfeed/domain/itunes/itunes_category.dart'; | ||
import 'package:webfeed/domain/itunes/itunes_episode_type.dart'; | ||
import 'package:webfeed/domain/itunes/itunes_image.dart'; | ||
import 'package:webfeed/domain/itunes/itunes_owner.dart'; | ||
import 'package:webfeed/domain/itunes/itunes_type.dart'; | ||
import 'package:webfeed/util/xml.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
class Itunes { | ||
final String author; | ||
final String summary; | ||
final bool explicit; | ||
final String title; | ||
final String subtitle; | ||
final ItunesOwner owner; | ||
final List<String> keywords; | ||
final ItunesImage image; | ||
final List<ItunesCategory> categories; | ||
final ItunesType type; | ||
final String newFeedUrl; | ||
final bool block; | ||
final bool complete; | ||
final int episode; | ||
final int season; | ||
final Duration duration; | ||
final ItunesEpisodeType episodeType; | ||
|
||
Itunes({ | ||
this.author, | ||
this.summary, | ||
this.explicit, | ||
this.title, | ||
this.subtitle, | ||
this.owner, | ||
this.keywords, | ||
this.image, | ||
this.categories, | ||
this.type, | ||
this.newFeedUrl, | ||
this.block, | ||
this.complete, | ||
this.episode, | ||
this.season, | ||
this.duration, | ||
this.episodeType, | ||
}); | ||
|
||
factory Itunes.parse(XmlElement element) { | ||
if (element == null) { | ||
return null; | ||
} | ||
var episodeStr = findElementOrNull(element, 'itunes:episode')?.text?.trim(); | ||
var seasonStr = findElementOrNull(element, 'itunes:season')?.text?.trim(); | ||
var durationStr = | ||
findElementOrNull(element, 'itunes:duration')?.text?.trim(); | ||
return Itunes( | ||
author: findElementOrNull(element, 'itunes:author')?.text?.trim(), | ||
summary: findElementOrNull(element, 'itunes:summary')?.text?.trim(), | ||
explicit: parseBoolLiteral(element, 'itunes:explicit'), | ||
title: findElementOrNull(element, 'itunes:title')?.text?.trim(), | ||
subtitle: findElementOrNull(element, 'itunes:subtitle')?.text?.trim(), | ||
owner: ItunesOwner.parse(findElementOrNull(element, 'itunes:owner')), | ||
keywords: findElementOrNull(element, 'itunes:keywords') | ||
?.text | ||
?.split(',') | ||
?.map((keyword) => keyword.trim()) | ||
?.toList(), | ||
image: ItunesImage.parse(findElementOrNull(element, 'itunes:image')), | ||
categories: findAllDirectElementsOrNull(element, 'itunes:category') | ||
.map((ele) => ItunesCategory.parse(ele)) | ||
.toList(), | ||
type: newItunesType(findElementOrNull(element, 'itunes:type')), | ||
newFeedUrl: | ||
findElementOrNull(element, 'itunes:new-feed-url')?.text?.trim(), | ||
block: parseBoolLiteral(element, 'itunes:block'), | ||
complete: parseBoolLiteral(element, 'itunes:complete'), | ||
episode: episodeStr == null ? null : int.parse(episodeStr), | ||
season: seasonStr == null ? null : int.parse(seasonStr), | ||
duration: durationStr == null ? null : _parseDuration(durationStr), | ||
episodeType: newItunesEpisodeType( | ||
findElementOrNull(element, 'itunes:episodeType')), | ||
); | ||
} | ||
|
||
static Duration _parseDuration(String s) { | ||
var hours = 0; | ||
var minutes = 0; | ||
var seconds = 0; | ||
var parts = s.split(':'); | ||
if (parts.length > 2) { | ||
hours = int.parse(parts[parts.length - 3]); | ||
} | ||
if (parts.length > 1) { | ||
minutes = int.parse(parts[parts.length - 2]); | ||
} | ||
seconds = int.parse(parts[parts.length - 1]); | ||
return Duration( | ||
hours: hours, | ||
minutes: minutes, | ||
seconds: seconds, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:xml/xml.dart'; | ||
|
||
enum ItunesEpisodeType { full, trailer, bonus, unknown } | ||
|
||
ItunesEpisodeType newItunesEpisodeType(XmlElement element) { | ||
switch (element?.text) { | ||
case 'full': | ||
return ItunesEpisodeType.full; | ||
case 'trailer': | ||
return ItunesEpisodeType.trailer; | ||
case 'bonus': | ||
return ItunesEpisodeType.bonus; | ||
default: | ||
return ItunesEpisodeType.unknown; | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
lib/domain/rss_itunes_image.dart → lib/domain/itunes/itunes_image.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
lib/domain/rss_itunes_owner.dart → lib/domain/itunes/itunes_owner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:xml/xml.dart'; | ||
|
||
enum ItunesType { episodic, serial, unknown } | ||
|
||
ItunesType newItunesType(XmlElement element) { | ||
switch (element?.text) { | ||
case 'episodic': | ||
return ItunesType.episodic; | ||
case 'serial': | ||
return ItunesType.serial; | ||
default: | ||
return ItunesType.unknown; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.