Skip to content

Instantly share code, notes, and snippets.

@ChlorideCull
Created May 4, 2014 01:00
Show Gist options
  • Save ChlorideCull/7025358f2ed731e453a0 to your computer and use it in GitHub Desktop.
Save ChlorideCull/7025358f2ed731e453a0 to your computer and use it in GitHub Desktop.
Quick UserScript to add a link to the highest quality video stream below the video.
// ==UserScript==
// @name ExternalPlayer
// @description Adds a link to show the video in an external player.
// @include http*://www.youtube.com/watch*
// ==/UserScript==
var playerparent = document.getElementById("player");
var newplayer = document.createElement("a");
newplayer.style.position = "relative";
newplayer.style.padding = "20px";
newplayer.style.top = "10px";
newplayer.style.zIndex = "2";
playerparent.appendChild(newplayer);
for (i = 0; i < playerparent.children.length; i++)
{
if (playerparent.children[i].nodeName == "SCRIPT")
{
var streammap = playerparent.children[i].innerHTML.match("stream_map\": \"(.*?)?\"");
if (streammap == null)
{
continue;
} else {
var maparray = streammap[0].replace(/\\u0026/g, "&").substring(14).split(",");
//First ID is best quality on all videos I've seen
var metadata = maparray[0].split("&");
for (i = 0; i < metadata.length; i++)
{
if (metadata[i].substring(0, 4) == "url=")
{
newplayer.href = decodeURIComponent(metadata[i].substring(4));
}
else if (metadata[i].substring(0, 8) == "quality=")
{
newplayer.innerHTML = metadata[i].substring(8).toUpperCase() + " (External Player)";
}
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment