Add support for telecinco.es
[GM_direct_download_links.git] / direct_download_links.user.js
index 6fa53ed..e79d916 100644 (file)
@@ -1,7 +1,7 @@
 // direct_download_links - Add direct download links
-// version 0.3
-// 2011-12-23
-// Copyright (C) 2011  Antonio Ospite <ospite@studenti.unina.it>
+// version 0.4
+// 2012-02-12
+// Copyright (C) 2011,2012  Antonio Ospite <ospite@studenti.unina.it>
 // Released under the GPL license
 // http://www.gnu.org/copyleft/gpl.html
 //
@@ -29,6 +29,7 @@
 // @include        http://www.kataweb.it/tvzap/*
 // @include        http://www.rai.tv/*
 // @include        http://soundcloud.com/*
+// @include        http://www.telecinco.es/*
 // ==/UserScript==
 //
 
@@ -78,7 +79,7 @@ var supported_sites = [
   {
     locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/,
     urlContainerXPath: '//div[@id="contA"]',
-    urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/,
+    urlRegexp: /[^\/]addParam\('format', '[^']*', '((http|mms):\/\/[^']*)'/,
     linkDestXPath: '//div[@id="contA"]',
   },
   {
@@ -98,14 +99,14 @@ var supported_sites = [
     locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/,
     urlContainerXPath: '//div[@id="tvzap_video"]',
     urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/,
-    linkDestXPath: '//div[@id="playerCont"]',
+    linkDestXPath: '//div[@id="tvzap_video"]',
   },
   {
     locationRegexp: /^http:\/\/www\.rai\.tv\/.*$/,
-      initCommand: function(site) {
-        unsafeWindow.Silverlight.isInstalled = function(version) {
-          return true;
-        };
+    initCommand: function(site) {
+      unsafeWindow.Silverlight.isInstalled = function(version) {
+        return true;
+      };
     },
     urlContainerXPath: '//div[@id="silverlightControlHost" or @id="SilverlightPlayer"]',
     urlRegexp: /mediaUri=(http:\/\/[^,]*)/,
@@ -119,6 +120,12 @@ var supported_sites = [
     urlRegexp: /"streamUrl":"([^"]*)"/,
     linkDestXPath: '//div[@id="main-content-inner"]',
   },
+  {
+    locationRegexp: /^http:\/\/www\.telecinco.es\/.*$/,
+    urlContainerXPath: '//video[@class="video-js"]',
+    urlRegexp: /src="([^"]*)"/,
+    linkDestXPath: '//div[@class="pg-bd"]',
+  },
 ];
 
 /* Apply different rules to different sites */
@@ -138,6 +145,13 @@ function getElementByXPath(query, root) {
   return document.evaluate(query, root || document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
 }
 
+/* from http://stackoverflow.com/questions/1912501 */
+function htmlDecode(input){
+  var e = document.createElement('div');
+  e.innerHTML = input;
+  return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
+}
+
 /**
  * Add a Direct Download link on the page for the specified URL
  *
@@ -146,7 +160,7 @@ function getElementByXPath(query, root) {
  * @return: null on error, true on success
  */
 function direct_download_link_add(pageURL, site) {
-  site.pageURL = pageURL
+  site.pageURL = pageURL;
   var element = getElementByXPath(site.urlContainerXPath);
   if (!element) {
     DDL_log('DirectDL (' + site.pageURL  + '): Cannot find the element ' + site.urlContainerXPath + ' containing the URL.');
@@ -198,7 +212,7 @@ function _get_URL(site, element) {
   var evt = document.createEvent('Event');
   evt.initEvent('UrlFetched', true, true);
   evt.site = site;
-  evt.URL = URL;
+  evt.URL = htmlDecode(URL);
   document.dispatchEvent(evt);
 }