mirror of https://github.com/calzoneman/sync.git
Wire up google drive subtitles
This commit is contained in:
parent
6d9fc73701
commit
33e7f81fa7
8
NEWS.md
8
NEWS.md
|
@ -1,3 +1,11 @@
|
|||
2015-07-25
|
||||
==========
|
||||
|
||||
* CyTube now supports subtitles for Google Drive videos. In order to take
|
||||
advantage of this, you must upgrade mediaquery by running `npm install
|
||||
cytube/mediaquery`. Subtitles are cached in the google-drive-subtitles
|
||||
folder.
|
||||
|
||||
2015-07-07
|
||||
==========
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ function md5(input) {
|
|||
|
||||
var slice = Array.prototype.slice;
|
||||
var subtitleDir = path.resolve(__dirname, '..', 'google-drive-subtitles');
|
||||
var ONE_HOUR = 60 * 60 * 1000;
|
||||
var ONE_DAY = 24 * ONE_HOUR;
|
||||
|
||||
function padZeros(n) {
|
||||
n = n.toString();
|
||||
|
@ -129,6 +131,7 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
|
|||
if (err) {
|
||||
cb(err);
|
||||
} else {
|
||||
Logger.syslog.log('Saved subtitle file ' + file);
|
||||
cb();
|
||||
}
|
||||
});
|
||||
|
@ -137,3 +140,29 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
|
|||
cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
function clearOldSubtitles() {
|
||||
fs.readdir(subtitleDir, function (err, files) {
|
||||
if (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(function (file) {
|
||||
fs.stat(path.join(subtitleDir, file), function (err, stats) {
|
||||
if (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stats.mtime.getTime() < Date.now() - ONE_DAY) {
|
||||
Logger.syslog.log('Deleting old subtitle file: ' + file);
|
||||
fs.unlink(path.join(subtitleDir, file));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(clearOldSubtitles, ONE_HOUR);
|
||||
clearOldSubtitles();
|
||||
|
|
|
@ -37,7 +37,8 @@ Media.prototype = {
|
|||
codec: this.meta.codec,
|
||||
bitrate: this.meta.bitrate,
|
||||
scuri: this.meta.scuri,
|
||||
embed: this.meta.embed
|
||||
embed: this.meta.embed,
|
||||
gdrive_subtitles: this.meta.gdrive_subtitles
|
||||
}
|
||||
};
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.8.2",
|
||||
"version": "3.9.0",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -66,6 +66,17 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
|
|||
).appendTo(video)
|
||||
)
|
||||
|
||||
if data.meta.gdrive_subtitles
|
||||
data.meta.gdrive_subtitles.available.forEach((subt) ->
|
||||
$('<track/>').attr(
|
||||
src: "/gdvtt/#{data.id}/#{subt.lang}/#{subt.name}.vtt?\
|
||||
vid=#{data.meta.gdrive_subtitles.vid}"
|
||||
kind: 'subtitles'
|
||||
srclang: subt.lang
|
||||
label: subt.name
|
||||
).appendTo(video)
|
||||
)
|
||||
|
||||
@player = videojs(video[0], autoplay: true, controls: true)
|
||||
@player.ready(=>
|
||||
@setVolume(VOLUME)
|
||||
|
|
|
@ -524,6 +524,16 @@
|
|||
'data-quality': source.quality
|
||||
}).appendTo(video);
|
||||
});
|
||||
if (data.meta.gdrive_subtitles) {
|
||||
data.meta.gdrive_subtitles.available.forEach(function(subt) {
|
||||
return $('<track/>').attr({
|
||||
src: "/gdvtt/" + data.id + "/" + subt.lang + "/" + subt.name + ".vtt?vid=" + data.meta.gdrive_subtitles.vid,
|
||||
kind: 'subtitles',
|
||||
srclang: subt.lang,
|
||||
label: subt.name
|
||||
}).appendTo(video);
|
||||
});
|
||||
}
|
||||
_this.player = videojs(video[0], {
|
||||
autoplay: true,
|
||||
controls: true
|
||||
|
|
Loading…
Reference in New Issue