-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support text tracks #108
Comments
Here's a few videos from archive.org we could use for text track examples (we'll need to use YouTube to autogenerate subtitles). https://archive.org/details/Computer1984 https://archive.org/details/commodore-64-training-tape-with-jim-butterfield |
We can run this in the console of a YouTube video to generate some VTT text var AVOID_CONCURRENT_CAPTIONS = true;
try {
var captionData = JSON.parse(ytplayer.config.args.player_response)
.captions
.playerCaptionsTracklistRenderer
.captionTracks[0];
fetch(captionData.baseUrl)
.then(function(res) {
return res.text();
})
.then(function(xmlString) {
return new window.DOMParser().parseFromString(xmlString, 'text/xml');
})
.then(function(xmlParsed) {
function pad2(number) {
// thanks https://www.electrictoolbox.com/pad-number-two-digits-javascript/
return (number < 10 ? '0' : '') + number
}
function pad3(number) {
return number >= 100 ? number : ('0' + pad2(number))
}
function formatTime(time) {
var hours = 0;
var minutes = 0;
var seconds = 0;
var milliseconds = 0;
while (time >= (60 * 60)) {
hours++;
time -= (60 * 60);
}
while (time >= 60) {
minutes++;
time -= 60;
}
while (time >= 1) {
seconds++;
time -= 1;
}
milliseconds = (time * 1000).toFixed(0);
return pad2(hours) + ':' + pad2(minutes) + ':' + pad2(seconds) + '.' + pad3(milliseconds);
}
var webVttContent = '';
webVttContent += 'WEBVTT\n';
var tempNode = document.createElement('div');
var textElements = xmlParsed.querySelector('transcript').childNodes;
Array.prototype.forEach.call(textElements, function(text, index) {
webVttContent += '\n' + (index + 1) + '\n';
var start = Number(text.getAttribute('start'));
var end = start + Number(text.getAttribute('dur'));
if (AVOID_CONCURRENT_CAPTIONS && index + 1 < textElements.length) {
var nextStart = Number(textElements[index + 1].getAttribute('start'));
end = Math.min(end, nextStart);
}
webVttContent += formatTime(start) + ' --> ' + formatTime(end) + '\n';
var content = text.textContent.replace(/<[^>]+>/g, '');
tempNode.innerHTML = content;
webVttContent += tempNode.textContent + '\n';
});
console.log(webVttContent);
});
} catch (err) {
console.warn(err);
console.warn('Unable to get WebVTT caption data from YouTube video.');
} |
Telephone Etiquette: https://hastebin.com/uzibatapis.sql Commodore 64 video: https://hastebin.com/lebuyaxifo.sql Computer Music: https://hastebin.com/sidubidudu.sql |
Some more notes:
I think this resolves all of the questions above except for:
I'd say that's still TBD, but we can go ahead and implement everything else. Perhaps for Cassette v2.0 we can skip |
Implementation outline for 2.0 beta:
|
I thought about whether we should support props to override how |
The |
That issue is fixed now! |
I think we're ok to handle |
Three more items to check off:
|
|
|
More info here.
For text tracks:
textTracks
property on the playlist track object which is a list of objects describing the properties in anHTMLTrackElement
. We will dynamically add tracks to the video element (this article has good advice).kind
s of text tracks (subtitles
,description
,chapters
,metadata
) I'm not sure how these are shown or not. How does the browser handle them? Do we need to do anything special since we're not displaying the browser's default video controls?displayNativeCaptions
(or something) that istrue
by default but can be turned off to disable the browser's native text tracks display inside the video element.playerContext
, which means making most or all of the data from the VTTCue interface available. We'll want to make all the active and possibly all the cues for the active track(s) available.We should check out how related/similar libraries have handled APIs for text tracks. Most importantly we should see what options popular media libraries have for manipulating available text tracks from the user angle.
The text was updated successfully, but these errors were encountered: