linterna-magica-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linterna-magica-commit] [153] Changes for tasks #11216.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [153] Changes for tasks #11216.
Date: Mon, 25 Jul 2011 13:49:18 +0000

Revision: 153
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=153
Author:   valkov
Date:     2011-07-25 13:49:17 +0000 (Mon, 25 Jul 2011)
Log Message:
-----------
Changes for tasks #11216. Added rule to process the XHR response. All sites 
migrated to the new code. Dropped support for sites that do not exist anymore.

Ticket Links:
------------
    http://savannah.gnu.org/task/?11216

Modified Paths:
--------------
    branches/task-11216/src/lm_site_bliptv.js
    branches/task-11216/src/lm_site_boozhocom.js
    branches/task-11216/src/lm_site_dailymotion.js
    branches/task-11216/src/lm_site_myvideode.js
    branches/task-11216/src/lm_site_theonion.js
    branches/task-11216/src/lm_site_vbox7com.js
    branches/task-11216/src/lm_site_videoclipsdumpcom.js
    branches/task-11216/src/lm_site_vimeo.js
    branches/task-11216/src/lm_site_youtube.js
    branches/task-11216/src/lm_sites.js
    branches/task-11216/src/lm_xhr.js

Modified: branches/task-11216/src/lm_site_bliptv.js
===================================================================
--- branches/task-11216/src/lm_site_bliptv.js   2011-07-25 09:13:04 UTC (rev 
152)
+++ branches/task-11216/src/lm_site_bliptv.js   2011-07-25 13:49:17 UTC (rev 
153)
@@ -136,3 +136,41 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["blip.tv"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+    var xml = client.responseXML;
+
+    // All the data is available in the XML, but it is not a
+    // good idea to support the site in two places. JSON is
+    // easier. The drawback is two requests.
+    try
+    {
+       var embed_id =
+           xml.getElementsByTagName("embedLookup");
+
+       // Firefox
+       if (embed_id && typeof(embed_id[0]) == "undefined")
+       {
+           embed_id = 
+               xml.getElementsByTagName("blip:embedLookup");
+       }
+
+       object_data.video_id = embed_id[0].textContent;
+       this.request_bliptv_jsonp_data(object_data);
+    }
+    catch(e)
+    {
+       this.log("LinternaMagica.prototype.request_video"+
+                "_link_parse_response:\n"+
+                "Exception in Blip.tv while parsing XML",1);
+    }
+
+    // Do not process the XHR anymore. The video object will not be
+    // created.
+    return null;
+}

