Created
October 24, 2015 22:02
-
-
Save ikouchiha47/28fca865455f0a9389f8 to your computer and use it in GitHub Desktop.
youtube downoader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var you = function(h, D) { | |
var frag = D.createDocumentFragment(), | |
count = 0, | |
len = 1; | |
h("#yt-masthead-content").appendChild(m("div", "", {className: "download"}, {paddingRight: "20px", height: "200px", overflowY: "scroll"})) | |
function addLinks(d, r) { | |
h(".download").appendChild(m("a", | |
d.title, | |
{className: "links", href: d.url, download: d.title + "." + r}, | |
{padding: "5px", display: "block"})) | |
} | |
function m(e, n, c, s, b) { | |
b = D.createElement(e) | |
b.innerHTML = n | |
if(!!c) | |
for(var i in c) | |
b[i] = c[i] | |
if(!!s) | |
for(var i in s) | |
b.style[i] = s[i]; | |
return b; | |
} | |
function jx(b, c, a) { | |
return new Promise(function(d, e) { | |
a = new XMLHttpRequest; | |
a.open("GET", b); | |
a.responseType = c || "text"; | |
a.onload = function() { | |
4 == a.readyState ? d(a["response"]) : e(Error(a.statusText)); | |
}; | |
a.send(null); | |
}); | |
} | |
function q(b, c) { | |
c = {}; | |
b.split("&").forEach(function(a) { | |
var b = decodeURIComponent(a.split("=")[0]); | |
a = decodeURIComponent(a.split("=")[1] || ""); | |
c[b] = a; | |
}); | |
return c; | |
} | |
function u(b, t, e, d) { | |
e = {}; | |
b.split(",").forEach(function(f, i) { | |
d = q(f); | |
e[d.quality + " " + d.type.split(";")[0]] = { url: d.url, title: t.split("+").join(" ")}; | |
}); | |
return e; | |
} | |
function f() {} | |
f.prototype = {durl:"", tube:function(b, c, a) { | |
var d = "", e = [], f = this; | |
jx("https://www.youtube.com/get_video_info?video_id=" + b, "text").then(function(b) { | |
d = q(b); | |
c = c || "video/mp4"; | |
a = a || "medium"; | |
e = u(d.url_encoded_fmt_stream_map, d.title); | |
console.log(e.url); | |
d = e[[a, c].join(" ")]; | |
addLinks(d, c.substring(6)) | |
count +=1; | |
if(count == len) { | |
h("#yt-masthead-content").appendChild(frag); | |
} | |
}); | |
}, tubes:function(p, c, a, f) { | |
f = this; | |
jx("https://gdata.youtube.com/feeds/api/playlists/" + p + "?v=2&alt=json", "json").then(function(r) { | |
r.feed.entry.forEach(function(t, i, o) { | |
t = t.link[1].href.split("/").slice(-2, -1)[0]; | |
f.tube(t); | |
if(len === 1) len = o.length | |
}) | |
}) | |
}}; | |
return f.prototype; | |
}($, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment