llkatc.blogg.se

How to get subtitles on youtube without cc
How to get subtitles on youtube without cc










how to get subtitles on youtube without cc

To join this to one big text you can write the following: let subsText = textNodes.map(x => x.textContent).join("\n").replaceAll(''',"'") We are interested in textContent: textNodes.map(x => x.textContent) On which you can perform a map operation to get the parameters. With spread notation you can make it an array of text nodes let textNodes = You then want to get the text elements xml.getElementsByTagName('text') For this it's very useful to use the DOMParser: let xml = new DOMParser().parseFromString(subs,"text/xml") This is possible because of a really cool trick: on a youtube page there is a global variable ytInitialPlayerResponse with a link to the captions: (make sure to refresh the page first) let subsUrl = .baseUrl īecause you're on the YouTube page, you are allowed to fetch this url (no cors problem, because your fetch originates from ) let subs = await (await fetch(subsUrl)).text() Wow, isn't that cool? And short and simple as well? Let subsText = textNodes.map(x => x.textContent).join("\n").replaceAll(''',"'") Let xml = new DOMParser().parseFromString(subs,"text/xml") Let subs = await (await fetch(subsUrl)).text() Try copy paste this: (make sure to refresh your page!) let subsUrl = .baseUrl

how to get subtitles on youtube without cc

The following works when you're on the youtube page Static async fetchCaptions(videoId, options) Is there any way my goal can be achieved in java (for offline solutions) or javascript (for online solutions)?ĭefaultId = 'fJ9rUzIMcZQ', /* Queen – Bohemian Rhapsody */ I've also tried an ugly solution with parsing YouTube Player IFrame (there is a div inside it with current subtitles' line), but it doesn't work because of origin mismatch security issues. I haven't found YouTube Player Api methods for captions, also I've tried to get YouTube captions as TextTrack with videojs player in the way it could be done for usual videos, but the following doesn't work: Ĭonsole.log('Tracks: ' + this.textTracks().length) //zero here :(Ĭonsole.log('Ready State', aTextTrack.readyState())

how to get subtitles on youtube without cc

Initially I've tried to do it offline via YouTube API, but as it seems YouTube forbids to fetch subtitles of videos you are not the owner. How can programmatically get subtitles of a playing YouTube video?












How to get subtitles on youtube without cc