Last active
May 4, 2018 15:09
-
-
Save maple3142/443ea1c37cf857b572ab25a6cf3ceb44 to your computer and use it in GitHub Desktop.
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
| // outdated | |
| // please heads for https://github.com/maple3142/ytdl | |
| const axios = require('axios') | |
| const parseQuery = s => { | |
| const o = s | |
| .split('&') | |
| .map(x => x.split('=')) | |
| .reduce((p, c) => { | |
| if (!(c[0] in p)) p[c[0]] = [] | |
| p[c[0]].push(decodeURIComponent(c[1])) | |
| return p | |
| }, {}) | |
| Object.keys(o).forEach(k => (o[k] = o[k].length === 1 ? o[k][0] : o[k])) | |
| return o | |
| } | |
| const decsig = a => { | |
| // 2018/4/19 | |
| var qz = { | |
| fG: function(a) { | |
| a.reverse() | |
| }, | |
| bL: function(a, b) { | |
| a.splice(0, b) | |
| }, | |
| hT: function(a, b) { | |
| var c = a[0] | |
| a[0] = a[b % a.length] | |
| a[b % a.length] = c | |
| } | |
| } | |
| a = a.split('') | |
| qz.bL(a, 2) | |
| qz.hT(a, 12) | |
| qz.hT(a, 49) | |
| qz.bL(a, 1) | |
| qz.fG(a, 9) | |
| qz.hT(a, 68) | |
| qz.fG(a, 1) | |
| qz.bL(a, 3) | |
| return a.join('') | |
| } | |
| // DEMO: https://www.youtube.com/watch?v=-tKVN2mAKRI | |
| const ID = process.argv[2] || '-tKVN2mAKRI' | |
| axios | |
| .get(`http://www.youtube.com/get_video_info?video_id=${ID}&el=embedded&ps=default&eurl=&gl=US&hl=en`) | |
| .then(({ data }) => { | |
| if (data.includes('status=fail')) { | |
| console.error(data) | |
| return | |
| } | |
| const obj = parseQuery(data) | |
| let mp = obj.url_encoded_fmt_stream_map.split(',').map(parseQuery) | |
| if (mp[0].sp && mp[0].sp.includes('signature')) { | |
| mp = mp.map(x => ({ ...x, s: decsig(x.s) })).map(x => ({ ...x, url: x.url + `&signature=${x.s}&alr=yes` })) | |
| } | |
| console.log(JSON.stringify(mp,null,2)) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment