Created
August 2, 2020 16:52
-
-
Save matheuschimelli/1bcd0419e93cf4600a8b3f60ca81ef79 to your computer and use it in GitHub Desktop.
Get Youtube raw video or audio url
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
(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