mirror of https://github.com/calzoneman/sync.git
Fixes for google drive subtitles
This commit is contained in:
parent
b0e6de389e
commit
174ad8d81e
|
@ -42,12 +42,13 @@ function formatTime(time) {
|
|||
return list.map(padZeros).join(':') + ms.toFixed(3).substring(1);
|
||||
}
|
||||
|
||||
function unescapeHtmlEntities(text) {
|
||||
function fixText(text) {
|
||||
return text.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'");
|
||||
.replace(/'/g, "'")
|
||||
.replace(/-->/g, '-->');
|
||||
}
|
||||
|
||||
exports.convert = function convertSubtitles(subtitles) {
|
||||
|
@ -55,10 +56,15 @@ exports.convert = function convertSubtitles(subtitles) {
|
|||
var lines = slice.call($('transcript text').map(function (index, elem) {
|
||||
var start = parseFloat(elem.attribs.start);
|
||||
var end = start + parseFloat(elem.attribs.dur);
|
||||
var text = elem.children[0].data;
|
||||
var text;
|
||||
if (elem.children.length) {
|
||||
text = elem.children[0].data;
|
||||
} else {
|
||||
text = '';
|
||||
}
|
||||
|
||||
var line = formatTime(start) + ' --> ' + formatTime(end);
|
||||
line += '\n' + unescapeHtmlEntities(text) + '\n';
|
||||
line += '\n' + fixText(text) + '\n';
|
||||
return line;
|
||||
}));
|
||||
|
||||
|
@ -66,16 +72,15 @@ exports.convert = function convertSubtitles(subtitles) {
|
|||
};
|
||||
|
||||
exports.attach = function setupRoutes(app) {
|
||||
app.get('/gdvtt/:id/:lang/:name.vtt', handleGetSubtitles);
|
||||
app.get('/gdvtt/:id/:lang/(:name)?.vtt', handleGetSubtitles);
|
||||
};
|
||||
|
||||
function handleGetSubtitles(req, res) {
|
||||
var id = req.params.id;
|
||||
var lang = req.params.lang;
|
||||
var name = req.params.name;
|
||||
var name = req.params.name || '';
|
||||
var vid = req.query.vid;
|
||||
if (typeof vid !== 'string' || typeof id !== 'string' || typeof lang !== 'string' ||
|
||||
typeof name !== 'string') {
|
||||
if (typeof vid !== 'string' || typeof id !== 'string' || typeof lang !== 'string') {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
var file = [id, lang, md5(name)].join('_') + '.vtt';
|
||||
|
|
Loading…
Reference in New Issue