Modified: branches/task-11216/src/lm_site_boozhocom.js
===================================================================
--- branches/task-11216/src/lm_site_boozhocom.js        2011-07-25 09:13:04 UTC 
(rev 152)
+++ branches/task-11216/src/lm_site_boozhocom.js        2011-07-25 13:49:17 UTC 
(rev 153)
@@ -40,3 +40,17 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["boozho.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+    var xml = client.responseXML;
+
+    var rel_url = xml.getElementsByTagName("movie_path")[0].textContent;
+    object_data.link = "http://www.boozho.com/"+rel_url;
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_dailymotion.js
===================================================================
--- branches/task-11216/src/lm_site_dailymotion.js      2011-07-25 09:13:04 UTC 
(rev 152)
+++ branches/task-11216/src/lm_site_dailymotion.js      2011-07-25 13:49:17 UTC 
(rev 153)
@@ -137,3 +137,68 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["dailymotion.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+    if (!this.plugin_is_installed &&
+       !object_data.linterna_magica_id && 
+       !object_data.parent)
+    {
+       // In Dailymotion the script that creates the flash
+       // object replaces itself. The work around here is to
+       // request the page and process it. 
+
+       // Dailymotion uses pseudo-random ids for some DOM
+       // elements of interest. We replace the body HTML with
+       // the one returned by the XHR. Then scripts are
+       // processed. The script extraction code matches the
+       // correct ID for the parentNode in DOM, that will
+       // hold the video object. The original body is
+       // restored, because some data is missing in the body
+       // data from XHR. After all data is collected, the
+       // parentNode (object_data.parent), where the video
+       // object will be inserted is replaced with the one in
+       // the original body.  Custom function to match the
+       // parent by CSS class is used, because getElementById
+       // does not support regular expressions.
+
+       var body_data = 
+           client.responseText.split("<body")[1].
+           replace(/>{1}/,"__SPLIT__").
+           split("__SPLIT__")[1];
+
+       var body = document.getElementsByTagName("body")[0];
+       var original_body_data = body.innerHTML;
+
+       body.innerHTML = body_data;
+
+       this.script_data = client.responseText;
+       object_data = this.extract_object_from_script_swfobject();
+
+       body.innerHTML = original_body_data;
+
+       object_data.parent = 
+           this.get_first_element_by_class("dmpi_video_playerv[0-9]+");
+
+       if (!object_data.parent)
+       {
+           return null;
+       }
+    }
+
+    var hd_links = this.extract_dailymotion_links(client.responseText);
+    object_data.link = hd_links ? hd_links[hd_links.length-1].url : null;
+    object_data.hd_links = hd_links.length ? hd_links : null;
+
+    // See "A note on cookies"
+    if (/restore/i.test(this.process_cookies))
+    {
+       this.restore_cookies();
+    }
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_myvideode.js
===================================================================
--- branches/task-11216/src/lm_site_myvideode.js        2011-07-25 09:13:04 UTC 
(rev 152)
+++ branches/task-11216/src/lm_site_myvideode.js        2011-07-25 13:49:17 UTC 
(rev 153)
@@ -102,3 +102,24 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["myvideo.de"].process_xhr_response =
+function(args)
+{
+    var object_data = args.object_data;
+    var client = args.client;
+
+    try
+    {
+       var thumb_url = client.responseText.split(/image_src/)[1];
+       thumb_url = thumb_url.split(/\/\>/)[0].split(/\'/)[2];
+
+       object_data.link = this.create_myvideode_link(thumb_url);
+    }
+    catch(e)
+    {
+       return null;
+    }
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_theonion.js
===================================================================
--- branches/task-11216/src/lm_site_theonion.js 2011-07-25 09:13:04 UTC (rev 
152)
+++ branches/task-11216/src/lm_site_theonion.js 2011-07-25 13:49:17 UTC (rev 
153)
@@ -165,3 +165,16 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["theonion.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+   var onion_data = eval("("+client.responseText+")");
+    object_data.link = onion_data.video_url;
+    this.capture_theonion_clip_change(object_data);
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_vbox7com.js
===================================================================
--- branches/task-11216/src/lm_site_vbox7com.js 2011-07-25 09:13:04 UTC (rev 
152)
+++ branches/task-11216/src/lm_site_vbox7com.js 2011-07-25 13:49:17 UTC (rev 
153)
@@ -44,3 +44,14 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["vbox7.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+    object_data.link = client.responseText.split("=")[1].replace("&","");
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_videoclipsdumpcom.js
===================================================================
--- branches/task-11216/src/lm_site_videoclipsdumpcom.js        2011-07-25 
09:13:04 UTC (rev 152)
+++ branches/task-11216/src/lm_site_videoclipsdumpcom.js        2011-07-25 
13:49:17 UTC (rev 153)
@@ -42,3 +42,19 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["videoclipsdump.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+    var xml = client.responseXML;
+    var path = xml.getElementsByTagName("videoPath")[0];
+
+    if (path)
+    {
+       object_data.link = path.getAttribute("value");
+    }
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_vimeo.js
===================================================================
--- branches/task-11216/src/lm_site_vimeo.js    2011-07-25 09:13:04 UTC (rev 
152)
+++ branches/task-11216/src/lm_site_vimeo.js    2011-07-25 13:49:17 UTC (rev 
153)
@@ -161,3 +161,67 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["vimeo.com"].process_xhr_response =
+function(args)
+{
+    var object_data = args.object_data;
+    var client = args.client;
+    var xml = client.responseXML;
+
+    var rq_sig = xml.getElementsByTagName("request_signature");
+
+    rq_sig = rq_sig[0].textContent;
+
+    var rq_exp = xml.getElementsByTagName(
+       "request_signature_expires")[0].textContent;
+    var id = xml.getElementsByTagName("video")[0];
+    id= id.getElementsByTagName("nodeId")[0].textContent;
+
+    object_data.link = "http://www.vimeo.com/moogaloop/play/clip:"+
+       id+"/"+rq_sig+"/"+rq_exp+"/?q=sd";
+
+    // Check if there is HD clip
+    var is_hd = xml.getElementsByTagName("isHD");
+    if (is_hd && is_hd[0] && is_hd[0].textContent)
+    {
+       try
+       {
+           is_hd=parseInt(is_hd[0].textContent);
+       }
+       catch(e)
+       {
+           is_hd=0;
+       }
+    }
+
+    // HD links support only for clips that have it
+    if (is_hd)
+    {
+       object_data.hd_links = new Array();
+       var hd_link = new Object();
+
+       // Translate?
+       hd_link.label = "Low quality";
+       hd_link.url = object_data.link;
+       object_data.hd_links.unshift(hd_link);
+
+       hd_link = new Object();
+       // Translate?
+       hd_link.label = "High quality";
+       hd_link.url = object_data.link.replace(/q=sd/, "q=hd");
+       object_data.hd_links.unshift(hd_link);
+    }
+
+    // Vimeo web server sends the clips as
+    // video/mp4. totemNarrowSpace plugin (plays video/mp4)
+    // sends custom UA. This prevents the video to load. Must
+    // use video/flv, so totemCone plugin could start and send
+    // UA of the browser.  totemNarrowSpace/QuickTime plugin
+    // have other issues as well. Could be forced to
+    // video/flv, but there is a better fix in
+    // create_video_object();
+    object_data.mime = "video/mp4";
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_site_youtube.js
===================================================================
--- branches/task-11216/src/lm_site_youtube.js  2011-07-25 09:13:04 UTC (rev 
152)
+++ branches/task-11216/src/lm_site_youtube.js  2011-07-25 13:49:17 UTC (rev 
153)
@@ -379,3 +379,25 @@
 
     return result;
 }
+
+LinternaMagica.prototype.sites["youtube.com"].process_xhr_response =
+function(args)
+{
+    var client = args.client;
+    var object_data = args.object_data;
+
+    var fmt = this.extract_youtube_fmt_parameter(client.responseText);
+    var maps = this.extract_youtube_fmt_url_map(client.responseText);
+
+    var hd_links = this.create_youtube_links(fmt, maps);
+    object_data.link = hd_links ? hd_links[hd_links.length-1].url : null;
+    object_data.hd_links = hd_links.length ? hd_links : null;
+
+    // See "A note on cookies"
+    if (/restore/i.test(this.process_cookies))
+    {
+       this.restore_cookies();
+    }
+
+    return object_data;
+}

Modified: branches/task-11216/src/lm_sites.js
===================================================================
--- branches/task-11216/src/lm_sites.js 2011-07-25 09:13:04 UTC (rev 152)
+++ branches/task-11216/src/lm_sites.js 2011-07-25 13:49:17 UTC (rev 153)
@@ -237,14 +237,24 @@
     return false;
 }
 
+// Process the XHR response. 
+// Arguments 
+// An object:
+// {
+//     // XHR client object
+//     client: object,
+//     // The object that holds the extracted information about the flash
+//     // object
+//     object_data: object
+// }
+// Return value
+// object_data
+LinternaMagica.prototype.sites.__process_xhr_response =
+function(args)
+{
+    return true;
+}
 
-// LinternaMagica.prototype.sites.__extract_scripts_extract_when // Condition 
? DM /ted? 
-// LinternaMagica.prototype.sites.__wait_before_inserting_object_from-script 
// FB
-// LinternaMagica.prototype.sites.__extract_swfobject_regex
-// LinternaMagica.prototype.sites.__match_for_video_link
-// LinternaMagica.prototype.sites.__keep_amps_in_video_link
-// LinternaMagica.prototype.sites.__prepare_xhr
-// LinternaMagica.prototype.sites.__process_xhr_responce
 // LinternaMagica.prototype.sites.__insert_object_after_xhr
 
 // Check if site specific config and function exists and call it. If

Modified: branches/task-11216/src/lm_xhr.js
===================================================================
--- branches/task-11216/src/lm_xhr.js   2011-07-25 09:13:04 UTC (rev 152)
+++ branches/task-11216/src/lm_xhr.js   2011-07-25 13:49:17 UTC (rev 153)
@@ -124,266 +124,26 @@
        var host = window.location.hostname;
        var url;
        var mime= "video/flv";
-       var xml;
-       var hd_links = new Array();
 
-       if (client.responseXML)
-           xml = client.responseXML;
+       var self = this;
+       var val = this.call_site_function_at_position.apply(self,[
+           "process_xhr_response",
+           host, {client: client, object_data:object_data}]);
 
-       if (/vbox7\.com/i.test(host))
-           url = client.responseText.split("=")[1].replace("&","");
-
-       if (/vimeo\.com/i.test(host))
+       if (!val ||  typeof(val) == "boolean" || (val && !val.link))
        {
-           var rq_sig = xml.getElementsByTagName("request_signature");
-
-           rq_sig = rq_sig[0].textContent;
-
-           var rq_exp = xml.getElementsByTagName(
-               "request_signature_expires")[0].textContent;
-           var id = xml.getElementsByTagName("video")[0];
-           id= id.getElementsByTagName("nodeId")[0].textContent;
-
-           url = "http://www.vimeo.com/moogaloop/play/clip:"+
-               id+"/"+rq_sig+"/"+rq_exp+"/?q=sd";
-
-           // Check if there is HD clip
-           var is_hd = xml.getElementsByTagName("isHD");
-           if (is_hd && is_hd[0] && is_hd[0].textContent)
-           {
-               try
-               {
-                   is_hd=parseInt(is_hd[0].textContent);
-               }
-               catch(e)
-               {
-                   is_hd=0;
-               }
-           }
-
-           // HD links support only for clips that have it
-           if (is_hd)
-           {
-               var hd_link = new Object();
-
-               // Translate?
-               hd_link.label = "Low quality";
-               hd_link.url = url;
-               hd_links.unshift(hd_link);
-
-               hd_link = new Object();
-               // Translate?
-               hd_link.label = "High quality";
-               hd_link.url = url.replace(/q=sd/, "q=hd");
-               hd_links.unshift(hd_link);
-           }
-
-           // Vimeo web server sends the clips as
-           // video/mp4. totemNarrowSpace plugin (plays video/mp4)
-           // sends custom UA. This prevents the video to load. Must
-           // use video/flv, so totemCone plugin could start and send
-           // UA of the browser.  totemNarrowSpace/QuickTime plugin
-           // have other issues as well. Could be forced to
-           // video/flv, but there is a better fix in
-           // create_video_object();
-           mime = "video/mp4";
+           return null;
        }
-
-       if (/4videosharing\.com/i.test(host))
+       else
        {
-           var video_tag = xml.getElementsByTagName("video")[0];
-           url = video_tag.getElementsByTagName("src")[0].textContent;
+           object_data = val;
        }
 
-       // We should not be entering here anyway. It seems most
-       // objects have the mediaURL variable)
-       // if (/metacafe\.com/i.test(host))
-       // {
-       //     // The Content-type is not correct
-       //     xml = (new DOMParser()).
-       //      parseFromString(client.responseText,"application/xml");
-       //     var item = xml.getElementsByTagName("item")[0];
-       //     url = item.getAttribute("url");
-       // }
-
-       if (/vbox\.bg/i.test(host))
+       if (!object_data.mime)
        {
-           url = xml.getElementsByTagName("clip")[0].
-               getAttribute("url");
+           object_data.mime = mime;
        }
 
-       if (/boozho\.com/i.test(host))
-       {
-           var rel_url = xml.getElementsByTagName("movie_path")[0].
-               textContent;
-           url = "http://www.boozho.com/"+rel_url;
-       }
-
-       if (/vidoemo\.com/i.test(host))
-       {
-           var links_re = new RegExp(
-               "\\\<a.*href=\\\"([^\\\"]+).*\\\>Download\\\s*"+
-                   "(.*)\\\s*of\\\s*video",
-               "ig");
-
-           var links;
-           while (links = links_re.exec(client.responseText))
-           {
-               var hd_link = new Object();
-               hd_link.label = links[2];
-               hd_link.url = links[1];
-               hd_links.push(hd_link);
-
-               if (/flv/i.test(hd_link.label))
-               {
-                   url = hd_link.url;
-               }
-           }
-       }
-
-       if (/youtube\.com/i.test(host) ||
-           /youtube-nocookie\.com/i.test(host))
-       {
-           var fmt =
-               this.extract_youtube_fmt_parameter(client.responseText);
-           var maps =
-               this.extract_youtube_fmt_url_map(client.responseText);
-
-           hd_links = this.create_youtube_links(fmt, maps);
-           url = hd_links ? hd_links[hd_links.length-1].url : null;
-           // See "A note on cookies"
-           if (/restore/i.test(this.process_cookies))
-           {
-               this.restore_cookies();
-           }
-       }
-
-       if (/dailymotion\.com/i.test(host))
-       {
-           if (!this.plugin_is_installed &&
-               !object_data.linterna_magica_id && 
-               !object_data.parent)
-           {
-               // In Dailymotion the script that creates the flash
-               // object replaces itself. The work around here is to
-               // request the page and process it. 
-
-               // Dailymotion uses pseudo-random ids for some DOM
-               // elements of interest. We replace the body HTML with
-               // the one returned by the XHR. Then scripts are
-               // processed. The script extraction code matches the
-               // correct ID for the parentNode in DOM, that will
-               // hold the video object. The original body is
-               // restored, because some data is missing in the body
-               // data from XHR. After all data is collected, the
-               // parentNode (object_data.parent), where the video
-               // object will be inserted is replaced with the one in
-               // the original body.  Custom function to match the
-               // parent by CSS class is used, because getElementById
-               // does not support regular expressions.
-
-               var body_data = 
-                   client.responseText.split("<body")[1].
-                   replace(/>{1}/,"__SPLIT__").
-                   split("__SPLIT__")[1];
-
-               var body = document.getElementsByTagName("body")[0];
-               var original_body_data = body.innerHTML;
-
-               body.innerHTML = body_data;
-
-               this.script_data = client.responseText;
-               object_data = this.extract_object_from_script_swfobject();
-
-               body.innerHTML = original_body_data;
-
-               object_data.parent = 
-                   this.get_first_element_by_class("dmpi_video_playerv[0-9]+");
-
-               if (!object_data.parent)
-               {
-                   return null;
-               }
-           }
-
-           hd_links = this.extract_dailymotion_links(client.responseText);
-           url = hd_links ? hd_links[hd_links.length-1].url : null;
-
-           // See "A note on cookies"
-           if (/restore/i.test(this.process_cookies))
-           {
-               this.restore_cookies();
-           }
-       }
-
-       if (/myvideo\.de/i.test(host))
-       {
-           try
-           {
-               var thumb_url = client.responseText.split(/image_src/)[1];
-               thumb_url = thumb_url.split(/\/\>/)[0].split(/\'/)[2];
-               url = this.create_myvideode_link(thumb_url);
-           }
-           catch(e)
-           {
-               return;
-           }
-       }
-
-       if (/videoclipsdump\.com/i.test(host))
-       {
-           var path = xml.getElementsByTagName("videoPath")[0];
-           if (path)
-           {
-               url = path.getAttribute("value");
-           }
-       }
-
-       if (/theonion\.com/i.test(host))
-       {
-           var onion_data = eval("("+client.responseText+")");
-           url = onion_data.video_url;
-           this.capture_theonion_clip_change(object_data);
-       }
-
-       if (/blip\.tv/i.test(host))
-       {
-           // All the data is available in the XML, but it is not a
-           // good idea to support the site in two places. JSON is
-           // easier. The drawback is two requests.
-           try
-           {
-               var embed_id =
-                   xml.getElementsByTagName("embedLookup");
-
-               // Firefox
-               if (embed_id && typeof(embed_id[0]) == "undefined")
-               {
-                   embed_id = 
-                       xml.getElementsByTagName("blip:embedLookup");
-               }
-
-               object_data.video_id = embed_id[0].textContent;
-               this.request_bliptv_jsonp_data(object_data);
-           }
-           catch(e)
-           {
-               this.log("LinternaMagica.prototype.request_video"+
-                        "_link_parse_response:\n"+
-                        "Exception in Blip.tv while parsing XML",1);
-           }
-           return null;
-       }
-
-       if (!url)
-       {
-           return;
-       }
-
-       object_data.link = url;
-       object_data.mime = mime;
-       object_data.hd_links = hd_links.length ? hd_links : null;
-
        // FIXME HTML5 in WebKit switch like for flash plugin ?
        // In the next release 0.0.10 ?!
        if (!/youtube\.com/i.test(window.location.host) &&
@@ -398,7 +158,7 @@
                     "Removing plugin install warning.",2);
            this.remove_plugin_install_warning(object_data.parent);
            this.log("LinternaMagica.request_video_link_parse response:\n"+
-                    "Creating video object with url: "+url,1);
+                    "Creating video object with url: "+object_data.link,1);
            this.create_video_object(object_data)
        }
        else if ((/youtube\.com/i.test(window.location.host) ||




reply via email to

[Prev in Thread] Current Thread [Next in Thread]