Skip to content

Instantly share code, notes, and snippets.

@garsue
Last active December 16, 2015 11:29
Show Gist options
  • Save garsue/5427405 to your computer and use it in GitHub Desktop.
Save garsue/5427405 to your computer and use it in GitHub Desktop.
(function (global, $){
var isScript = function (elem) {
return elem.hasOwnProperty("tagName") && elem.tagName.toUpperCase() === "SCRIPT";
};
var extractAsJson = function (line) {
var startStr = "var info =";
var striped = line.strip();
if (striped.startsWith(startStr)) {
var ret = striped.substr(startStr.length, striped.length - startStr.length - 1);
return ret.evalJSON();
}
return null;
};
var convertFormatStr = function (formatStr) {
var format = "_";
switch (formatStr) {
case "sd":
format = "_";
break;
case "hd720":
format = "_hd_";
break;
default:
format = "_" + formatStr + "_";
break;
}
return "stream_h264" + format + "url";
};
var searchInfo = function (lines) {
$.each(lines, function (k, line) {
var info = extractAsJson(line);
if (info !== null) {
format = convertFormatStr(info.available_formats.last());
console.log(info);
console.log(format);
var url = info[format];
console.log(url);
location.href = url;
}
});
};
if (location.protocol === "http") {
// Use https to commit same origin policy
location.protocol = "https";
}
var m = document.getElementsByTagName("meta");
var url = null;
$.each(m, function(k, v) {
// Find embed url
if (v.getAttribute("name") === "twitter:player") {
url = v.getAttribute("value");
}
});
console.log(url);
$.get(url.replace("https", "http")).done(function(data){
$.each($(data), function(k, elem) {
if (isScript(elem)) {
lines = elem.innerHTML.split("\n");
searchInfo(lines);
}
});
console.log("Done!");
});
}(this, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment