Capture even more youtube embed able content - preserve time shortcutting #50

Merged
merged 3 commits into from Oct 30, 2011
View
38 js/tv.js
@@ -47,7 +47,7 @@ var globals = {
'trutv.com', 'twitvid.com', 'ustream.com', 'viddler.com', 'video.google.com',
'video.nationalgeographic.com', 'video.pbs.org', 'video.yahoo.com', 'vids.myspace.com', 'vimeo.com',
'wordpress.tv', 'worldstarhiphop.com', 'xtranormal.com',
- 'youtube.com', 'zapiks.com'
+ 'youtube.com', 'youtu.be', 'zapiks.com'
]
,videos: []
@@ -267,23 +267,16 @@ function loadChannel(channel, video_id) {
globals.videos[this_chan] = {};
globals.videos[this_chan].video = []; //clear out stored videos
for(var x in data.data.children){
- if(!isEmpty(data.data.children[x].data.media_embed)
- && isVideo(data.data.children[x].data.media.type)
- && (data.data.children[x].data.score > 1)
- )
- {
- globals.videos[this_chan].video.push(data.data.children[x].data);
- }
- //if reddit's scrape didn't build the embed, built it ourself
- else if(data.data.children[x].data.domain == 'youtube.com'
- || data.data.children[x].data.domain == 'youtu.be'
- )
- {
- var created = youtube.createEmbed(data.data.children[x].data.url);
- data.data.children[x].data.media_embed.content = created.embed;
- data.data.children[x].data.media = {};
- data.data.children[x].data.media.oembed = {};
- data.data.children[x].data.media.oembed.thumbnail_url = created.thumbnail;
+ if(isVideo(data.data.children[x].data.domain) && (data.data.children[x].data.score > 1)){
+ if(isEmpty(data.data.children[x].data.media_embed)){
+ var created = createEmbed(data.data.children[x].data.url, data.data.children[x].data.domain);
+ if(created !== false){
+ data.data.children[x].data.media_embed.content = created.embed;
+ data.data.children[x].data.media = {};
+ data.data.children[x].data.media.oembed = {};
+ data.data.children[x].data.media.oembed.thumbnail_url = created.thumbnail;
+ }
+ }
if(data.data.children[x].data.media_embed.content){
globals.videos[this_chan].video.push(data.data.children[x].data);
}
@@ -685,6 +678,15 @@ function isUserChan(channel){
return false;
}
+function createEmbed(url, type){
+ switch(type){
+ default:
+ return false;
+ case 'youtube.com': case 'youtu.be':
+ return youtube.createEmbed(url);
+ }
+}
+
function prepEmbed(embed, type){
switch(type){
default:
View
24 js/tv.youtube.js
@@ -36,25 +36,27 @@ var youtube = {
}
,createEmbed: function(url){
- var ID, parts, data = {};
+ var ID, time, parts, data = {};
- if(url.match(/youtu\.be/)){
+ consoleLog('url: '+url);
+
+ time = url.match(/(&|&|\?)t=([HhMmSs0-9]+)/);
+ time = time !== null ? '&' + time[0].replace(/(&|\?)/gi, '') : '';
+ consoleLog('time: '+time);
+
+ if(url.match(/(\?v\=|&v\=|&v=)/)){
+ parts = url.split('v=');
+ ID = parts[1].substr(0,11);
+ consoleLog('youtube ID: '+ID);
+ }else if(url.match(/youtu\.be/)){
parts = url.split("/");
ID = parts[3].substr(0,11);
consoleLog('youtu.be ID: '+ID);
}
-
- if(url.match('youtube.com')){
- if(url.match(/\?v\=/)){
- parts = url.split('?v=');
- ID = parts[1].substr(0,11);
- consoleLog('youtube.com ID: '+ID);
- }
- }
if(ID){
data.embed = "<object width=\"600\" height=\"338\"><param name=\"movie\" value=\"http://www.youtube.com/v/"
- +ID+"?version=3&feature=oembed\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+ID+"?version=3&feature=oembed\" type=\"application/x-shockwave-flash\" width=\"600\" height=\"338\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed></object>";
+ +ID+"?version=3&feature=oembed"+time+"\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+ID+"?version=3&feature=oembed"+time+"\" type=\"application/x-shockwave-flash\" width=\"600\" height=\"338\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed></object>";
data.thumbnail = "http://i2.ytimg.com/vi/"+ID+"/hqdefault.jpg";
return data;
}else{