Large

YouTube HD Ultimate

By Avindra V.G. Last update Dec 10, 2010 — Installed 402,073 times.

No more fmt=18?

in
Subscribe to No more fmt=18? 13 posts, 8 voices



GhostNPC User
FirefoxWindows

I remember that this script used to always add the extra HQ-ness to old standard videos, but it doesn't seem to be doing it anymore.

http://www.youtube.com/watch?v=HVn5kQx8xL8 Check at 1:45 and on with the script, then check again by adding an fmt=18. The Use HD is indeed on.

 
Blue_Ninja0 User
FirefoxWindows

Not all videos have a HQ version available. That seems to be the case in that video.

 
GIJoe Scriptwright
SeamonkeyMacintosh

This video has a HQ version, but can only detected by loading the fmt=18 watch page.

 
Razor912 Scriptwright
FirefoxWindows

I noticed that also. I would love to see that functionality back

 
joeysazo Scriptwright
FirefoxWindows

I was annoyed enough by this too, so I fixed it.

So, replace lines 360-361 in 1.1.4:

if(unsafeWindow.isHDAvailable && !opts.useHD) swfArgs.fmt_map = unescape(swfArgs.fmt_map).replace(/^22[^,]+,/,"");
else if(swfArgs.fmt_map.indexOf("18")==0 && /3[45]/.test(swfArgs.fmt_map)) swfArgs.fmt_map=swfArgs.fmt_map.replace(/18.+?,/,"");

with this much longer block (I like spacing & comments):

/****************************************************************
// if not using HD or it's unavailable for this video, 
//  then get HQ (18 or 35) instead of whatever default fmt
//
// Each fmt_map entry is 5 fields separated by '/' starting with 
/   fmt number, and multiple entries are delimited by ','
//
// Note the following formats for reference (2009-10-16)
// fmt=0  -> flv:  320x240 (flv1) / mp3 1.0 22KHz (same as fmt=5)
// fmt=5  -> flv:  320x240 (flv1) / mp3 1.0 22KHz
// fmt=13 -> 3gp:  176x144 (mpg4) / ??? 2.0  8KHz
// fmt=17 -> 3gp:  176x144 (mpg4) / ??? 1.0 22KHz
// fmt=18 -> mp4:  480x360 (H264) / AAC 2.0 44KHz
// fmt=22 -> mp4: 1280x720 (H264) / AAC 2.0 44KHz
// fmt=34 -> flv:  320x240 (flv?) / ??? 2.0 44KHz (default now)
// fmt=35 -> flv:  640x380 (flv?) / ??? 2.0 44KHz
****************************************************************/

