Переглянути джерело

support media namespaces

master
Wito Chandra 8 роки тому
джерело
коміт
c545acb789
28 змінених файлів з 1087 додано та 108 видалено
  1. +23
    -14
      lib/domain/atom_feed.dart
  2. +47
    -35
      lib/domain/atom_item.dart
  3. +34
    -0
      lib/domain/media/community.dart
  4. +21
    -0
      lib/domain/media/copyright.dart
  5. +21
    -0
      lib/domain/media/description.dart
  6. +30
    -0
      lib/domain/media/embed.dart
  7. +21
    -0
      lib/domain/media/hash.dart
  8. +24
    -0
      lib/domain/media/license.dart
  9. +126
    -0
      lib/domain/media/media.dart
  10. +21
    -0
      lib/domain/media/param.dart
  11. +24
    -0
      lib/domain/media/peer_link.dart
  12. +27
    -0
      lib/domain/media/player.dart
  13. +24
    -0
      lib/domain/media/price.dart
  14. +24
    -0
      lib/domain/media/restriction.dart
  15. +18
    -0
      lib/domain/media/rights.dart
  16. +28
    -0
      lib/domain/media/scene.dart
  17. +24
    -0
      lib/domain/media/star_rating.dart
  18. +18
    -0
      lib/domain/media/statistics.dart
  19. +21
    -0
      lib/domain/media/status.dart
  20. +21
    -0
      lib/domain/media/tags.dart
  21. +30
    -0
      lib/domain/media/text.dart
  22. +24
    -0
      lib/domain/media/thumbnail.dart
  23. +21
    -0
      lib/domain/media/title.dart
  24. +41
    -31
      lib/domain/rss_feed.dart
  25. +133
    -2
      test/atom_test.dart
  26. +92
    -3
      test/rss_test.dart
  27. +118
    -0
      test/xml/Atom-Media.xml
  28. +31
    -23
      test/xml/RSS-Media.xml

+ 23
- 14
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,


+ 47
- 35
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<AtomPerson> authors;
List<AtomLink> links;
List<AtomCategory> categories;
List<AtomPerson> contributors;
AtomSource source;
String published;
String content;
String summary;
String rights;
final List<AtomPerson> authors;
final List<AtomLink> links;
final List<AtomCategory> categories;
final List<AtomPerson> 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


+ 34
- 0
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"),
),
);
}
}

+ 21
- 0
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,
);
}
}

+ 21
- 0
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,
);
}
}

+ 30
- 0
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<Param> 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(),
);
}
}

+ 21
- 0
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,
);
}
}

+ 24
- 0
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,
);
}
}

+ 126
- 0
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<Credit> credits;
final Category category;
final Rating rating;
final Title title;
final Description description;
final String keywords;
final List<Thumbnail> thumbnails;
final Hash hash;
final Player player;
final Copyright copyright;
final Text text;
final Restriction restriction;
final Community community;
final List<String> comments;
final Embed embed;
final List<String> responses;
final List<String> backLinks;
final Status status;
final List<Price> prices;
final License license;
final PeerLink peerLink;
final Rights rights;
final List<Scene> 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() ??
[],
);
}
}

+ 21
- 0
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,
);
}
}

+ 24
- 0
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,
);
}
}

+ 27
- 0
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,
);
}
}

+ 24
- 0
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"),
);
}
}

+ 24
- 0
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,
);
}
}

+ 18
- 0
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"),
);
}
}

+ 28
- 0
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,
);
}
}

+ 24
- 0
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"),
);
}
}

+ 18
- 0
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"),
);
}
}

+ 21
- 0
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"),
);
}
}

+ 21
- 0
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"),
);
}
}

+ 30
- 0
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,
);
}
}

+ 24
- 0
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"),
);
}
}

+ 21
- 0
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,
);
}
}

+ 41
- 31
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


+ 133
- 2
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");
});
}

+ 92
- 3
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, "<img width=\"1000\" height=\"690\" src=\"https://test.com/image_link\"/> Test content<br />");
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");
});
}

