Hello, I would like to propose the implementation of support for closed caption files (.srt and .vvt) for media stored in Brave Playlist. I believe it would be a good quality of life feature.
Could you please elaborate on this?
- why do you think this will be useful?
- use cases?
- maybe present some code…
Yes, some users, including myself, are deaf or hard of hearing and depend on subtitles to fully understand video content. Additionally, it would be a valuable feature for those who watch foreign films, documentaries, non-native content, or for anyone in noisy environments.
Here’s my attempt at creating a JavaScript snippet using resources I found online.
function parseSRT(data) {
const subtitles = data.split(‘\n\n’);
return subtitles.map(subtitle => {
const [index, time, …text] = subtitle.split(‘\n’);
const [start, end] = time.split(’ → ‘);
return { start, end, text: text.join(’\n’) };
});
}function showSubtitles(subtitles, video) {
const track = document.createElement(‘track’);
track.kind = ‘subtitles’;
track.srclang = ‘en’;
track.label = ‘English’;
track.mode = ‘showing’;subtitles.forEach(sub => { const cue = new VTTCue(sub.start, sub.end, sub.text); track.addCue(cue); }); video.appendChild(track);
}
// Example
const video = document.querySelector(‘video’);
fetch(‘subtitles.srt’)
.then(response => response.text())
.then(data => {
const subtitles = parseSRT(data);
showSubtitles(subtitles, video);
});