| @@ -0,0 +1,24 @@ | |||||
| import 'package:xml/xml.dart'; | |||||
| class Category { | |||||
| final String scheme; | |||||
| final String label; | |||||
| final String value; | |||||
| Category({ | |||||
| this.scheme, | |||||
| this.label, | |||||
| this.value, | |||||
| }); | |||||
| factory Category.parse(XmlElement element) { | |||||
| if (element == null) { | |||||
| return null; | |||||
| } | |||||
| return new Category( | |||||
| scheme: element.getAttribute("scheme"), | |||||
| label: element.getAttribute("label"), | |||||
| value: element.text, | |||||
| ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,21 @@ | |||||
| import 'package:xml/xml.dart'; | |||||
| class Credit { | |||||
| final String role; | |||||
| final String scheme; | |||||
| final String value; | |||||
| Credit({ | |||||
| this.role, | |||||
| this.scheme, | |||||
| this.value, | |||||
| }); | |||||
| factory Credit.parse(XmlElement element) { | |||||
| return new Credit( | |||||
| role: element.getAttribute("role"), | |||||
| scheme: element.getAttribute("scheme"), | |||||
| value: element.text, | |||||
| ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,40 @@ | |||||
| import 'package:webfeed/domain/media/category.dart'; | |||||
| import 'package:webfeed/domain/media/content.dart'; | |||||
| import 'package:webfeed/domain/media/credit.dart'; | |||||
| import 'package:webfeed/domain/media/rating.dart'; | |||||
| import 'package:webfeed/util/helpers.dart'; | |||||
| import 'package:xml/xml.dart'; | |||||
| class Group { | |||||
| final List<Content> contents; | |||||
| final List<Credit> credits; | |||||
| final Category category; | |||||
| final Rating rating; | |||||
| Group({ | |||||
| this.contents, | |||||
| this.credits, | |||||
| this.category, | |||||
| this.rating, | |||||
| }); | |||||
| factory Group.parse(XmlElement element) { | |||||
| if (element == null) { | |||||
| return null; | |||||
| } | |||||
| return new Group( | |||||
| contents: element.findElements("media:content").map((e) { | |||||
| return new Content.parse(e); | |||||
| }).toList(), | |||||
| credits: element.findElements("media:credit").map((e) { | |||||
| return new Credit.parse(e); | |||||
| }).toList(), | |||||
| category: new Category.parse( | |||||
| findElementOrNull(element, "media:category"), | |||||
| ), | |||||
| rating: new Rating.parse( | |||||
| findElementOrNull(element, "media:rating"), | |||||
| ), | |||||
| ); | |||||
| } | |||||
| } | |||||
| @@ -1,17 +1,43 @@ | |||||
| import 'package:webfeed/domain/media/category.dart'; | |||||
| import 'package:webfeed/domain/media/content.dart'; | import 'package:webfeed/domain/media/content.dart'; | ||||
| import 'package:webfeed/domain/media/credit.dart'; | |||||
| import 'package:webfeed/domain/media/group.dart'; | |||||
| import 'package:webfeed/domain/media/rating.dart'; | |||||
| import 'package:webfeed/util/helpers.dart'; | |||||
| import 'package:xml/xml.dart'; | import 'package:xml/xml.dart'; | ||||
| class Media { | class Media { | ||||
| final Group group; | |||||
| final List<Content> contents; | final List<Content> contents; | ||||
| final List<Credit> credits; | |||||
| final Category category; | |||||
| final Rating rating; | |||||
| Media({this.contents}); | |||||
| Media({ | |||||
| this.group, | |||||
| this.contents, | |||||
| this.credits, | |||||
| this.category, | |||||
| this.rating, | |||||
| }); | |||||
| factory Media.parse(XmlElement element) { | factory Media.parse(XmlElement element) { | ||||
| var contents = element.findAllElements("media:content").map((e) { | |||||
| return new Content.parse(e); | |||||
| }).toList(); | |||||
| return new Media( | return new Media( | ||||
| contents: contents, | |||||
| group: new Group.parse( | |||||
| findElementOrNull(element, "media:group"), | |||||
| ), | |||||
| contents: element.findElements("media:content").map((e) { | |||||
| return new Content.parse(e); | |||||
| }).toList(), | |||||
| credits: element.findElements("media:credit").map((e) { | |||||
| return new Credit.parse(e); | |||||
| }).toList(), | |||||
| category: new Category.parse( | |||||
| findElementOrNull(element, "media:category"), | |||||
| ), | |||||
| rating: new Rating.parse( | |||||
| findElementOrNull(element, "media:rating"), | |||||
| ), | |||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,21 @@ | |||||
| import 'package:xml/xml.dart'; | |||||
| class Rating { | |||||
| final String scheme; | |||||
| final String value; | |||||
| Rating({ | |||||
| this.scheme, | |||||
| this.value, | |||||
| }); | |||||
| factory Rating.parse(XmlElement element) { | |||||
| if (element == null) { | |||||
| return null; | |||||
| } | |||||
| return new Rating( | |||||
| scheme: element.getAttribute("scheme"), | |||||
| value: element.text, | |||||
| ); | |||||
| } | |||||
| } | |||||
| @@ -2,6 +2,14 @@ import 'dart:core'; | |||||
| import 'package:xml/xml.dart'; | import 'package:xml/xml.dart'; | ||||
| XmlElement findElementOrNull(XmlElement element, String name) { | |||||
| try { | |||||
| return element.findAllElements(name).first; | |||||
| } on StateError { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| String xmlGetString(XmlElement element, String name, {strict: true}) { | String xmlGetString(XmlElement element, String name, {strict: true}) { | ||||
| try { | try { | ||||
| return element.findElements(name).first.text; | return element.findElements(name).first.text; | ||||
| @@ -90,6 +90,11 @@ void main() { | |||||
| expect(item.link, "http://www.foo.com"); | expect(item.link, "http://www.foo.com"); | ||||
| expect(item.pubDate, "Mon, 27 Aug 2001 16:08:56 PST"); | expect(item.pubDate, "Mon, 27 Aug 2001 16:08:56 PST"); | ||||
| 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); | expect(item.media.contents.length, 2); | ||||
| var mediaContent = item.media.contents.first; | var mediaContent = item.media.contents.first; | ||||
| expect(mediaContent.url, "http://www.foo.com/video.mov"); | expect(mediaContent.url, "http://www.foo.com/video.mov"); | ||||
| @@ -102,5 +107,18 @@ void main() { | |||||
| expect(mediaContent.framerate, 25); | expect(mediaContent.framerate, 25); | ||||
| expect(mediaContent.samplingrate, 44.1); | expect(mediaContent.samplingrate, 44.1); | ||||
| expect(mediaContent.channels, 2); | 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"); | |||||
| }); | }); | ||||
| } | } | ||||
| @@ -10,6 +10,30 @@ | |||||
| <pubDate>Mon, 27 Aug 2001 16:08:56 PST</pubDate> | <pubDate>Mon, 27 Aug 2001 16:08:56 PST</pubDate> | ||||
| <media:content url="http://www.foo.com/video.mov" fileSize="2000" medium="video" isDefault="true" expression="full" bitrate="128" framerate="25" samplingrate="44.1" channels="2" type="video/quicktime" /> | <media:content url="http://www.foo.com/video.mov" fileSize="2000" medium="video" isDefault="true" expression="full" bitrate="128" framerate="25" samplingrate="44.1" channels="2" type="video/quicktime" /> | ||||
| <media:content url="http://www.foo.com/video2.mov" fileSize="2000" bitrate="128" type="video/quicktime" expression="full" /> | <media:content url="http://www.foo.com/video2.mov" fileSize="2000" bitrate="128" type="video/quicktime" expression="full" /> | ||||
| <media:credit role="owner1" scheme="urn:yvs">copyright holder of the entity</media:credit> | |||||
| <media:credit role="owner2" scheme="urn:yvs">copyright holder of the entity</media:credit> | |||||
| <media:category scheme="http://search.yahoo.com/mrss/category_ schema" label="Music">music/artist/album/song</media:category> | |||||
| <media:rating scheme="urn:simple">adult</media:rating> | |||||
| <media:group> | |||||
| <media:content url="http://www.foo.com/song64kbps.mp3" | |||||
| fileSize="1000" bitrate="64" type="audio/mpeg" | |||||
| isDefault="true" expression="full" /> | |||||
| <media:content url="http://www.foo.com/song128kbps.mp3" | |||||
| fileSize="2000" bitrate="128" type="audio/mpeg" | |||||
| expression="full" /> | |||||
| <media:content url="http://www.foo.com/song256kbps.mp3" | |||||
| fileSize="4000" bitrate="256" type="audio/mpeg" | |||||
| expression="full" /> | |||||
| <media:content url="http://www.foo.com/song512kbps.mp3.torrent" | |||||
| fileSize="8000" type="application/x-bittorrent;enclosed=audio/mpeg" | |||||
| expression="full" /> | |||||
| <media:content url="http://www.foo.com/song.wav" | |||||
| fileSize="16000" type="audio/x-wav" expression="full" /> | |||||
| <media:credit role="musician">band member 1</media:credit> | |||||
| <media:credit role="musician">band member 2</media:credit> | |||||
| <media:category>music/artist name/album/song</media:category> | |||||
| <media:rating>nonadult</media:rating> | |||||
| </media:group> | |||||
| <media:community> | <media:community> | ||||
| <media:starRating average="3.5" count="20" min="1" max="10" /> | <media:starRating average="3.5" count="20" min="1" max="10" /> | ||||
| <media:statistics views="5" favorites="5" /> | <media:statistics views="5" favorites="5" /> | ||||