using the debug module now

Esse commit está contido em:
Simon Kusterer
2014-11-23 15:41:23 +01:00
commit ea7b64b2be
11 arquivos alterados com 43 adições e 57 exclusões
+8 -4
Ver Arquivo
@@ -71,8 +71,6 @@ contains subtitles.
* `--myip <IP>` Your main IP address (useful if you have multiple network adapters)
* `--debug` Output debug messages.
* `--verbose` Hide the player timeline.
* `--peerflix-* <val>` Pass options to peerflix.
@@ -97,11 +95,17 @@ q // quit
```
### Installation
### reporting bugs/issues
Please always append the debug output to your issues. You can enable the debug messages by setting the
DEBUG ENV variable before running the castnow-command like this: `DEBUG=castnow* castnow ./myvideo.mp4`.
Some problems are also already addressed in our wiki https://github.com/xat/castnow/wiki.
### installation
`npm install castnow -g`
### Contributers
### contributers
* [tooryx](https://github.com/tooryx)
* [przemyslawpluta](https://github.com/przemyslawpluta)
+8 -13
Ver Arquivo
@@ -7,7 +7,7 @@ var keypress = require('keypress');
var ui = require('playerui')();
var circulate = require('array-loop');
var xtend = require('xtend');
var logger = require('./utils/logger');
var debug = require('debug')('castnow');
var noop = function() {};
// plugins
@@ -30,7 +30,6 @@ if (opts.help) {
'--subtitles <path/url> Path or URL to an SRT or VTT file',
'--myip <ip> Your main IP address',
'--verbose No output',
'--debug Output debug messages',
'--peerflix-* <value> Pass options to peerflix',
'--ffmpeg-* <value> Pass options to ffmpeg',
'--help This help screen',
@@ -61,14 +60,10 @@ if (opts._.length) {
delete opts._;
if (opts.verbose || opts.debug) {
if (opts.verbose || process.env.DEBUG) {
ui.hide();
}
if (opts.debug) {
logger.on();
}
ui.showLabels('state');
var last = function(fn, l) {
@@ -82,7 +77,7 @@ var last = function(fn, l) {
var ctrl = function(err, p, ctx) {
if (err) {
logger.print('[core] player error', err);
debug('player error: %o', err);
console.log(chalk.red(err));
process.exit();
}
@@ -157,7 +152,7 @@ var ctrl = function(err, p, ctx) {
if (!playlist.length) return;
p.stop(function() {
ui.showLabels('state');
logger.print('[core] loading next in playlist');
debug('loading next in playlist: %o', playlist[0]);
p.load(playlist[0], noop);
playlist.shift();
});
@@ -243,7 +238,7 @@ var ctrl = function(err, p, ctx) {
process.stdin.on('keypress', function(ch, key) {
if (key && key.name && keyMappings[key.name]) {
logger.print('[core] key pressed', key.name);
debug('key pressed: %s', key.name);
keyMappings[key.name]();
}
if (key && key.ctrl && key.name == 'c') {
@@ -261,7 +256,7 @@ var logState = (function() {
var dots = circulate(['.', '..', '...', '....']);
return function(status) {
if (inter) clearInterval(inter);
logger.print('[core] player status:', status);
debug('player status: %s', status);
inter = setInterval(function() {
ui.setLabel('state', 'State', capitalize(status) + dots());
ui.render();
@@ -290,10 +285,10 @@ player.use(function(ctx, next) {
});
if (!opts.playlist) {
logger.print('[core] attaching...');
debug('attaching...');
player.attach(opts, ctrl);
} else {
logger.print('[core] launching...');
debug('launching...');
player.launch(opts, ctrl);
}
+1
Ver Arquivo
@@ -31,6 +31,7 @@
"castv2-client": "0.0.8",
"chalk": "^0.5.1",
"chromecast-player": "0.1.6",
"debug": "^2.1.0",
"fs-extended": "^0.2.0",
"get-youtube-id": "^0.1.3",
"got": "^1.2.2",
+3 -3
Ver Arquivo
@@ -2,7 +2,7 @@ var fs = require('fs-extended');
var path = require('path');
var join = path.join;
var extname = path.extname;
var logger = require('../utils/logger');
var debug = require('debug')('castnow:directories');
var acceptedExtensions = {
'.mp3': true,
@@ -24,10 +24,10 @@ var flattenFiles = function(playlist) {
var items = [];
playlist.forEach(function(item) {
if (isDir(item)) {
logger.print('[directories] directory found:', item.path);
debug('directory found: %s', item.path);
var mediaFiles = fs.listFilesSync(item.path, { filter: filter });
items.push.apply(items, mediaFiles.map(function(file) {
logger.print('[directories] added file', file, 'from directory', item.path);
debug('added file %s from directory %s', file, item.path);
return {
path: join(item.path, file)
};
+3 -3
Ver Arquivo
@@ -3,7 +3,7 @@ var internalIp = require('internal-ip');
var router = require('router');
var path = require('path');
var serveMp4 = require('../utils/serve-mp4');
var logger = require('../utils/logger');
var debug = require('debug')('castnow:localfile');
var fs = require('fs');
var port = 4100;
@@ -40,12 +40,12 @@ var localfile = function(ctx, next) {
});
route.all('/{idx}', function(req, res) {
logger.print('[localfile] incoming request serving', list[req.params.idx].path);
debug('incoming request serving %s', list[req.params.idx].path);
serveMp4(req, res, list[req.params.idx].path);
});
http.createServer(route).listen(port);
logger.print('[localfile] started webserver on address', ip, 'using port', port);
debug('started webserver on address %s using port %s', ip, port);
next();
};
+5 -5
Ver Arquivo
@@ -2,7 +2,7 @@ var http = require('http');
var fs = require('fs');
var srt2vtt = require('srt2vtt');
var internalIp = require('internal-ip');
var logger = require('../utils/logger');
var debug = require('debug')('castnow:subtitles');
var got = require('got');
var port = 4101;
@@ -13,7 +13,7 @@ var srtToVtt = function(source, cb) {
if (!isSrt(source)) return cb(null, content);
srt2vtt(content, function(err, data) {
if (err) return cb(err);
logger.print('[subtitles] converted srt to vtt', source);
debug('converted srt to vtt: %s', source);
cb(null, data);
});
});
@@ -52,12 +52,12 @@ var subtitles = function(ctx, next) {
srtToVtt(ctx.options.subtitles, function(err, data) {
if (err) return next();
logger.print('[subtitles] loading subtitles', ctx.options.subtitles);
debug('loading subtitles', ctx.options.subtitles);
if (err) return next();
var ip = ctx.options.myip || internalIp();
var addr = 'http://' + ip + ':' + port;
http.createServer(function(req, res) {
logger.print('[subtitles] incoming request');
debug('incoming request');
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Content-Length': data.length,
@@ -65,7 +65,7 @@ var subtitles = function(ctx, next) {
});
res.end(data);
}).listen(port);
logger.print('[subtitles] started webserver on address', ip, 'using port', port);
debug('started webserver on address %s using port %s', ip, port);
ctx.options.subtitles = addr;
attachSubtitles(ctx);
next();
+3 -3
Ver Arquivo
@@ -2,7 +2,7 @@ var readTorrent = require('read-torrent');
var peerflix = require('peerflix');
var internalIp = require('internal-ip');
var grabOpts = require('../utils/grab-opts');
var logger = require('../utils/logger');
var debug = require('debug')('castnow:torrent');
var port = 4102;
var torrent = function(ctx, next) {
@@ -16,14 +16,14 @@ var torrent = function(ctx, next) {
readTorrent(path, function(err, torrent) {
if (err) {
logger.print('[torrent] error reading torrent', err);
debug('error reading torrent: %o', err);
return next();
}
if (!ctx.options['peerflix-port']) ctx.options['peerflix-port'] = port;
var engine = peerflix(torrent, grabOpts(ctx.options, 'peerflix-'));
var ip = ctx.options.myip || internalIp();
engine.server.once('listening', function() {
logger.print('[torrent] started webserver on address', ip, 'using port', engine.server.address().port);
debug('started webserver on address %s using port %s', ip, engine.server.address().port);
ctx.options.playlist[0] = {
path: 'http://' + ip + ':' + engine.server.address().port,
type: 'video/mp4',
+7 -7
Ver Arquivo
@@ -3,7 +3,7 @@ var internalIp = require('internal-ip');
var got = require('got');
var Transcoder = require('stream-transcoder');
var grabOpts = require('../utils/grab-opts');
var logger = require('../utils/logger');
var debug = require('debug')('castnow:transcode');
var port = 4103;
var transcode = function(ctx, next) {
@@ -20,13 +20,13 @@ var transcode = function(ctx, next) {
ctx.options.disableSeek = true;
http.createServer(function(req, res) {
var opts = grabOpts(ctx.options, 'ffmpeg-');
logger.print('[transcode] incoming request for path', orgPath);
debug('incoming request for path %s', orgPath);
res.writeHead(200, {
'Access-Control-Allow-Origin': '*'
});
var s = got(orgPath);
s.on('error', function(err) {
logger.print('[transcode] got error', err);
debug('got error: %o', err);
});
var trans = new Transcoder(s)
@@ -34,10 +34,10 @@ var transcode = function(ctx, next) {
.format('mp4')
.custom('strict', 'experimental')
.on('finish', function() {
logger.print('[transcode] finished transcoding');
debug('finished transcoding');
})
.on('error', function(err) {
logger.print('[transcode] transcoding error', err);
debug('transcoding error: %o', err);
});
for (var key in opts) {
trans.custom(key, opts[key]);
@@ -46,11 +46,11 @@ var transcode = function(ctx, next) {
var args = trans._compileArguments();
args = [ '-i', '-' ].concat(args);
args.push('pipe:1');
logger.print('[transcode] spawning ffmpeg', args.join(' '));
debug('spawning ffmpeg %s', args.join(' '));
trans.stream().pipe(res);
}).listen(port);
logger.print('[transcode] started webserver on address', ip, 'using port', port);
debug('started webserver on address %s using port %s', ip, port);
next();
};
+3 -3
Ver Arquivo
@@ -3,7 +3,7 @@ var castv2Cli = require('castv2-client');
var RequestResponseController = castv2Cli.RequestResponseController;
var inherits = require('util').inherits;
var getYouTubeId = require('get-youtube-id');
var logger = require('../utils/logger');
var debug = require('debug')('castnow:youtube');
var Yt = function() {
Api.apply(this, arguments);
@@ -17,7 +17,7 @@ inherits(Yt, Api);
Yt.prototype.load = function(options, cb) {
var youtubeId = getYouTubeId(options.path);
logger.print('[youtube] loading video with id', youtubeId);
debug('loading video with id %s', youtubeId);
var opts = {
type: 'flingVideo',
data: {
@@ -32,7 +32,7 @@ Yt.prototype.load = function(options, cb) {
var youtube = function(ctx, next) {
if (ctx.mode !== 'launch') return next();
if (!getYouTubeId(ctx.options.playlist[0].path)) return next();
logger.print('[youtube] using youtube api');
debug('using youtube api');
ctx.api = Yt;
next();
};
+2 -2
Ver Arquivo
@@ -2,7 +2,7 @@ var url = require('url');
var got = require('got');
var qs = require('query-string');
var parser = require('xml2js').parseString;
var logger = require('../utils/logger');
var debug = require('debug')('castnow:youtubeplaylist');
function getPlaylistItems(id, callback) {
@@ -54,7 +54,7 @@ var youtubePlaylist = function youtubePlaylist(ctx, next) {
for (i = 0; i < ctx.options.playlist.length; i++) {
if (/youtube/.test(ctx.options.playlist[i].path) && /playlist\?list/.test(ctx.options.playlist[i].path)) {
logger.print('[youtubeplaylist] loading youtube playlist', ctx.options.playlist[i].path);
debug('loading youtube playlist %s', ctx.options.playlist[i].path);
items.push(qs.parse(url.parse(ctx.options.playlist[i].path).query).list);
ctx.options.playlist[i] = items.length;
}
-14
Ver Arquivo
@@ -1,14 +0,0 @@
var on = false;
module.exports.print = function() {
if (!on) return;
console.log.apply(console, arguments);
};
module.exports.on = function() {
on = true;
};
module.exports.off = function() {
on = false;
};