mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 998063 - Support media:thumbnail in feed parser. r=mak
This commit is contained in:
parent
17614d6413
commit
a42a68b78c
@ -463,11 +463,15 @@ Entry.prototype = {
|
||||
|
||||
// Add media:content to enclosures
|
||||
if (bagHasKey(this.fields, "mediacontent"))
|
||||
this._mediacontentToEnclosures();
|
||||
this._mediaToEnclosures("mediacontent");
|
||||
|
||||
// Add media:thumbnail to enclosures
|
||||
if (bagHasKey(this.fields, "mediathumbnail"))
|
||||
this._mediaToEnclosures("mediathumbnail");
|
||||
|
||||
// Add media:content in media:group to enclosures
|
||||
if (bagHasKey(this.fields, "mediagroup"))
|
||||
this._mediagroupToEnclosures();
|
||||
this._mediaToEnclosures("mediagroup", "mediacontent");
|
||||
},
|
||||
|
||||
__enclosure_map: null,
|
||||
@ -539,38 +543,15 @@ Entry.prototype = {
|
||||
this._addToEnclosures(enc);
|
||||
},
|
||||
|
||||
_mediacontentToEnclosures: function Entry_mediacontentToEnclosures() {
|
||||
var mediacontent = this.fields.getPropertyAsInterface("mediacontent", Ci.nsIArray);
|
||||
_mediaToEnclosures: function Entry_mediaToEnclosures(mediaType, contentType) {
|
||||
var content = this.fields.getPropertyAsInterface(mediaType, Ci.nsIArray);
|
||||
|
||||
for (var i = 0; i < mediacontent.length; ++i) {
|
||||
var contentElement = mediacontent.queryElementAt(i, Ci.nsIWritablePropertyBag2);
|
||||
if (contentType)
|
||||
content = content.getPropertyAsInterface(contentType, Ci.nsIArray);
|
||||
|
||||
// media:content don't require url, but if it's not there, we should
|
||||
// skip it.
|
||||
if (!bagHasKey(contentElement, "url"))
|
||||
continue;
|
||||
|
||||
var enc = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
|
||||
|
||||
// copy media:content bits over to equivalent enclosure bits
|
||||
enc.setPropertyAsAString("url", contentElement.getPropertyAsAString("url"));
|
||||
if (bagHasKey(contentElement, "type")) {
|
||||
enc.setPropertyAsAString("type", contentElement.getPropertyAsAString("type"));
|
||||
}
|
||||
if (bagHasKey(contentElement, "fileSize")) {
|
||||
enc.setPropertyAsAString("length", contentElement.getPropertyAsAString("fileSize"));
|
||||
}
|
||||
|
||||
this._addToEnclosures(enc);
|
||||
}
|
||||
},
|
||||
|
||||
_mediagroupToEnclosures: function Entry_mediagroupToEnclosures() {
|
||||
var group = this.fields.getPropertyAsInterface("mediagroup", Ci.nsIPropertyBag2);
|
||||
|
||||
var content = group.getPropertyAsInterface("mediacontent", Ci.nsIArray);
|
||||
for (var i = 0; i < content.length; ++i) {
|
||||
var contentElement = content.queryElementAt(i, Ci.nsIWritablePropertyBag2);
|
||||
|
||||
// media:content don't require url, but if it's not there, we should
|
||||
// skip it.
|
||||
if (!bagHasKey(contentElement, "url"))
|
||||
@ -582,7 +563,12 @@ Entry.prototype = {
|
||||
enc.setPropertyAsAString("url", contentElement.getPropertyAsAString("url"));
|
||||
if (bagHasKey(contentElement, "type")) {
|
||||
enc.setPropertyAsAString("type", contentElement.getPropertyAsAString("type"));
|
||||
} else if (mediaType == "mediathumbnail") {
|
||||
// thumbnails won't have a type, but default to image types
|
||||
enc.setPropertyAsAString("type", "image/*");
|
||||
enc.setPropertyAsBool("thumbnail", true);
|
||||
}
|
||||
|
||||
if (bagHasKey(contentElement, "fileSize")) {
|
||||
enc.setPropertyAsAString("length", contentElement.getPropertyAsAString("fileSize"));
|
||||
}
|
||||
@ -1137,6 +1123,7 @@ function FeedProcessor() {
|
||||
"enclosure": new ElementInfo("enclosure", null, null, false),
|
||||
"media:content": new ElementInfo("mediacontent", null, null, true),
|
||||
"media:group": new ElementInfo("mediagroup", null, null, false),
|
||||
"media:thumbnail": new ElementInfo("mediathumbnail", null, null, true),
|
||||
"guid": new ElementInfo("guid", null, rssGuid, false)
|
||||
},
|
||||
|
||||
@ -1149,7 +1136,8 @@ function FeedProcessor() {
|
||||
},
|
||||
|
||||
"IN_MEDIAGROUP": {
|
||||
"media:content": new ElementInfo("mediacontent", null, null, true)
|
||||
"media:content": new ElementInfo("mediacontent", null, null, true),
|
||||
"media:thumbnail": new ElementInfo("mediathumbnail", null, null, true)
|
||||
},
|
||||
|
||||
/********* RSS1 **********/
|
||||
|
@ -9,7 +9,8 @@ Expect: var enc = feed.items.queryElementAt(0, Components.interfaces.nsIFeedEntr
|
||||
<channel>
|
||||
<item>
|
||||
|
||||
<media:content fileSize="24986239" type="video/mpeg" url="http://dallas.example.com/joebob_050689.mpeg" />
|
||||
<media:content fileSize="24986239" type="video/mpeg" url="http://dallas.example.com/joebob_050689.mpeg" />
|
||||
<media:thumbnail url="http://dallas.example.com/joebob_050689.jpg" width="75" height="50"/>
|
||||
<author>jbb@dallas.example.com (Joe Bob Briggs)</author>
|
||||
<comments>http://example.org</comments>
|
||||
<title>test</title>
|
||||
|
Loading…
Reference in New Issue
Block a user