Show youtube video length

in Ideas and script requests
Subscribe to Show youtube video length 18 posts, 4 voices



TwinScript Scriptwright
OperaWindows

I'm hoping something like this already exists, but I can't find anything.

I have a userscript 'Disable Youtube Autoplay' (http://userscripts.org/scripts/show/100858)

Unfortunately there is no way to get an indication of the length of the current video unless you press play.

I'm hoping there is a userscript that can give an indication of the video length without clicking play.

 
mike cupcake Scriptwright
FirefoxWindows

I see the length beside the play and volume buttons. Installing that script doesn't stop it being shown in either the flash or HTML5 player (although it does fail to prevent HTML5 auto-play).

Maybe another script/plugin is causing you problems?

In any case, the page code contains references to length_seconds%3d359 , where %3d is a URI-encoded = and 359 is the video length in seconds. So yes, you should be able to access this information from a userscript.

 
TwinScript Scriptwright
OperaWindows

http://s11.postimage.org/z2r0uypjn/Youtube_No_A...

I don't see the length anywhere, pic related. In order to see it I have to press play, which plays the video and defeats the whole purpose of having a script to disable autoplay.

See, I don't want to load the video unless I know how long it is first. This in particular is very important.

 
Jefferson Scher Scriptwright
FirefoxWindows

What is the player you have in that image? I've never seen it before.

 
mike cupcake Scriptwright
FirefoxWindows

Yep that's no official youtube player, they'd never include a download link :-)

 
TwinScript Scriptwright
OperaWindows

It's a different userscript that provides the download link. I don't actually use it, but it's there if I need it.

The 'player'? That is Opera's standard flash blocking policy that very neatly integrates into youtube, meaning you have to press play to enable the video. I wish other browsers would have that feature implemented by default.

 
mike cupcake Scriptwright
FirefoxMacintosh

Are you being deliberately confusing?

 
TwinScript Scriptwright
OperaWindows

Reread the thread title: I need a userscript that will "Show youtube video length" without clicking play on the video. I don't care where the length is shown, though I figured a good spot would be just below the video on the right.

A simple 1:36 for a one minute thirty six second video. How is that confusing?

 
AmpliDude Scriptwright
FirefoxWindows

First of all you can go to Opera preferences -> Advanced -> Content and uncheck 'Enable plug-ins only on demand' if you don't like the idea of press to play.

Second - you can get the length in seconds from:
window.yt.playerConfig.args.length_seconds

 
TwinScript Scriptwright
OperaWindows

I know about that first point, and who in their right mind would uncheck that? It's one of the few things that Opera has built-in that makes youtube autoplay/autobuffer blocking scripts unnecessary, which is fantastic.

How would I go about utilizing the 'window.yt.playerConfig.args.length_seconds' code? I'm not a script writer.

 
Jefferson Scher Scriptwright
FirefoxWindows

In Opera, can you still run JavaScript from the address bar? If so, try this on a sample page to see whether the variable is set:

javascript:alert(window.yt.playerConfig.args.length_seconds);

Or perhaps there is a script console that you would use instead, omitting the protocol:

alert(window.yt.playerConfig.args.length_seconds);

If the value is defined and non-zero, then you can access it in your script.

 
TwinScript Scriptwright
OperaWindows

I just pasted the first script into the address bar on a youtube page and pressed enter. It correctly returned the video length in the alert.

The second link returned an invalid URL, but maybe that's just because I tried running it directly from the address bar.

 
Jefferson Scher Scriptwright
FirefoxWindows

Cool, so now how you do want the information displayed in the page by your userscript? Perhaps:

// ==UserScript==
// @name        Video Length After Title
// @namespace   YourNameHere
// @include     http*://www.youtube.tld/watch*
// @version     1
// ==/UserScript==

function ShowRunningTime(e){
  if (window.self != window.top) return;
  var emb = document.querySelector('#movie_player');
  if (!emb){
    window.setTimeout(ShowRunningTime, 250); // doesn't work??
    return;
  }
  var fvars = emb.getAttribute("flashvars");
  fvars = fvars.substr(fvars.indexOf("length_seconds=") + "length_seconds=".length);
  var trt = fvars.split("&")[0];
  var vidtitle = document.getElementById("watch-headline-title");
  if (trt > 0 && vidtitle){
    var min = Math.floor(parseInt(trt)/60);
    var sec = parseInt(trt) - (min * 60);
    vidtitle.appendChild(document.createTextNode(" (trt: " + min + ":" + sec + ")"));
  }
}
ShowRunningTime();

I only tested that on Firefox in Greasemonkey and I'm not blocking Flash. YMMV.

 
TwinScript Scriptwright
OperaWindows

Had to change the include line to * (not all youtube links have .tld in them), but it works brilliantly in both Opera and Firefox, though for some odd reason not in Chrome (Tampermonkey extension).

 
Jefferson Scher Scriptwright
FirefoxWindows

.tld is a magic wildcard for known TLDs, but perhaps only Greasemonkey itself supports it. (I don't test in Opera or Chrome.)

 
TwinScript Scriptwright
OperaWindows

I wonder what could be causing Chrome to fail. Oh well, it works in Opera and that was the main goal, as Opera has the best flash blocking abilities.

Do you mind if I publish it as a userscript (with you in the credits of course) or would you prefer to publish it yourself?

 
Jefferson Scher Scriptwright
FirefoxWindows

Go for it. Then you get the pleasure of responding to requests for fixes and enhancements. ;-)

 
TwinScript Scriptwright
OperaWindows

Fine, I'll forward the requests to you. Nahh.

Though it probably won't need fixing. I don't really expect it to break.