Fixed episode filter; allow delay unlink at merge

This commit is contained in:
Roel van Uden
2015-01-24 13:13:22 +01:00
parent 4b0c993969
commit 46baad6c8b
2 changed files with 38 additions and 7 deletions

View File

@@ -45,9 +45,10 @@ module.exports = function (config, address, done) {
* @param {function(Error)} done
*/
function _download(cache, config, baseAddress, data, done) {
if (typeof config.episode === 'number') {
if (config.episode > 0 && data.number < config.episode) return done();
if (config.episode < 0 && -config.episode < data.number) return done();
if (typeof config.episode !== 'undefined') {
var filter = parseInt(config.episode, 10);
if (filter > 0 && data.number <= filter) return done();
if (filter < 0 && data.number >= Math.abs(filter)) return done();
}
var address = url.resolve(baseAddress, data.address);
if (cache[address]) return done();

View File

@@ -3,6 +3,7 @@ var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');
var os = require('os');
var subtitle = require('../subtitle');
/**
* Merges the subtitle and video files into a Matroska Multimedia Container.
@@ -12,7 +13,8 @@ var os = require('os');
* @param {function(Error)} done
*/
module.exports = function(config, rtmpInputPath, filePath, done) {
var subtitlePath = filePath + '.' + config.format;
var format = subtitle.formats[config.format] ? config.format : 'ass';
var subtitlePath = filePath + '.' + format;
var videoPath = filePath + path.extname(rtmpInputPath);
childProcess.exec(_command() + ' ' +
'-o "' + filePath + '.mkv" ' +
@@ -21,9 +23,9 @@ module.exports = function(config, rtmpInputPath, filePath, done) {
maxBuffer: Infinity
}, function(err) {
if (err) return done(err);
fs.unlink(videoPath, function(err) {
if (err) return done(err);
fs.unlink(subtitlePath, done);
_unlink(videoPath, subtitlePath, function(err) {
if (err) _unlinkTimeout(videoPath, subtitlePath, 5000);
done();
});
});
};
@@ -37,3 +39,31 @@ function _command() {
if (os.platform() !== 'win32') return 'mkvmerge';
return path.join(__dirname, '../../bin/mkvmerge.exe');
}
/**
* Unlinks the video and subtitle
* @param {string} videoPath
* @param {string} subtitlePath
* @param {function(Error)} done
*/
function _unlink(videoPath, subtitlePath, done) {
fs.unlink(videoPath, function(err) {
if (err) return done(err);
fs.unlink(subtitlePath, done);
});
}
/**
* Attempts to unlink the video and subtitle with a timeout between each try.
* @param {string} videoPath
* @param {string} subtitlePath
* @param {function(Error)} done
*/
function _unlinkTimeout(videoPath, subtitlePath, timeout) {
console.log('Trying to unlink...' + Date.now());
setTimeout(function() {
_unlink(videoPath, subtitlePath, function(err) {
if (err) _unlinkTimeout(videoPath, subtitlePath, timeout);
});
}, timeout);
}