ready4testing
This commit is contained in:
parent
101315a1b5
commit
a81efff715
@ -56,63 +56,64 @@ exports.play = function(idx) {
|
|||||||
var channel = Conf.channels[idx];
|
var channel = Conf.channels[idx];
|
||||||
if(channel !== undefined) {
|
if(channel !== undefined) {
|
||||||
var stream2play = channel.stream;
|
var stream2play = channel.stream;
|
||||||
|
|
||||||
var m3u = '/tmp/kitchenradio.m3u';
|
var m3u = '/tmp/kitchenradio.m3u';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(m3u);
|
fs.unlinkSync(m3u);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Log.error('Radio: Error deleting "' + m3u + '".' + e);
|
Log.error('Radio: Error deleting "' + m3u + '".' + e);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
wget.download(channel.stream, m3u);
|
|
||||||
} catch(e) {
|
|
||||||
Log.error('Radio: Error downloading "' + channel.stream + '".' + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Helper.isDefinedAndNotNull(Child)) {
|
var download = wget.download(channel.stream, m3u);
|
||||||
|
download.on('end', function(output) {
|
||||||
|
Log.inspect('Radio: Download completed', output);
|
||||||
|
|
||||||
|
if(Helper.isDefinedAndNotNull(Child)) {
|
||||||
|
try {
|
||||||
|
Child.kill();
|
||||||
|
} catch(err) {
|
||||||
|
Log.error('Radio: Error killing process');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Child.kill();
|
var parsers = require('playlist-parser');
|
||||||
} catch(err) {
|
var M3U = parsers.M3U;
|
||||||
Log.error('Radio: Error killing process');
|
|
||||||
|
var playlist = M3U.parse(fs.readFileSync(m3u, { encoding: 'utf8' }));
|
||||||
|
Log.inspect('Radio: playlist', playlist);
|
||||||
|
|
||||||
|
if(Helper.isDefinedAndNotNull(playlist[0])) {
|
||||||
|
stream2play = playlist[0].file;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
Log.error(e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
var Child = spawn(
|
||||||
var parsers = require('playlist-parser');
|
'mplayer',
|
||||||
var M3U = parsers.M3U;
|
[
|
||||||
|
'-slave',
|
||||||
|
'-quiet',
|
||||||
|
stream2play
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
var playlist = M3U.parse(fs.readFileSync(m3u, { encoding: 'utf8' }));
|
// listen for any response from the child
|
||||||
Log.inspect('Radio: playlist', playlist);
|
Child.stdout.on('data', function(chunk) {
|
||||||
|
Log.log('Radio: ' + chunk);
|
||||||
|
});
|
||||||
|
|
||||||
if(Helper.isDefinedAndNotNull(playlist[0])) {
|
// listen for any errors
|
||||||
stream2play = playlist[0].file;
|
Child.stderr.on('data', function (chunk) {
|
||||||
}
|
Log.error('Radio: ' + chunk);
|
||||||
} catch(e) {
|
});
|
||||||
Log.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var Child = spawn(
|
/*Child.on('exit', function (code){
|
||||||
'mplayer',
|
Log.log('Radio: Child process exited with exit code ' + code);
|
||||||
[
|
});*/
|
||||||
'-slave',
|
|
||||||
'-quiet',
|
|
||||||
stream2play
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// listen for any response from the child
|
|
||||||
Child.stdout.on('data', function(chunk) {
|
|
||||||
Log.log('Radio: ' + chunk);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// listen for any errors
|
|
||||||
Child.stderr.on('data', function (chunk) {
|
|
||||||
Log.error('Radio: ' + chunk);
|
|
||||||
});
|
|
||||||
|
|
||||||
/*Child.on('exit', function (code){
|
|
||||||
Log.log('Radio: Child process exited with exit code ' + code);
|
|
||||||
});*/
|
|
||||||
} else {
|
} else {
|
||||||
Log.error('Radio: No channel defined!');
|
Log.error('Radio: No channel defined!');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user