Skip to content

Instantly share code, notes, and snippets.

View matheuschimelli's full-sized avatar
:shipit:
Focusing

Matheus Chimelli matheuschimelli

:shipit:
Focusing
View GitHub Profile
@matheuschimelli
matheuschimelli / file.js
Created August 2, 2020 16:52
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) => {