Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions plugins/subtitles.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@ var findSubtitles = function(options) {
}

return;
}
};

var isRemote = function(path) {
var url = new URL(path);
return ['http:', 'https:'].indexOf(url.protocol) !== -1;
};

var isExtension = function(path, extension) {
return path.substr(-4).toLowerCase() === '.' + extension;
};

var isSrt = function(path) {
return path.substr(-4).toLowerCase() === '.srt';
return isExtension(path, 'srt');
};

var isVtt = function(path) {
return isExtension(path, 'vtt');
};

var attachSubtitles = function(ctx) {
Expand Down Expand Up @@ -90,10 +103,16 @@ var subtitles = function(ctx, next) {
}
}

if (isVtt(ctx.options.subtitles) && isRemote(ctx.options.subtitles)) {
debug('attaching remote subtitles', ctx.options.subtitles);
attachSubtitles(ctx);
return next();
}

var port = ctx.options['subtitle-port'] || 4101;
srtToVtt(ctx.options, function(err, data) {
if (err) return next();
debug('loading subtitles', ctx.options.subtitles);
debug('attaching local subtitles', ctx.options.subtitles);
if (err) return next();
var ip = ctx.options.myip || internalIp.v4.sync();
var addr = 'http://' + ip + ':' + port;
Expand Down