YouTube.js
Go to the documentation of this file.
1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
3 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
4 
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cr = Components.results;
8 
9 const DESCRIPTION = "mashTape Provider: YouTube Provider";
10 const CID = "{e0f43860-6a5c-11dd-ad8b-0800200c9a66}";
11 const CONTRACTID = "@songbirdnest.com/mashTape/provider/flash/YouTube;1";
12 
13 // XPCOM constructor for our YouTube mashTape provider
14 function YouTube() {
15  this.wrappedJSObject = this;
16  Components.utils.import("resource://mashtape/mtUtils.jsm");
17 }
18 
19 YouTube.prototype.constructor = YouTube;
20 YouTube.prototype = {
22  classID: Components.ID(CID),
24  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMashTapeFlashProvider,
25  Ci.sbIMashTapeProvider]),
26 
27  providerName: "YouTube",
28  providerType: "flash",
29  providerUrl: "http://www.youtube.com",
30  providerIcon: "chrome://mashTape/content/tabs/youtube.png",
31  searchURL: "http://gdata.youtube.com/feeds/videos?vq=",
32 
33  query: function(searchTerms, updateFn) {
34  var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
35  .createInstance(Ci.nsIXMLHttpRequest);
36  var query = "%22" + escape(searchTerms) + "%22";
37  mtUtils.log("YouTube", "URL: " + this.searchURL + query);
38  req.open("GET", this.searchURL + query, true);
39  req.provider = this;
40  req.updateFn = updateFn;
41  req.onreadystatechange = function() {
42  if (this.readyState != 4)
43  return;
44  if (this.status == 200) {
45  var results = new Array();
46  var x = new XML(this.responseText.replace(
47  "<?xml version='1.0' encoding='UTF-8'?>", ""));
48 
49  // Define our XML namespaces
50  var atomns = new Namespace('http://www.w3.org/2005/Atom');
51  var medians = new Namespace('http://search.yahoo.com/mrss/');
52  var ytns = new
53  Namespace('http://gdata.youtube.com/schemas/2007');
54 
55  for each (var entry in x..atomns::entry) {
56  // Find the <link> that is to the HTML page
57  var url;
58  for each (var link in entry.atomns::link) {
59  if (link.@type == "text/html") {
60  url = link.@href;
61  break;
62  }
63  }
64 
65  // Find the media:content that's the SWF
66  var swfUrl = null;
67  for each (var media in entry..medians::content) {
68  if (media.@type == "application/x-shockwave-flash") {
69  swfUrl = media.@url;
70  break;
71  }
72  }
73  if (swfUrl == null)
74  continue;
75 
76  // We want to externally script the swf player
77  swfUrl += "&enablejsapi=1";
78 
79  // Find the largest thumbnail
80  var thumbnail;
81  var thumbnailWidth = 0;
82  for each (var thumb in entry..medians::thumbnail) {
83  if (parseInt(thumb.@width) > thumbnailWidth) {
84  thumbnailWidth = thumb.@width;
85  thumbnail = thumb.@url;
86  }
87  }
88 
89  // Calculate the publication date
90  var dateObj = new Date();
91  dateObj.setISO8601(entry.atomns::published);
92 
93  var authorUrl = "http://www.youtube.com/user/" +
94  entry.atomns::author.atomns::name;
95 
96  var item = {
97  title: entry.atomns::title,
98  url: url,
99  swfUrl: swfUrl,
100  duration: entry..ytns::duration.@seconds,
101  time: dateObj.getTime(),
102  thumbnail: thumbnail,
103  author: entry.atomns::author.atomns::name,
104  //authorUrl: entry.atomns::author.atomns::uri,
105  authorUrl: authorUrl,
106  description: entry.atomns::content,
107  provider: this.provider.providerName,
108  providerUrl: this.provider.providerUrl,
109  ratio: 1.33,
110  width: 320,
111  height: 240,
112  }
113  results.push(item);
114  }
115 
116  results.wrappedJSObject = results;
117  this.updateFn.wrappedJSObject.update(CONTRACTID, results);
118  }
119  }
120  req.send(null);
121  },
122 }
123 
124 var components = [YouTube];
125 function NSGetModule(compMgr, fileSpec) {
126  return XPCOMUtils.generateModule([YouTube]);
127 }
classDescription entry
Definition: FeedWriter.js:1427
const Cc
Definition: YouTube.js:5
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function width(ele) rect(ele).width
_hideDatepicker duration
const CONTRACTID
Definition: YouTube.js:11
const Cr
Definition: YouTube.js:7
Element Properties href
return null
Definition: FeedWriter.js:1143
_updateDatepicker height
function url(spec)
const CID
Definition: YouTube.js:10
function NSGetModule(compMgr, fileSpec)
Definition: YouTube.js:125
const DESCRIPTION
Definition: YouTube.js:9
sbDeviceFirmwareAutoCheckForUpdate prototype classID
const Ci
Definition: YouTube.js:6
function YouTube()
Definition: YouTube.js:14