Youtube Alternate Video Player

By Yansky Last update Dec 23, 2008 — Installed 25,067 times.

"Hack" for HD Streams / new widescreen layout

in
Subscribe to "Hack" for HD Streams / new widescreen layout 15 posts, 5 voices



tecker User
Im calling this a "hack" as it was a quick and unauthorized addition that was tested to the point where it works for me.

See below for newer, more complete uploaded version

I got bored over the weekend and added some code for switching to High Qualith Streams. It required two sections:

Section 1 in the header between scrWithT and pD

var quallink = '<a style="text-decoration:none" href="'+document.location.toString()+'&fmt=18">Watch in High Quality</a>';
var qual = 'Regular';
if (document.location.toString().indexOf("fmt=18") != -1){
	qual = 'High';
	quallink = '<a style="text-decoration:none" href="'+document.location.toString().split("&fmt=",1) +'">Watch in Regular Quality</a>';
	srcWithT = 'http://'+document.domain+'/get_video?fmt=18&video_id='+vidID+'&t='+fv.split("&t=")[1].split("&")[0];
}

Section 2 is in the pD.innerHTML = section apended to the end.

<br><div width="480"><div style="float:left;">Playing '+ qual +' Quality</div>'+
		'<div style="float:right;" align="right">'+quallink+'</div><div style="clear: both;"></div></div>

Let me know what you think. It really was just a quick hack but if you want some help then I can help refine it.

 
tecker User
Well Im back at it. These changes might reflect for me only. Please let me know if you are seeing the new formats.

See below for newer, more complete uploaded version

Youtube just changed their site in prep for the new Widescreen HD streams. There for the following addtions/changes can be made to fit the new layout better.

1) Change the width = 480 to 640 and it will stretch out flowplayer.

2) Change initialScale: \'scale\' to initialScale: \'fit\'. This will help preserve the aspect ratios. Some videos will actually take advantage of the new system provided you watch them in format 18.

3) Youtube moved the quality link out and it will appear annoyingly at times. Add the following to hide it everytime.
Add this after the var pD = line

var ytQualLink = document.getElementById('watch-video-quality-setting');

Then after the pD.innerHTML section add this

if (ytQualLink) {
   	ytQualLink.parentNode.removeChild(ytQualLink);
}

 
tecker User
Still at it.

See below for newer, more complete uploaded version

Now that the widescreen has been enabled the format 22 (HD Streams) can be hacked in. Section 1 in the header between scrWithT and pD now becomes more complex to:

var quallink = 'Switch to: <a style="text-decoration:none" href="'+document.location.toString()+'&fmt=18">High Quality</a>/
<a style="text-decoration:none" href="'+document.location.toString()+'&fmt=22">HD Quality</a>'; var qual = 'Regular'; if (document.location.toString().indexOf("fmt=18") != -1){ qual = 'High'; quallink = 'Switch to: <a style="text-decoration:none" href="'+document.location.toString().split("&fmt=",1) +'">Regular Quality</a>/
<a style="text-decoration:none" href="'+document.location.toString().split("&fmt=",1) +'&fmt=22">HD Quality</a>'; srcWithT = 'http://'+document.domain+'/get_video?fmt=18&video_id='+vidID+'&t='+fv.split("&t=")[1].split("&")[0]; } if (document.location.toString().indexOf("fmt=22") != -1){ qual = 'HD'; quallink = 'Switch to: <a style="text-decoration:none" href="'+document.location.toString().split("&fmt=",1) +'">Regular Quality</a>/
<a style="text-decoration:none" href="'+document.location.toString().split("&fmt=",1) +'&fmt=18">High Quality</a>'; srcWithT = 'http://'+document.domain+'/get_video?fmt=22&video_id='+vidID+'&t='+fv.split("&t=")[1].split("&")[0]; }

This will let you switch back and forth between Standard/High/HD. And the new format 22 HD looks amazing but eats your system resources like crazy.

 
fattie Scriptwright

I can't get the code to work. My editor seems to be confused about the syntax when I put it in the corresponding spots. I don't know if you could possibly email me the .js or something?

 
tecker User
Newer, more complete uploaded version

