---
 modules/page-modes/youtube.js |   44 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/modules/page-modes/youtube.js b/modules/page-modes/youtube.js
index ebcbf5a..4064199 100644
--- a/modules/page-modes/youtube.js
+++ b/modules/page-modes/youtube.js
@@ -30,9 +30,53 @@ function media_scrape_youtube(buffer) {
     return null;
 }
 
+
+// From http://userscripts.org/scripts/source/25105.user.js
+function youtube_mp4(buffer) {
+  var document = buffer.document;
+
+  if (document.getElementById('download-youtube-video')) return;
+
+  var video_id = null;
+  var video_hash = null;
+  var video_player = document.getElementById('movie_player');
+
+  if (video_player) {
+    var flash_variables = video_player.attributes.getNamedItem('flashvars');
+    if (flash_variables) {
+      var flash_values = flash_variables.value;
+      if (flash_values) {
+        var video_id_match = flash_values.match(/video_id=([^(\&|$)]*)/);
+        if (video_id_match!=null) video_id = video_id_match[1];
+        var video_hash_match = flash_values.match(/t=([^(\&|$)]*)/);
+        if (video_hash_match!=null) video_hash = video_hash_match[1];
+      }
+    }
+  }
+
+  if (video_id==null || video_hash==null) {
+    var args = unsafeWindow.swfArgs;
+    if (args) {
+      video_id = args['video_id'];
+      video_hash = args['t'];
+    }
+  }
+
+  if (video_id==null || video_hash==null) return;
+
+   var yt_mp4_path 
='http://www.youtube.com/get_video?fmt=18&video_id='+video_id+'&t='+video_hash;
+   var div_embed = document.getElementById('watch-embed-div');
+
+   if (div_embed) {
+      div_embed.innerHTML = div_embed.innerHTML + '<br /> <span 
id=\'download-youtube-video\'> <a href=\''+yt_mp4_path+'\'>Download as MP4</a> 
'+'</span>';
+  }
+
+}
+
 define_page_mode("youtube_mode", "YouTube", $enable = function (buffer) {
     buffer.local_variables.media_scraper = media_scrape_youtube;
     media_setup_local_object_classes(buffer);
+    add_hook.call(buffer, "content_buffer_finished_loading_hook", youtube_mp4);
 });
 
 auto_mode_list.push([media_youtube_uri_test_regexp, youtube_mode]);
-- 
1.5.5
_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to