+ 118
- 0
test/xml/Atom-Media.xml Переглянути файл

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>foo-bar-id</id>
<title type="text">Foo bar news</title>
<updated>2018-04-06T13:02:46Z</updated>
<link rel="foo" type="text/html" hreflang="en" href="http://foo.bar.news/" title="Foo bar news html" length="1000"/>
<link rel="bar" type="application/atom+xml" hreflang="pt" href="http://foo.bar.news/feed.atom" title="Foo bar news atom" length="100"/>
<author>
<name>Alice</name>
<uri>http://foo.bar.news/people/alice</uri>
<email>alice@foo.bar.news</email>
</author>
<author>
<name>Bob</name>
<uri>http://foo.bar.news/people/bob</uri>
<email>bob@foo.bar.news</email>
</author>
<contributor>
<name>Charlie</name>
<uri>http://foo.bar.news/people/charlie</uri>
<email>charlie@foo.bar.news</email>
</contributor>
<contributor>
<name>David</name>
<uri>http://foo.bar.news/people/david</uri>
<email>david@foo.bar.news</email>
</contributor>
<category term="foo category" scheme="this-is-foo-scheme" label="this is foo label"/>
<category term="bar category" scheme="this-is-bar-scheme" label="this is bar label"/>
<generator uri="http://foo.bar.news/generator" version="1.0">Foo bar generator</generator>
<icon>http://foo.bar.news/icon.png</icon>
<logo>http://foo.bar.news/logo.png</logo>
<subtitle>This is subtitle</subtitle>
<entry>
<id>foo-bar-entry-id-1</id>
<title>Foo bar item 1</title>
<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: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:title type="plain">The Judy's -- The Moo Song</media:title>
<media:description type="plain">This was some really bizarre band I listened to as a young lad.</media:description>
<media:keywords>kitty, cat, big dog, yarn, fluffy</media:keywords>
<media:thumbnail url="http://www.foo.com/keyframe1.jpg" width="75" height="50" time="12:05:01.123" />
<media:thumbnail url="http://www.foo.com/keyframe2.jpg" width="150" height="100" time="12:05:01.125" />
<media:hash algo="md5">dfdec888b72151965a34b4b59031290a</media:hash>
<media:player url="http://www.foo.com/player?id=1111" height="200" width="400" />
<media:copyright url="http://blah.com/additional-info.html">2005 FooBar Media</media:copyright>
<media:text type="plain" lang="en" start="00:00:03.000" end="00:00:10.000"> Oh, say, can you see</media:text>
<media:restriction relationship="allow" type="country">au us</media:restriction>
<media:community>
<media:starRating average="3.5" count="20" min="1" max="10" />
<media:statistics views="5" favorites="4" />
<media:tags>news: 5, abc:3</media:tags>
</media:community>
<media:comments>
<media:comment>comment1</media:comment>
<media:comment>comment2</media:comment>
</media:comments>
<media:embed url="http://www.foo.com/player.swf" width="512" height="323">
<media:param name="type">application/x-shockwave-flash</media:param>
<media:param name="width">512</media:param>
<media:param name="height">323</media:param>
<media:param name="allowFullScreen">true</media:param>
<media:param name="flashVars"> id=12345&amp;vid=678912i&amp;lang=en-us&amp;intl=us&amp;thumbUrl=http://www.foo.com/thumbnail.jpg
</media:param>
</media:embed>
<media:responses>
<media:response>http://www.response1.com</media:response>
<media:response>http://www.response2.com</media:response>
</media:responses>
<media:backLinks>
<media:backLink>http://www.backlink1.com</media:backLink>
<media:backLink>http://www.backlink2.com</media:backLink>
</media:backLinks>
<media:status state="active" />
<media:price type="rent" price="19.99" info="http://www.dummy.jp/package_info.html" currency="EUR" />
<media:price type="buy" price="39.99" currency="EUR" />
<media:license type="text/html" href="http://www.licensehost.com/license"> Sample license for a video</media:license>
<media:subTitle type="application/smil" lang="en-us" href="http://www.foo.org/subtitle.smil" />
<media:peerLink type="application/x-bittorrent" href="http://www.foo.org/sampleFile.torrent" />
<media:location description="My house" start="00:01" end="01:00">
<georss:where>
<gml:Point>
<gml:pos>35.669998 139.770004</gml:pos>
</gml:Point>
</georss:where>
</media:location>
<media:rights status="official" />
<media:scenes>
<media:scene>
<sceneTitle>sceneTitle1</sceneTitle>
<sceneDescription>sceneDesc1</sceneDescription>
<sceneStartTime>00:15</sceneStartTime>
<sceneEndTime>00:45</sceneEndTime>
</media:scene>
<media:scene>
<sceneTitle>sceneTitle2</sceneTitle>
<sceneDescription>sceneDesc2</sceneDescription>
<sceneStartTime>00:15</sceneStartTime>
<sceneEndTime>00:55</sceneEndTime>
</media:scene>
</media:scenes>
</entry>
</feed>