Try this link: Tecker Modified Version V1.0tm4
(http://hockersmith.net/FirefoxHacking/youtube_a...)


I just threw this up on my website. Let me know if it works for you.
 
tecker User
[edit, the code that was posted here was incomplete so I'm retracting it. See below for explanation.]

The uploaded file linked above has been HEAVILY modified. I have made a default format ability and to track when you have switched from the default to what ever else you picked.

The number of changes are enormous (Yansky if you need help understanding let me know) so I will not list them here.

I have finally reached a point where it behaves as I want it to.
Expected Behavior:
  • Standard Youtube Link is set to the default and played at desired level
  • Youtube links with a format attached (ex url&fmt=18&whoop) are played as linked
  • Unknown formats are honored and indicated by a message to the lower right of the player
  • Format switches are available to switch to other qualities.
  • Format can switch regardless of "&fmt=" position in the url

Caveat: Only drawback is in the default system causes a page refresh and will cause another entry in the history. This makes going back harder as the script will constantly push you back forward. To beat this you have to quickly go back 2 times to get to the linking page or the original page.
FIXED. See below.

Please test and let me know what happens. Thanks.
 
tecker User

Fixed the caveat. Version 1.0tm4 (Tecker Mod 4) has been uploaded. See above for new version. In fixing the code I was able to clean it up a little as well and make it a little less complex.

Now the handling of the default is all interal to the script and does not require you to refresh the page. This should make back and page navigation easier.

 
leecovuk User

Thanks Tecker, I'm trying this out.

Can I ask, can I simply replace the code exactly as suggested by Yansky in another thread, to revert the player in your revised code to the old player?

I like the way you've made/kept the default playback quality as non-HQ (I think you have anyway). My old Pentium III struggles with streaming normal Flash at the best of times, let alone high quality clips.
:)

Lee
UK

 
desert User

Firefox update 3.0.5 breaks this nice script ? at least on my pc
still working with 3.0.4 though

 
tecker User

Interesting. Im noticing that exact same behavior as you mentioned. I will see what I can find but this may be related to an XSS bug fix and may stem from either a problem in greasemonkey or the way we are doing the script.

 
tecker User

[note: Script broken in 3.0.5. Am looking for workaround.]

FOUND IT.
Mozilla disabled a function call that we need to get the string back from youtube.

http://www.mozilla.org/security/announce/2008/m... states that due to the XMLHttpRequest vulnerability they implemented the following workaround:
"Disable JavaScript [function] until a version containing these fixes can be installed."

Way to go fellas. Coulda let some of us who USE that function know that you were going to get rid of it. Thanks. I will see if there is a greasemonkey call that we can make to fix this.

 
Yansky Script's Author

@ tecker
I've updated the code for the script and I think it should work ok with the new firefox XMLHttpRequest fix.

Feel free to make a new userscript with your HD version. I personally am logged into youtube most of the time, so I almost always have "HD" enabled in my youtube settings, but I realise a lot of people don't do it that way so if you create a new userscript, I will put a link to it on this scripts page.

BTW, all my scripts are released with a CC license, so you can do just about anything you want with them. :)
http://creativecommons.org/licenses/by-sa/3.0/

 
tecker User

I had stumbled upon that last night. I think that you should use this as a stop gap only. Here's why:

GM_XMLHttpRequest will actually download the full video when called the way you have it implemented (onload). The standard XMLHttpRequest could be polled in the middle to check to see when youtube passed us off and then just grab the new URL and run. GM_XMLHttpRequest does not have a reliable way of doing this. Trying to catch it mid request (onstatechange) will cause really bad script hangs and processor loads.

Currently the video will download 2 times. First time to get just the URL the second time to actually load the video into FlowPlayer. I think that we should watch the changelogs to see when this is fixed (3.1 maybe?) as I prefer the old method. Or greasemonkey could just fix the dang bug.

Your code on this version however is nicely minimal.

 
Yansky Script's Author

Try it now.

 
tecker User
Woah wait a tick. How did you pull that off? I could have sworn I had tried that but it didnt load. Hmmm. Maybe I didnt trigger it correctly.

[edit]
Hmmmmm... I didnt encode the string though. I was just pulling the srcWithT variable not a URIecnoded version. Good revisit. This restores the script once again to my active status. Oh and yet again you simplified the code. I honestly dont think this is going to get any simpler. (you might surprise me though.)
[/edit]
Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel