sbHTMLPlaylistHandler.js
Go to the documentation of this file.
1 
31  this._originalURI = null;
32 }
33 
34 // sbIPlaylistReader
35 sbHTMLPlaylistHandler.prototype.__defineGetter__("originalURI",
36 function()
37 {
38  return this._originalURI;
39 });
40 
41 sbHTMLPlaylistHandler.prototype.__defineSetter__("originalURI",
42 function(value)
43 {
44  this._originalURI = value;
45 });
46 
47 sbHTMLPlaylistHandler.prototype.read =
48 function(aFile, aMediaList, aReplace)
49 {
50  var toAdd = [];
51 
52  var typeSniffer = Cc["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
53  .createInstance(Ci.sbIMediacoreTypeSniffer);
54 
55  // A fairly permissive regular expression to match href attributes. It will
56  // match href values that are surrounded by single or double quotes, or no
57  // quotes at all. It is also permissive about whitespace around the equals
58  // sign.
59  //
60  // The regular expression explained:
61  // match "href" then 0 or more characters of whitespace
62  // match "=" then 0 or more characters of whitespace
63  // capture an optional single or double quote
64  // non-greedy capture of everything up to...
65  // something that matches the first capture or a close angle bracket
66  //
67  // Note that the match we want shows up in the second capture
68  var re = new RegExp("href\\s*=\\s*(['\"])?(.*?)(?:\\1|>)", "ig");
69 
70  var self = this;
71  SB_ProcessFile(aFile, function(aLine) {
72 
73  var a = re.exec(aLine);
74  while (a && a.length == 3) {
75  var href = a[2];
76  var newUri = SB_ResolveURI(href, this._originalURI);
77  if (newUri && typeSniffer.isValidMediaURL(newUri)) {
78  var item = { uri: newUri, properties: {}};
79  toAdd.push(item);
80  }
81 
82  a = re.exec(aLine);
83  }
84 
85  }, this);
86 
87  SB_AddItems(toAdd, aMediaList, aReplace);
88 
89 }
90 
91 sbHTMLPlaylistHandler.prototype.vote =
92 function(aURL)
93 {
94  return 10000;
95 }
96 
97 sbHTMLPlaylistHandler.prototype.name =
98 function()
99 {
100  return "Songbird HTML Reader";
101 }
102 
103 sbHTMLPlaylistHandler.prototype.description =
104 function()
105 {
106  return "Scrape HREFs from HTML files.";
107 }
108 
109 sbHTMLPlaylistHandler.prototype.supportedMIMETypes =
110 function(aMIMECount)
111 {
112  var mimeTypes = ["text/html"];
113  aMIMECount.value = mimeTypes.length;
114  return mimeTypes;
115 }
116 
117 sbHTMLPlaylistHandler.prototype.supportedFileExtensions =
118 function(aExtCount)
119 {
120  var exts = ["html", "htm", "php", "php3", ""];
121  aExtCount.value = exts.length;
122  return exts;
123 }
124 
125 sbHTMLPlaylistHandler.prototype.QueryInterface =
126 function(iid)
127 {
128  if (!iid.equals(Ci.sbIPlaylistReader) &&
129  !iid.equals(Ci.nsISupports))
130  throw Cr.NS_ERROR_NO_INTERFACE;
131  return this;
132 }
133 
const Cc
Element Properties href
function sbHTMLPlaylistHandler()
return null
Definition: FeedWriter.js:1143
var uri
Definition: FeedWriter.js:1135
function SB_AddItems(aItems, aMediaList, aAddDistinctOnly)
countRef value
Definition: FeedWriter.js:1423
const Cr
const Ci
function SB_ResolveURI(aStringURL, aBaseURI)
function SB_ProcessFile(aFile, aCallback, aThis)
Process the file aFile line by line with the callback function aCallback.