if (!opts.useHD || !unsafeWindow.isHDAvailable) {
    // unescape fmt_map for processing
    tmp_fmt_map = unescape(swfArgs.fmt_map);
            
    // get HQ if available, in this priority order
    // (35 typically has better resolution with the same audio quality)
    var fmt1 = tmp_fmt_map.search(/35(\/[^,]+){4}/);
    var fmt2 = tmp_fmt_map.search(/18(\/[^,]+){4}/);
    
    if (fmt1 != -1) {
        // move to the front of fmt_map if necessary
        if (fmt1 > 0) {
            tmp_fmt_map = tmp_fmt_map.substr(fmt1);
        }
        // remove any other formats to get rid of "HQ" icon
        var addlFmt1 = tmp_fmt_map.indexOf(",");
        if (addlFmt1 != -1) {
            tmp_fmt_map = tmp_fmt_map.substr(0, addlFmt1);
        }
    }
    else if (fmt2 != -1) {
        // move to the front of fmt_map if necessary
        if (fmt2 > 0) {
            tmp_fmt_map = tmp_fmt_map.substr(fmt2);
        }
        // remove any other formats to get rid of "HQ" icon
        var addlFmt2 = tmp_fmt_map.indexOf(",");
        if (addlFmt2 != -1) {
            tmp_fmt_map = tmp_fmt_map.substr(0, addlFmt2);
        }
    } 
    else if (document.URL.search("&fmt=18") == -1) {
        // brute force method for vids like watch?v=HVn5kQx8xL8
        //  which have a fmt=18 but youtube oddly doesn't show it in fmt_map
        document.location += "&fmt=18";
        // 2 notes:
        //  forcing 18 is much more likely to succeed than 35 for older vids
        //  for some reason, this may override color changes
    }
    else {
        // brute force didn't work, so remove HD and use whatever default format
        tmp_fmt_map = tmp_fmt_map.replace(/22(\/[^,]+){4},?/, "");
        tmp_fmt_map = tmp_fmt_map.replace(/,/g, "%2C");  // escape commas
    }

    // manually escape '/', since fmt_map is escaped by default
    swfArgs.fmt_map = tmp_fmt_map.replace(/\//g, "%2F");
}

The list of formats is from GIJoe's Youtube Enhancer script. Thanks for that!

So now you can listen to she in HQ. I kinda like their songs, have listened to a few in a row now.

cheers

 
digideth Scriptwright
FirefoxWindows

So is this going to be included in the 1.5 update that just came out a few minutes ago?

 
Avindra V.G. Script's Author
FirefoxWindows

I don't want to steal the code, but I do see what you guys are talking about. I'll work on it when I have time to play around with it.

 
joeysazo Scriptwright
FirefoxWindows

Feel free to use the code as you see fit, Avindra. Don't worry, you're not stealing one bit. I put it here so that people can use it if they want. Afterall, you've done me a much bigger favor by publishing this script in the first place!

BTW, per 1.1.5 there's one change - rename unsafeWindow.isHDAvailable to config.CFG_IS_HD_AVAILABLE. Thanks for making that fix yesterday!

 
Avindra V.G. Script's Author
FirefoxWindows

joey: I already made that change.

 
Andrew Frost User
ieWindows

Hi
In case anyone's still looking at this topic: we're trying to force YouTube to give us video in the H.264 480x360 format (fmt=18) by changing the fmt_map parameter to just contain that option (fmt_map=18/640x360/9/0/115) but all it gives us back is format 5 (FLV/Sorenson). This seemed to be a recent change, it was working okay up until a month or so ago. Has anyone else seen that or got any hints as to how we force YouTube to serve up video in H.264 baseline profile (fmt 18) rather than main/high profiles (fmts 34/35)?
thanks
Andrew

 
Avindra V.G. Script's Author
FirefoxWindows

Andrew Frost wrote:
all it gives us back is format 5
Are you using my script? When the only format is 5, there is no hope, lol. I just redirect the page, as you can see:

// ... (fmt 5 is assumed to exist)
if (swfArgs.fmt_stream_map.split(",").length == 1) {
	// 240p default, 360p secret
	if (location.search.indexOf("fmt=18")==-1) {
		location.replace(location.protocol + "//" + location.host +location.pathname + location.search + "&fmt=18" + location.hash);
		return;
	}
}
// ...

You're right, just messing with the fmt_map worked, but YouTube changed things. There are actually specific token values in the fmt_stream_map that you don't get until you actually go to the fmt=18 page, which is why I use this method.

YouTube relies too heavily on parameters (at least for video formats), in my opinion. They should clean it up...

 
Andrew Frost User
ieWindows

Thanks for the response. We're not using your script I'm afraid - we're actually implementing a Flash Player so sadly we can't redirect the page for this. Though I suspect this will make it into a 'readme' for us somewhere!

We'll also look into more details at fmt_stream_map and the other FlashVars that are being passed in, thanks for this hint.

Do you have any more details on this second part of the fmt_map items?
(RegExp.$1=="0" ? "512000" : "640x360")
e.g. what's the difference, does this have any impact? I'm assuming the first usage is a bitrate and the second is the resolution, and I think I've seen both in different videos.

cheers

 
Avindra V.G. Script's Author
FirefoxWindows

Andrew Frost wrote:
(RegExp.$1=="0" ? "512000" : "640x360")
That's actually when YouTube changed from the (as you also assume) the bitrate, to the resolution. I kept both in just in case, but I'm pretty sure they just use the resolution now. I haven't seen a fmt string with bitrates in a while, so I'm just assuming resolution from now on. This is done in r94.

As I say, I have no idea why YouTube can't just have the flash read these things off the damn stream, instead of having the parameters passed in.

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