+ 31
- 23
test/xml/RSS-Media.xml Переглянути файл

@@ -1,5 +1,6 @@
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:georss="http://www.georss.org/georss"
<rss version="2.0"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml">

<channel>
@@ -15,28 +16,29 @@
<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: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:title type="plain">The Judy's -- The Moo Song</media:title>
<media:description type="plain">This was some really bizarre band I listened to as a young lad.</media:description>
<media:keywords>kitty, cat, big dog, yarn, fluffy</media:keywords>
<media:thumbnail url="http://www.foo.com/keyframe1.jpg" width="75" height="50" time="12:05:01.123" />
<media:thumbnail url="http://www.foo.com/keyframe2.jpg" width="150" height="100" time="12:05:01.125" />
<media:hash algo="md5">dfdec888b72151965a34b4b59031290a</media:hash>
<media:player url="http://www.foo.com/player?id=1111" height="200" width="400" />
<media:copyright url="http://blah.com/additional-info.html">2005 FooBar Media</media:copyright>
<media:text type="plain" lang="en" start="00:00:03.000" end="00:00:10.000"> Oh, say, can you see</media:text>
<media:restriction relationship="allow" type="country">au us</media:restriction>
<media:community>
<media:starRating average="3.5" count="20" min="1" max="10" />
<media:statistics views="5" favorites="5" />
<media:statistics views="5" favorites="4" />
<media:tags>news: 5, abc:3</media:tags>
</media:community>
<media:comments>
@@ -48,8 +50,7 @@
<media:param name="width">512</media:param>
<media:param name="height">323</media:param>
<media:param name="allowFullScreen">true</media:param>
<media:param name="flashVars">
id=12345&amp;vid=678912i&amp;lang=en-us&amp;intl=us&amp;thumbUrl=http://www.foo.com/thumbnail.jpg
<media:param name="flashVars"> id=12345&amp;vid=678912i&amp;lang=en-us&amp;intl=us&amp;thumbUrl=http://www.foo.com/thumbnail.jpg
</media:param>
</media:embed>
<media:responses>
@@ -61,18 +62,19 @@
<media:backLink>http://www.backlink2.com</media:backLink>
</media:backLinks>
<media:status state="active" />
<media:price type="rent" price="19.99" currency="EUR" />
<media:price type="rent" price="19.99" info="http://www.dummy.jp/package_info.html" currency="EUR" />
<media:price type="buy" price="39.99" currency="EUR" />
<media:license type="text/html" href="http://www.licensehost.com/license"> Sample license for a video</media:license>
<media:subTitle type="application/smil" lang="en-us" href="http://www.foo.org/subtitle.smil" />
<media:peerLink type="application/x-bittorrent " href="http://www.foo.org/sampleFile.torrent" />
<media:peerLink type="application/x-bittorrent" href="http://www.foo.org/sampleFile.torrent" />
<media:location description="My house" start="00:01" end="01:00">
<georss:where>
<gml:Point>
<gml:pos>35.669998 139.770004</gml:pos>
<gml:pos>35.669998 139.770004</gml:pos>
</gml:Point>
</georss:where>
</media:location>
<media:restriction type="sharing" relationship="deny" />
<media:rights status="official" />
<media:scenes>
<media:scene>
<sceneTitle>sceneTitle1</sceneTitle>
@@ -80,6 +82,12 @@
<sceneStartTime>00:15</sceneStartTime>
<sceneEndTime>00:45</sceneEndTime>
</media:scene>
<media:scene>
<sceneTitle>sceneTitle2</sceneTitle>
<sceneDescription>sceneDesc2</sceneDescription>
<sceneStartTime>00:15</sceneStartTime>
<sceneEndTime>00:55</sceneEndTime>
</media:scene>
</media:scenes>
</item>
</channel>

Завантаження…
Відмінити
Зберегти