X-Git-Url: https://git.ao2.it/GM_direct_download_links.git/blobdiff_plain/5175c992803297edf8c7acd5faaba0aa38c5be8b..c0822563e49f1dcca21a6c78064f10f4f06943fc:/direct_download_links.user.js diff --git a/direct_download_links.user.js b/direct_download_links.user.js index 9344012..11932f8 100644 --- a/direct_download_links.user.js +++ b/direct_download_links.user.js @@ -1,7 +1,7 @@ // direct_download_links - Add direct download links -// version 0.3 -// 2011-12-23 -// Copyright (C) 2011 Antonio Ospite +// version 0.4 +// 2012-02-12 +// Copyright (C) 2011,2012 Antonio Ospite // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // @@ -78,7 +78,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,20 +98,20 @@ 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="Player"]', + urlContainerXPath: '//div[@id="silverlightControlHost" or @id="SilverlightPlayer"]', urlRegexp: /mediaUri=(http:\/\/[^,]*)/, onEvent: { evt: 'DOMNodeInserted', targetElement: 'object' }, processURL: _rai_get_actual_url, - linkDestXPath: '//div[@id="Player"]', + linkDestXPath: '//div[@id="silverlightControlHost" or @id="SilverlightPlayer"]', }, { locationRegexp: /^http:\/\/soundcloud.com\/.*$/, @@ -138,6 +138,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,6 +153,7 @@ function getElementByXPath(query, root) { * @return: null on error, true on success */ function direct_download_link_add(pageURL, site) { + site.pageURL = pageURL; var element = getElementByXPath(site.urlContainerXPath); if (!element) { DDL_log('DirectDL (' + site.pageURL + '): Cannot find the element ' + site.urlContainerXPath + ' containing the URL.'); @@ -197,7 +205,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); } @@ -267,9 +275,21 @@ function _rai_get_actual_url(site, URL) { parser = new DOMParser(); xmlDoc = parser.parseFromString(text, "text/xml"); - ref = xmlDoc.getElementsByTagName('REF'); - if (ref.length > 0) { - href = ref[0].getAttribute('HREF');; + // MMS streams + elems = xmlDoc.getElementsByTagName('REF'); + if (elems.length > 0) { + href = elems[0].getAttribute('HREF');; + + var evt = document.createEvent('Event'); + evt.initEvent('UrlFetched', true, true); + evt.site = site; + evt.URL = href; + document.dispatchEvent(evt); + } + // SmoothStreaming streams + elems = xmlDoc.getElementsByTagName('playListItem'); + if (elems.length > 0) { + href = elems[0].getAttribute('mediaSource');; var evt = document.createEvent('Event'); evt.initEvent('UrlFetched', true, true);