Skip to content

Instantly share code, notes, and snippets.

@matheuschimelli
Created August 2, 2020 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheuschimelli/1bcd0419e93cf4600a8b3f60ca81ef79 to your computer and use it in GitHub Desktop.
Save matheuschimelli/1bcd0419e93cf4600a8b3f60ca81ef79 to your computer and use it in GitHub Desktop.
Get Youtube raw video or audio url
(async () => {
const html = await fetch(window.location.href).then((resp) => resp.text()).then((text) => text);
const startStr = 'ytplayer.config = {';
const start = html.indexOf(startStr) + startStr.length - 1;
const end = html.indexOf('};', start) + 1;
const playerObj = JSON.parse(html.slice(start, end));
playerObj.args.player_response = JSON.parse(playerObj.args.player_response);
const videoUrls = playerObj.args.player_response.streamingData.adaptiveFormats.reduce((acc, item) => {
if (!acc[item.quality]) {
acc[item.quality] = {};
}
const mimeType = item.mimeType.split(';')[0];
acc[item.quality][mimeType] = item;
return acc;
}, {});
console.log('!!', videoUrls);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment