Created
May 18, 2020 04:59
-
-
Save KhunHtetzNaing/af61d4f72f03ac5fc2b2153fa2d50e15 to your computer and use it in GitHub Desktop.
Extract stream url from google drive [2020]
This file contains 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
function get_map() { | |
var str = document.head.innerHTML, //get html in current page | |
regex = /fmt_stream_map",(.*?)]/gm, //fetch map regex | |
m; | |
if ((m = regex.exec(str)) !== null) { | |
return m[1].replace(/"/g, ","); | |
} | |
return null; | |
} | |
function parse_map(str) { | |
var regex = /https:(.*?),/mg, | |
m, | |
src = []; | |
while ((m = regex.exec(str)) !== null) { | |
// This is necessary to avoid infinite loops with zero-width matches | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++; | |
} | |
// The result can be accessed through the `m`-variable. | |
m.forEach((match, groupIndex) => { | |
if (groupIndex == 1) { | |
src.push(match); | |
} | |
}); | |
} | |
return src; | |
} | |
function get_quality(url) { | |
if (contain(url, 'itag=37')) { | |
return '1080p'; | |
} else if (contain(url, 'itag=22')) { | |
return '720p'; | |
} else if (contain(url, 'itag=59')) { | |
return '480p'; | |
} else if (contain(url, 'itag=18')) { | |
return '360p'; | |
} | |
return null; | |
} | |
function contain(m, s) { | |
return m.indexOf(s) != -1; | |
} | |
var map = get_map(), | |
out = []; | |
if (map != null) { | |
var srx = parse_map(map); | |
srx.forEach(e => { | |
e = JSON.parse('"https:' + e + '"'); | |
var qua = get_quality(e); | |
if (qua != null) { | |
var tmp = { | |
'label': qua, | |
'file': e | |
} | |
out.push(tmp); | |
} | |
}) | |
} | |
console.log(JSON.stringify(out)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment