From c545acb789c0abbd7bf84686aeb73be2e961231b Mon Sep 17 00:00:00 2001 From: Wito Chandra Date: Thu, 13 Sep 2018 04:14:20 +0700 Subject: [PATCH] support media namespaces --- lib/domain/atom_feed.dart | 37 ++++---- lib/domain/atom_item.dart | 82 ++++++++++-------- lib/domain/media/community.dart | 34 ++++++++ lib/domain/media/copyright.dart | 21 +++++ lib/domain/media/description.dart | 21 +++++ lib/domain/media/embed.dart | 30 +++++++ lib/domain/media/hash.dart | 21 +++++ lib/domain/media/license.dart | 24 ++++++ lib/domain/media/media.dart | 126 ++++++++++++++++++++++++++++ lib/domain/media/param.dart | 21 +++++ lib/domain/media/peer_link.dart | 24 ++++++ lib/domain/media/player.dart | 27 ++++++ lib/domain/media/price.dart | 24 ++++++ lib/domain/media/restriction.dart | 24 ++++++ lib/domain/media/rights.dart | 18 ++++ lib/domain/media/scene.dart | 28 +++++++ lib/domain/media/star_rating.dart | 24 ++++++ lib/domain/media/statistics.dart | 18 ++++ lib/domain/media/status.dart | 21 +++++ lib/domain/media/tags.dart | 21 +++++ lib/domain/media/text.dart | 30 +++++++ lib/domain/media/thumbnail.dart | 24 ++++++ lib/domain/media/title.dart | 21 +++++ lib/domain/rss_feed.dart | 72 +++++++++------- test/atom_test.dart | 135 +++++++++++++++++++++++++++++- test/rss_test.dart | 95 ++++++++++++++++++++- test/xml/Atom-Media.xml | 118 ++++++++++++++++++++++++++ test/xml/RSS-Media.xml | 54 +++++++----- 28 files changed, 1087 insertions(+), 108 deletions(-) create mode 100644 lib/domain/media/community.dart create mode 100644 lib/domain/media/copyright.dart create mode 100644 lib/domain/media/description.dart create mode 100644 lib/domain/media/embed.dart create mode 100644 lib/domain/media/hash.dart create mode 100644 lib/domain/media/license.dart create mode 100644 lib/domain/media/param.dart create mode 100644 lib/domain/media/peer_link.dart create mode 100644 lib/domain/media/player.dart create mode 100644 lib/domain/media/price.dart create mode 100644 lib/domain/media/restriction.dart create mode 100644 lib/domain/media/rights.dart create mode 100644 lib/domain/media/scene.dart create mode 100644 lib/domain/media/star_rating.dart create mode 100644 lib/domain/media/statistics.dart create mode 100644 lib/domain/media/status.dart create mode 100644 lib/domain/media/tags.dart create mode 100644 lib/domain/media/text.dart create mode 100644 lib/domain/media/thumbnail.dart create mode 100644 lib/domain/media/title.dart create mode 100644 test/xml/Atom-Media.xml diff --git a/lib/domain/atom_feed.dart b/lib/domain/atom_feed.dart index b1391b8..2a0dffa 100644 --- a/lib/domain/atom_feed.dart +++ b/lib/domain/atom_feed.dart @@ -22,16 +22,21 @@ class AtomFeed { String rights; String subtitle; - AtomFeed(this.id, this.title, this.updated, this.items, - {this.links, - this.authors, - this.contributors, - this.categories, - this.generator, - this.icon, - this.logo, - this.rights, - this.subtitle}); + AtomFeed({ + this.id, + this.title, + this.updated, + this.items, + this.links, + this.authors, + this.contributors, + this.categories, + this.generator, + this.icon, + this.logo, + this.rights, + this.subtitle, + }); factory AtomFeed.parse(String xmlString) { var document = parse(xmlString); @@ -41,9 +46,9 @@ class AtomFeed { } on StateError { throw new ArgumentError("feed not found"); } - var id = xmlGetString(feedElement, "id"); - var title = xmlGetString(feedElement, "title"); - var updated = xmlGetString(feedElement, "updated"); + var id = xmlGetString(feedElement, "id", strict: false); + var title = xmlGetString(feedElement, "title", strict: false); + var updated = xmlGetString(feedElement, "updated", strict: false); var items = feedElement.findElements("entry").map((element) { return new AtomItem.parse(element); @@ -76,7 +81,11 @@ class AtomFeed { var rights = xmlGetString(feedElement, "rights", strict: false); var subtitle = xmlGetString(feedElement, "subtitle", strict: false); - return new AtomFeed(id, title, updated, items, + return new AtomFeed( + id: id, + title: title, + updated: updated, + items: items, links: links, authors: authors, contributors: contributors, diff --git a/lib/domain/atom_item.dart b/lib/domain/atom_item.dart index e0b58b3..11c74c5 100644 --- a/lib/domain/atom_item.dart +++ b/lib/domain/atom_item.dart @@ -2,39 +2,46 @@ import 'package:webfeed/domain/atom_category.dart'; import 'package:webfeed/domain/atom_link.dart'; import 'package:webfeed/domain/atom_person.dart'; import 'package:webfeed/domain/atom_source.dart'; +import 'package:webfeed/domain/media/media.dart'; import 'package:webfeed/util/helpers.dart'; import 'package:xml/xml.dart'; class AtomItem { - String id; - String title; - String updated; + final String id; + final String title; + final String updated; - List authors; - List links; - List categories; - List contributors; - AtomSource source; - String published; - String content; - String summary; - String rights; + final List authors; + final List links; + final List categories; + final List contributors; + final AtomSource source; + final String published; + final String content; + final String summary; + final String rights; + final Media media; - AtomItem(this.id, this.title, this.updated, - {this.authors, - this.links, - this.categories, - this.contributors, - this.source, - this.published, - this.content, - this.summary, - this.rights}); + AtomItem({ + this.id, + this.title, + this.updated, + this.authors, + this.links, + this.categories, + this.contributors, + this.source, + this.published, + this.content, + this.summary, + this.rights, + this.media, + }); factory AtomItem.parse(XmlElement element) { - var id = xmlGetString(element, "id"); - var title = xmlGetString(element, "title"); - var updated = xmlGetString(element, "updated"); + var id = xmlGetString(element, "id", strict: false); + var title = xmlGetString(element, "title", strict: false); + var updated = xmlGetString(element, "updated", strict: false); var authors = element.findElements("author").map((element) { return new AtomPerson.parse(element); @@ -62,16 +69,21 @@ class AtomItem { var summary = xmlGetString(element, "summary", strict: false); var rights = xmlGetString(element, "rights", strict: false); - return new AtomItem(id, title, updated, - authors: authors, - links: links, - categories: categories, - contributors: contributors, - source: source, - published: published, - content: content, - summary: summary, - rights: rights); + return new AtomItem( + id: id, + title: title, + updated: updated, + authors: authors, + links: links, + categories: categories, + contributors: contributors, + source: source, + published: published, + content: content, + summary: summary, + rights: rights, + media: new Media.parse(element), + ); } @override diff --git a/lib/domain/media/community.dart b/lib/domain/media/community.dart new file mode 100644 index 0000000..b301050 --- /dev/null +++ b/lib/domain/media/community.dart @@ -0,0 +1,34 @@ +import 'package:webfeed/domain/media/star_rating.dart'; +import 'package:webfeed/domain/media/statistics.dart'; +import 'package:webfeed/domain/media/tags.dart'; +import 'package:webfeed/util/helpers.dart'; +import 'package:xml/xml.dart'; + +class Community { + final StarRating starRating; + final Statistics statistics; + final Tags tags; + + Community({ + this.starRating, + this.statistics, + this.tags, + }); + + factory Community.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Community( + starRating: new StarRating.parse( + findElementOrNull(element, "media:starRating"), + ), + statistics: new Statistics.parse( + findElementOrNull(element, "media:statistics"), + ), + tags: new Tags.parse( + findElementOrNull(element, "media:tags"), + ), + ); + } +} diff --git a/lib/domain/media/copyright.dart b/lib/domain/media/copyright.dart new file mode 100644 index 0000000..1cad059 --- /dev/null +++ b/lib/domain/media/copyright.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Copyright { + final String url; + final String value; + + Copyright({ + this.url, + this.value, + }); + + factory Copyright.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Copyright( + url: element.getAttribute("url"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/description.dart b/lib/domain/media/description.dart new file mode 100644 index 0000000..ba6f0e0 --- /dev/null +++ b/lib/domain/media/description.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Description { + final String type; + final String value; + + Description({ + this.type, + this.value, + }); + + factory Description.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Description( + type: element.getAttribute("type"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/embed.dart b/lib/domain/media/embed.dart new file mode 100644 index 0000000..1cca476 --- /dev/null +++ b/lib/domain/media/embed.dart @@ -0,0 +1,30 @@ +import 'package:webfeed/domain/media/param.dart'; +import 'package:xml/xml.dart'; + +class Embed { + final String url; + final int width; + final int height; + final List params; + + Embed({ + this.url, + this.width, + this.height, + this.params, + }); + + factory Embed.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Embed( + url: element.getAttribute("url"), + width: int.tryParse(element.getAttribute("width") ?? "0"), + height: int.tryParse(element.getAttribute("height") ?? "0"), + params: element.findElements("media:param").map((e) { + return new Param.parse(e); + }).toList(), + ); + } +} diff --git a/lib/domain/media/hash.dart b/lib/domain/media/hash.dart new file mode 100644 index 0000000..72ce859 --- /dev/null +++ b/lib/domain/media/hash.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Hash { + final String algo; + final String value; + + Hash({ + this.algo, + this.value, + }); + + factory Hash.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Hash( + algo: element.getAttribute("algo"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/license.dart b/lib/domain/media/license.dart new file mode 100644 index 0000000..c52a8c6 --- /dev/null +++ b/lib/domain/media/license.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class License { + final String type; + final String href; + final String value; + + License({ + this.type, + this.href, + this.value, + }); + + factory License.parse(XmlElement element) { + if (element == null) { + return null; + } + return new License( + type: element.getAttribute("type"), + href: element.getAttribute("href"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/media.dart b/lib/domain/media/media.dart index 2815ec0..2f685c1 100644 --- a/lib/domain/media/media.dart +++ b/lib/domain/media/media.dart @@ -1,8 +1,24 @@ import 'package:webfeed/domain/media/category.dart'; +import 'package:webfeed/domain/media/community.dart'; import 'package:webfeed/domain/media/content.dart'; +import 'package:webfeed/domain/media/copyright.dart'; import 'package:webfeed/domain/media/credit.dart'; +import 'package:webfeed/domain/media/description.dart'; +import 'package:webfeed/domain/media/embed.dart'; import 'package:webfeed/domain/media/group.dart'; +import 'package:webfeed/domain/media/hash.dart'; +import 'package:webfeed/domain/media/license.dart'; +import 'package:webfeed/domain/media/peer_link.dart'; +import 'package:webfeed/domain/media/player.dart'; +import 'package:webfeed/domain/media/price.dart'; import 'package:webfeed/domain/media/rating.dart'; +import 'package:webfeed/domain/media/restriction.dart'; +import 'package:webfeed/domain/media/rights.dart'; +import 'package:webfeed/domain/media/scene.dart'; +import 'package:webfeed/domain/media/status.dart'; +import 'package:webfeed/domain/media/text.dart'; +import 'package:webfeed/domain/media/thumbnail.dart'; +import 'package:webfeed/domain/media/title.dart'; import 'package:webfeed/util/helpers.dart'; import 'package:xml/xml.dart'; @@ -12,6 +28,26 @@ class Media { final List credits; final Category category; final Rating rating; + final Title title; + final Description description; + final String keywords; + final List thumbnails; + final Hash hash; + final Player player; + final Copyright copyright; + final Text text; + final Restriction restriction; + final Community community; + final List comments; + final Embed embed; + final List responses; + final List backLinks; + final Status status; + final List prices; + final License license; + final PeerLink peerLink; + final Rights rights; + final List scenes; Media({ this.group, @@ -19,6 +55,26 @@ class Media { this.credits, this.category, this.rating, + this.title, + this.description, + this.keywords, + this.thumbnails, + this.hash, + this.player, + this.copyright, + this.text, + this.restriction, + this.community, + this.comments, + this.embed, + this.responses, + this.backLinks, + this.status, + this.prices, + this.license, + this.peerLink, + this.rights, + this.scenes, }); factory Media.parse(XmlElement element) { @@ -38,6 +94,76 @@ class Media { rating: new Rating.parse( findElementOrNull(element, "media:rating"), ), + title: new Title.parse( + findElementOrNull(element, "media:title"), + ), + description: new Description.parse( + findElementOrNull(element, "media:description"), + ), + keywords: findElementOrNull(element, "media:keywords")?.text, + thumbnails: element.findElements("media:thumbnail").map((e) { + return new Thumbnail.parse(e); + }).toList(), + hash: new Hash.parse( + findElementOrNull(element, "media:hash"), + ), + player: new Player.parse( + findElementOrNull(element, "media:player"), + ), + copyright: new Copyright.parse( + findElementOrNull(element, "media:copyright"), + ), + text: new Text.parse( + findElementOrNull(element, "media:text"), + ), + restriction: new Restriction.parse( + findElementOrNull(element, "media:restriction"), + ), + community: new Community.parse( + findElementOrNull(element, "media:community"), + ), + comments: findElementOrNull(element, "media:comments") + ?.findElements("media:comment") + ?.map((e) { + return e.text; + })?.toList() ?? + [], + embed: new Embed.parse( + findElementOrNull(element, "media:embed"), + ), + responses: findElementOrNull(element, "media:responses") + ?.findElements("media:response") + ?.map((e) { + return e.text; + })?.toList() ?? + [], + backLinks: findElementOrNull(element, "media:backLinks") + ?.findElements("media:backLink") + ?.map((e) { + return e.text; + })?.toList() ?? + [], + status: new Status.parse( + findElementOrNull(element, "media:status"), + ), + prices: element.findElements("media:price").map((e) { + return new Price.parse(e); + }).toList(), + license: new License.parse( + findElementOrNull(element, "media:license"), + ), + peerLink: new PeerLink.parse( + findElementOrNull(element, "media:peerLink"), + ), + rights: new Rights.parse( + findElementOrNull(element, "media:rights"), + ), + scenes: findElementOrNull(element, "media:scenes") + ?.findElements("media:scene") + ?.map((e) { + return new Scene.parse(e); + })?.toList() ?? + [], ); } } diff --git a/lib/domain/media/param.dart b/lib/domain/media/param.dart new file mode 100644 index 0000000..175e6b8 --- /dev/null +++ b/lib/domain/media/param.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Param { + final String name; + final String value; + + Param({ + this.name, + this.value, + }); + + factory Param.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Param( + name: element.getAttribute("name"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/peer_link.dart b/lib/domain/media/peer_link.dart new file mode 100644 index 0000000..6c51a17 --- /dev/null +++ b/lib/domain/media/peer_link.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class PeerLink { + final String type; + final String href; + final String value; + + PeerLink({ + this.type, + this.href, + this.value, + }); + + factory PeerLink.parse(XmlElement element) { + if (element == null) { + return null; + } + return new PeerLink( + type: element.getAttribute("type"), + href: element.getAttribute("href"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/player.dart b/lib/domain/media/player.dart new file mode 100644 index 0000000..23d5e7a --- /dev/null +++ b/lib/domain/media/player.dart @@ -0,0 +1,27 @@ +import 'package:xml/xml.dart'; + +class Player { + final String url; + final int width; + final int height; + final String value; + + Player({ + this.url, + this.width, + this.height, + this.value, + }); + + factory Player.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Player( + url: element.getAttribute("url"), + width: int.tryParse(element.getAttribute("width") ?? "0"), + height: int.tryParse(element.getAttribute("height") ?? "0"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/price.dart b/lib/domain/media/price.dart new file mode 100644 index 0000000..6da075b --- /dev/null +++ b/lib/domain/media/price.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class Price { + final double price; + final String type; + final String info; + final String currency; + + Price({ + this.price, + this.type, + this.info, + this.currency, + }); + + factory Price.parse(XmlElement element) { + return new Price( + price: double.tryParse(element.getAttribute("price") ?? "0"), + type: element.getAttribute("type"), + info: element.getAttribute("info"), + currency: element.getAttribute("currency"), + ); + } +} diff --git a/lib/domain/media/restriction.dart b/lib/domain/media/restriction.dart new file mode 100644 index 0000000..4aa56bd --- /dev/null +++ b/lib/domain/media/restriction.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class Restriction { + final String relationship; + final String type; + final String value; + + Restriction({ + this.relationship, + this.type, + this.value, + }); + + factory Restriction.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Restriction( + relationship: element.getAttribute("relationship"), + type: element.getAttribute("type"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/rights.dart b/lib/domain/media/rights.dart new file mode 100644 index 0000000..eb00d4d --- /dev/null +++ b/lib/domain/media/rights.dart @@ -0,0 +1,18 @@ +import 'package:xml/xml.dart'; + +class Rights { + final String status; + + Rights({ + this.status, + }); + + factory Rights.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Rights( + status: element.getAttribute("status"), + ); + } +} diff --git a/lib/domain/media/scene.dart b/lib/domain/media/scene.dart new file mode 100644 index 0000000..9eab8d0 --- /dev/null +++ b/lib/domain/media/scene.dart @@ -0,0 +1,28 @@ +import 'package:webfeed/util/helpers.dart'; +import 'package:xml/xml.dart'; + +class Scene { + final String title; + final String description; + final String startTime; + final String endTime; + + Scene({ + this.title, + this.description, + this.startTime, + this.endTime, + }); + + factory Scene.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Scene( + title: findElementOrNull(element, "sceneTitle")?.text, + description: findElementOrNull(element, "sceneDescription")?.text, + startTime: findElementOrNull(element, "sceneStartTime")?.text, + endTime: findElementOrNull(element, "sceneEndTime")?.text, + ); + } +} diff --git a/lib/domain/media/star_rating.dart b/lib/domain/media/star_rating.dart new file mode 100644 index 0000000..ae4c400 --- /dev/null +++ b/lib/domain/media/star_rating.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class StarRating { + final double average; + final int count; + final int min; + final int max; + + StarRating({ + this.average, + this.count, + this.min, + this.max, + }); + + factory StarRating.parse(XmlElement element) { + return new StarRating( + average: double.tryParse(element.getAttribute("average") ?? "0"), + count: int.tryParse(element.getAttribute("count") ?? "0"), + min: int.tryParse(element.getAttribute("min") ?? "0"), + max: int.tryParse(element.getAttribute("max") ?? "0"), + ); + } +} diff --git a/lib/domain/media/statistics.dart b/lib/domain/media/statistics.dart new file mode 100644 index 0000000..d93461f --- /dev/null +++ b/lib/domain/media/statistics.dart @@ -0,0 +1,18 @@ +import 'package:xml/xml.dart'; + +class Statistics { + final int views; + final int favorites; + + Statistics({ + this.views, + this.favorites, + }); + + factory Statistics.parse(XmlElement element) { + return new Statistics( + views: int.tryParse(element.getAttribute("views") ?? "0"), + favorites: int.tryParse(element.getAttribute("favorites") ?? "0"), + ); + } +} diff --git a/lib/domain/media/status.dart b/lib/domain/media/status.dart new file mode 100644 index 0000000..3071a09 --- /dev/null +++ b/lib/domain/media/status.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Status { + final String state; + final String reason; + + Status({ + this.state, + this.reason, + }); + + factory Status.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Status( + state: element.getAttribute("state"), + reason: element.getAttribute("reason"), + ); + } +} diff --git a/lib/domain/media/tags.dart b/lib/domain/media/tags.dart new file mode 100644 index 0000000..c7001a7 --- /dev/null +++ b/lib/domain/media/tags.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Tags { + final String tags; + final int weight; + + Tags({ + this.tags, + this.weight, + }); + + factory Tags.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Tags( + tags: element.text, + weight: int.tryParse(element.getAttribute("weight") ?? "1"), + ); + } +} diff --git a/lib/domain/media/text.dart b/lib/domain/media/text.dart new file mode 100644 index 0000000..1ff886b --- /dev/null +++ b/lib/domain/media/text.dart @@ -0,0 +1,30 @@ +import 'package:xml/xml.dart'; + +class Text { + final String type; + final String lang; + final String start; + final String end; + final String value; + + Text({ + this.type, + this.lang, + this.start, + this.end, + this.value, + }); + + factory Text.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Text( + type: element.getAttribute("type"), + lang: element.getAttribute("lang"), + start: element.getAttribute("start"), + end: element.getAttribute("end"), + value: element.text, + ); + } +} diff --git a/lib/domain/media/thumbnail.dart b/lib/domain/media/thumbnail.dart new file mode 100644 index 0000000..8adce3b --- /dev/null +++ b/lib/domain/media/thumbnail.dart @@ -0,0 +1,24 @@ +import 'package:xml/xml.dart'; + +class Thumbnail { + final String url; + final String width; + final String height; + final String time; + + Thumbnail({ + this.url, + this.width, + this.height, + this.time, + }); + + factory Thumbnail.parse(XmlElement element) { + return new Thumbnail( + url: element.getAttribute("url"), + width: element.getAttribute("width"), + height: element.getAttribute("height"), + time: element.getAttribute("time"), + ); + } +} diff --git a/lib/domain/media/title.dart b/lib/domain/media/title.dart new file mode 100644 index 0000000..8c875a6 --- /dev/null +++ b/lib/domain/media/title.dart @@ -0,0 +1,21 @@ +import 'package:xml/xml.dart'; + +class Title { + final String type; + final String value; + + Title({ + this.type, + this.value, + }); + + factory Title.parse(XmlElement element) { + if (element == null) { + return null; + } + return new Title( + type: element.getAttribute("type"), + value: element.text, + ); + } +} diff --git a/lib/domain/rss_feed.dart b/lib/domain/rss_feed.dart index cd69e56..65445ee 100644 --- a/lib/domain/rss_feed.dart +++ b/lib/domain/rss_feed.dart @@ -28,21 +28,26 @@ class RssFeed { final String webMaster; final int ttl; - RssFeed(this.title, this.description, this.link, this.items, - {this.image, - this.cloud, - this.categories, - this.skipDays, - this.skipHours, - this.lastBuildDate, - this.language, - this.generator, - this.copyright, - this.docs, - this.managingEditor, - this.rating, - this.webMaster, - this.ttl}); + RssFeed({ + this.title, + this.description, + this.link, + this.items, + this.image, + this.cloud, + this.categories, + this.skipDays, + this.skipHours, + this.lastBuildDate, + this.language, + this.generator, + this.copyright, + this.docs, + this.managingEditor, + this.rating, + this.webMaster, + this.ttl, + }); factory RssFeed.parse(String xmlString) { var document = parse(xmlString); @@ -52,7 +57,7 @@ class RssFeed { } on StateError { throw new ArgumentError("channel not found"); } - var title = xmlGetString(channelElement, "title"); + var title = xmlGetString(channelElement, "title", strict: false); var description = xmlGetString(channelElement, "description", strict: false); var link = xmlGetString(channelElement, "link", strict: false); @@ -106,21 +111,26 @@ class RssFeed { var webMaster = xmlGetString(channelElement, "webMaster", strict: false); var ttl = xmlGetInt(channelElement, "ttl", strict: false); - return new RssFeed(title, description, link, feeds, - image: image, - cloud: cloud, - categories: categories, - skipDays: skipDays, - skipHours: skipHours, - lastBuildDate: lastBuildDate, - language: language, - generator: generator, - copyright: copyright, - docs: docs, - managingEditor: managingEditor, - rating: rating, - webMaster: webMaster, - ttl: ttl); + return new RssFeed( + title: title, + description: description, + link: link, + items: feeds, + image: image, + cloud: cloud, + categories: categories, + skipDays: skipDays, + skipHours: skipHours, + lastBuildDate: lastBuildDate, + language: language, + generator: generator, + copyright: copyright, + docs: docs, + managingEditor: managingEditor, + rating: rating, + webMaster: webMaster, + ttl: ttl, + ); } @override diff --git a/test/atom_test.dart b/test/atom_test.dart index 421d50d..d397a9a 100644 --- a/test/atom_test.dart +++ b/test/atom_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; import 'package:webfeed/webfeed.dart'; void main() { - test("parsing Invalid.xml", () { + test("parse Invalid.xml", () { var xmlString = new File("test/xml/Invalid.xml").readAsStringSync(); try { @@ -14,7 +14,7 @@ void main() { } on ArgumentError {} }); - test("parsing Atom.xml", () { + test("parse Atom.xml", () { var xmlString = new File("test/xml/Atom.xml").readAsStringSync(); var feed = new AtomFeed.parse(xmlString); @@ -88,4 +88,135 @@ void main() { expect(item.content, "This is content 1"); expect(item.rights, "This is rights 1"); }); + test("parse Atom-Media.xml", (){ + var xmlString = new File("test/xml/Atom-Media.xml").readAsStringSync(); + + var feed = new AtomFeed.parse(xmlString); + expect(feed.id, "foo-bar-id"); + expect(feed.title, "Foo bar news"); + expect(feed.updated, "2018-04-06T13:02:46Z"); + + expect(feed.items.length, 1); + + var item = feed.items.first; + expect(item.media.group.contents.length, 5); + expect(item.media.group.credits.length, 2); + expect(item.media.group.category.value, "music/artist name/album/song"); + expect(item.media.group.rating.value, "nonadult"); + + expect(item.media.contents.length, 2); + var mediaContent = item.media.contents.first; + expect(mediaContent.url, "http://www.foo.com/video.mov"); + expect(mediaContent.type, "video/quicktime"); + expect(mediaContent.fileSize, 2000); + expect(mediaContent.medium, "video"); + expect(mediaContent.isDefault, true); + expect(mediaContent.expression, "full"); + expect(mediaContent.bitrate, 128); + expect(mediaContent.framerate, 25); + expect(mediaContent.samplingrate, 44.1); + expect(mediaContent.channels, 2); + + expect(item.media.credits.length, 2); + var mediaCredit = item.media.credits.first; + expect(mediaCredit.role, "owner1"); + expect(mediaCredit.scheme, "urn:yvs"); + expect(mediaCredit.value, "copyright holder of the entity"); + + expect(item.media.category.scheme, "http://search.yahoo.com/mrss/category_ schema"); + expect(item.media.category.label, "Music"); + expect(item.media.category.value, "music/artist/album/song"); + + expect(item.media.rating.scheme, "urn:simple"); + expect(item.media.rating.value, "adult"); + + expect(item.media.title.type, "plain"); + expect(item.media.title.value, "The Judy's -- The Moo Song"); + + expect(item.media.description.type, "plain"); + expect(item.media.description.value, "This was some really bizarre band I listened to as a young lad."); + + expect(item.media.keywords, "kitty, cat, big dog, yarn, fluffy"); + + expect(item.media.thumbnails.length, 2); + var mediaThumbnail = item.media.thumbnails.first; + expect(mediaThumbnail.url, "http://www.foo.com/keyframe1.jpg"); + expect(mediaThumbnail.width, "75"); + expect(mediaThumbnail.height, "50"); + expect(mediaThumbnail.time, "12:05:01.123"); + + expect(item.media.hash.algo, "md5"); + expect(item.media.hash.value, "dfdec888b72151965a34b4b59031290a"); + + expect(item.media.player.url, "http://www.foo.com/player?id=1111"); + expect(item.media.player.width, 400); + expect(item.media.player.height, 200); + expect(item.media.player.value, ""); + + expect(item.media.copyright.url, "http://blah.com/additional-info.html"); + expect(item.media.copyright.value, "2005 FooBar Media"); + + expect(item.media.text.type, "plain"); + expect(item.media.text.lang, "en"); + expect(item.media.text.start, "00:00:03.000"); + expect(item.media.text.end, "00:00:10.000"); + expect(item.media.text.value, " Oh, say, can you see"); + + expect(item.media.restriction.relationship, "allow"); + expect(item.media.restriction.type, "country"); + expect(item.media.restriction.value, "au us"); + + expect(item.media.community.starRating.average, 3.5); + expect(item.media.community.starRating.count, 20); + expect(item.media.community.starRating.min, 1); + expect(item.media.community.starRating.max, 10); + expect(item.media.community.statistics.views, 5); + expect(item.media.community.statistics.favorites, 4); + expect(item.media.community.tags.tags, "news: 5, abc:3"); + expect(item.media.community.tags.weight, 1); + + expect(item.media.comments.length, 2); + expect(item.media.comments.first, "comment1"); + expect(item.media.comments.last, "comment2"); + + expect(item.media.embed.url, "http://www.foo.com/player.swf"); + expect(item.media.embed.width, 512); + expect(item.media.embed.height, 323); + expect(item.media.embed.params.length, 5); + expect(item.media.embed.params.first.name, "type"); + expect(item.media.embed.params.first.value, "application/x-shockwave-flash"); + + expect(item.media.responses.length, 2); + expect(item.media.responses.first, "http://www.response1.com"); + expect(item.media.responses.last, "http://www.response2.com"); + + expect(item.media.backLinks.length, 2); + expect(item.media.backLinks.first, "http://www.backlink1.com"); + expect(item.media.backLinks.last, "http://www.backlink2.com"); + + expect(item.media.status.state, "active"); + expect(item.media.status.reason, null); + + expect(item.media.prices.length, 2); + expect(item.media.prices.first.price, 19.99); + expect(item.media.prices.first.type, "rent"); + expect(item.media.prices.first.info, "http://www.dummy.jp/package_info.html"); + expect(item.media.prices.first.currency, "EUR"); + + expect(item.media.license.type, "text/html"); + expect(item.media.license.href, "http://www.licensehost.com/license"); + expect(item.media.license.value, " Sample license for a video"); + + expect(item.media.peerLink.type, "application/x-bittorrent"); + expect(item.media.peerLink.href, "http://www.foo.org/sampleFile.torrent"); + expect(item.media.peerLink.value, ""); + + expect(item.media.rights.status, "official"); + + expect(item.media.scenes.length, 2); + expect(item.media.scenes.first.title, "sceneTitle1"); + expect(item.media.scenes.first.description, "sceneDesc1"); + expect(item.media.scenes.first.startTime, "00:15"); + expect(item.media.scenes.first.endTime, "00:45"); + }); } diff --git a/test/rss_test.dart b/test/rss_test.dart index bc59ea0..bb4a398 100644 --- a/test/rss_test.dart +++ b/test/rss_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; import 'package:webfeed/webfeed.dart'; void main() { - test("parsing Invalid.xml", () { + test("parse Invalid.xml", () { var xmlString = new File("test/xml/Invalid.xml").readAsStringSync(); try { @@ -13,7 +13,7 @@ void main() { fail("Should throw Argument Error"); } on ArgumentError {} }); - test("parsing RSS.xml", () { + test("parse RSS.xml", () { var xmlString = new File("test/xml/RSS.xml").readAsStringSync(); var feed = new RssFeed.parse(xmlString); @@ -76,7 +76,7 @@ void main() { expect(feed.items.first.content.value, " Test content
"); expect(feed.items.first.content.images.first, "https://test.com/image_link"); }); - test("parsing RSS-Media.xml", (){ + test("parse RSS-Media.xml", (){ var xmlString = new File("test/xml/RSS-Media.xml").readAsStringSync(); var feed = new RssFeed.parse(xmlString); @@ -120,5 +120,94 @@ void main() { expect(item.media.rating.scheme, "urn:simple"); expect(item.media.rating.value, "adult"); + + expect(item.media.title.type, "plain"); + expect(item.media.title.value, "The Judy's -- The Moo Song"); + + expect(item.media.description.type, "plain"); + expect(item.media.description.value, "This was some really bizarre band I listened to as a young lad."); + + expect(item.media.keywords, "kitty, cat, big dog, yarn, fluffy"); + + expect(item.media.thumbnails.length, 2); + var mediaThumbnail = item.media.thumbnails.first; + expect(mediaThumbnail.url, "http://www.foo.com/keyframe1.jpg"); + expect(mediaThumbnail.width, "75"); + expect(mediaThumbnail.height, "50"); + expect(mediaThumbnail.time, "12:05:01.123"); + + expect(item.media.hash.algo, "md5"); + expect(item.media.hash.value, "dfdec888b72151965a34b4b59031290a"); + + expect(item.media.player.url, "http://www.foo.com/player?id=1111"); + expect(item.media.player.width, 400); + expect(item.media.player.height, 200); + expect(item.media.player.value, ""); + + expect(item.media.copyright.url, "http://blah.com/additional-info.html"); + expect(item.media.copyright.value, "2005 FooBar Media"); + + expect(item.media.text.type, "plain"); + expect(item.media.text.lang, "en"); + expect(item.media.text.start, "00:00:03.000"); + expect(item.media.text.end, "00:00:10.000"); + expect(item.media.text.value, " Oh, say, can you see"); + + expect(item.media.restriction.relationship, "allow"); + expect(item.media.restriction.type, "country"); + expect(item.media.restriction.value, "au us"); + + expect(item.media.community.starRating.average, 3.5); + expect(item.media.community.starRating.count, 20); + expect(item.media.community.starRating.min, 1); + expect(item.media.community.starRating.max, 10); + expect(item.media.community.statistics.views, 5); + expect(item.media.community.statistics.favorites, 4); + expect(item.media.community.tags.tags, "news: 5, abc:3"); + expect(item.media.community.tags.weight, 1); + + expect(item.media.comments.length, 2); + expect(item.media.comments.first, "comment1"); + expect(item.media.comments.last, "comment2"); + + expect(item.media.embed.url, "http://www.foo.com/player.swf"); + expect(item.media.embed.width, 512); + expect(item.media.embed.height, 323); + expect(item.media.embed.params.length, 5); + expect(item.media.embed.params.first.name, "type"); + expect(item.media.embed.params.first.value, "application/x-shockwave-flash"); + + expect(item.media.responses.length, 2); + expect(item.media.responses.first, "http://www.response1.com"); + expect(item.media.responses.last, "http://www.response2.com"); + + expect(item.media.backLinks.length, 2); + expect(item.media.backLinks.first, "http://www.backlink1.com"); + expect(item.media.backLinks.last, "http://www.backlink2.com"); + + expect(item.media.status.state, "active"); + expect(item.media.status.reason, null); + + expect(item.media.prices.length, 2); + expect(item.media.prices.first.price, 19.99); + expect(item.media.prices.first.type, "rent"); + expect(item.media.prices.first.info, "http://www.dummy.jp/package_info.html"); + expect(item.media.prices.first.currency, "EUR"); + + expect(item.media.license.type, "text/html"); + expect(item.media.license.href, "http://www.licensehost.com/license"); + expect(item.media.license.value, " Sample license for a video"); + + expect(item.media.peerLink.type, "application/x-bittorrent"); + expect(item.media.peerLink.href, "http://www.foo.org/sampleFile.torrent"); + expect(item.media.peerLink.value, ""); + + expect(item.media.rights.status, "official"); + + expect(item.media.scenes.length, 2); + expect(item.media.scenes.first.title, "sceneTitle1"); + expect(item.media.scenes.first.description, "sceneDesc1"); + expect(item.media.scenes.first.startTime, "00:15"); + expect(item.media.scenes.first.endTime, "00:45"); }); } diff --git a/test/xml/Atom-Media.xml b/test/xml/Atom-Media.xml new file mode 100644 index 0000000..7f0ab84 --- /dev/null +++ b/test/xml/Atom-Media.xml @@ -0,0 +1,118 @@ + + + foo-bar-id + Foo bar news + 2018-04-06T13:02:46Z + + + + Alice + http://foo.bar.news/people/alice + alice@foo.bar.news + + + Bob + http://foo.bar.news/people/bob + bob@foo.bar.news + + + Charlie + http://foo.bar.news/people/charlie + charlie@foo.bar.news + + + David + http://foo.bar.news/people/david + david@foo.bar.news + + + + Foo bar generator + http://foo.bar.news/icon.png + http://foo.bar.news/logo.png + This is subtitle + + foo-bar-entry-id-1 + Foo bar item 1 + + + copyright holder of the entity + copyright holder of the entity + music/artist/album/song + adult + + + + + + + band member 1 + band member 2 + music/artist name/album/song + nonadult + + The Judy's -- The Moo Song + This was some really bizarre band I listened to as a young lad. + kitty, cat, big dog, yarn, fluffy + + + dfdec888b72151965a34b4b59031290a + + 2005 FooBar Media + Oh, say, can you see + au us + + + + news: 5, abc:3 + + + comment1 + comment2 + + + application/x-shockwave-flash + 512 + 323 + true + id=12345&vid=678912i&lang=en-us&intl=us&thumbUrl=http://www.foo.com/thumbnail.jpg + + + + http://www.response1.com + http://www.response2.com + + + http://www.backlink1.com + http://www.backlink2.com + + + + + Sample license for a video + + + + + + 35.669998 139.770004 + + + + + + + sceneTitle1 + sceneDesc1 + 00:15 + 00:45 + + + sceneTitle2 + sceneDesc2 + 00:15 + 00:55 + + + + \ No newline at end of file diff --git a/test/xml/RSS-Media.xml b/test/xml/RSS-Media.xml index db6da03..4cc2f02 100644 --- a/test/xml/RSS-Media.xml +++ b/test/xml/RSS-Media.xml @@ -1,5 +1,6 @@ - @@ -15,28 +16,29 @@ music/artist/album/song adult - - - - - + + + + + band member 1 band member 2 music/artist name/album/song nonadult + The Judy's -- The Moo Song + This was some really bizarre band I listened to as a young lad. + kitty, cat, big dog, yarn, fluffy + + + dfdec888b72151965a34b4b59031290a + + 2005 FooBar Media + Oh, say, can you see + au us - + news: 5, abc:3 @@ -48,8 +50,7 @@ 512 323 true - - id=12345&vid=678912i&lang=en-us&intl=us&thumbUrl=http://www.foo.com/thumbnail.jpg + id=12345&vid=678912i&lang=en-us&intl=us&thumbUrl=http://www.foo.com/thumbnail.jpg @@ -61,18 +62,19 @@ http://www.backlink2.com - + + Sample license for a video - + - 35.669998 139.770004 + 35.669998 139.770004 - + sceneTitle1 @@ -80,6 +82,12 @@ 00:15 00:45 + + sceneTitle2 + sceneDesc2 + 00:15 + 00:55 +