Add ffmpeg when using HLS instead of RTMP.

This commit is contained in:
Godzil 2016-08-13 16:20:33 +01:00
parent e06ff53210
commit 546a849aa5
4 changed files with 38 additions and 14 deletions

View File

@ -26,14 +26,14 @@ Use the applicable instructions to install. Is your operating system not listed?
### Debian (Mint, Ubuntu, etc)
1. Run in *Terminal*: `sudo apt-get install nodejs npm mkvtoolnix rtmpdump`
1. Run in *Terminal*: `sudo apt-get install nodejs npm mkvtoolnix rtmpdump ffmpeg`
2. Run in *Terminal*: `sudo ln -s /usr/bin/nodejs /usr/bin/node`
3. Run in *Terminal*: `sudo npm install -g crunchyroll`
### Mac OS X
1. Install *Homebrew* following the instructions at http://brew.sh/
2. Run in *Terminal*: `brew install node mkvtoolnix rtmpdump`
2. Run in *Terminal*: `brew install node mkvtoolnix rtmpdump ffmpeg`
3. Run in *Terminal*: `npm install -g crunchyroll`
### Windows

BIN
bin/ffmpeg.exe Executable file

Binary file not shown.

View File

@ -88,7 +88,7 @@ function downloadVideo(config: IConfig,
player.video.host,
player.video.file,
page.swf,
filePath + path.extname(player.video.file),
filePath, path.extname(player.video.file),
done);
}
@ -152,6 +152,11 @@ function scrapePlayer(config: IConfig, address: string, id: number, done: (err:
if (err) return done(err);
try {
var isSubtitled = Boolean(player['default:preload'].subtitle);
var streamMode="RTMP";
if (player['default:preload'].stream_info.host == "")
{
streamMode="HLS";
}
done(null, {
subtitle: isSubtitled ? {
id: parseInt(player['default:preload'].subtitle.$.id, 10),
@ -159,6 +164,7 @@ function scrapePlayer(config: IConfig, address: string, id: number, done: (err:
data: player['default:preload'].subtitle.data
} : null,
video: {
mode: streamMode;
file: player['default:preload'].stream_info.file,
host: player['default:preload'].stream_info.host
}

View File

@ -6,20 +6,38 @@ import os = require('os');
/**
* Streams the video to disk.
*/
export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, done: (err: Error) => void) {
childProcess.exec(command() + ' ' +
'-r "' + rtmpUrl + '" ' +
'-y "' + rtmpInputPath + '" ' +
'-W "' + swfUrl + '" ' +
'-o "' + filePath + '"', {
maxBuffer: Infinity
}, done);
export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, fileExt: string, done: (err: Error) => void) {
if (mode == "RTMP")
{
childProcess.exec(command("rtmpdump") + ' ' +
'-r "' + rtmpUrl + '" ' +
'-y "' + rtmpInputPath + '" ' +
'-W "' + swfUrl + '" ' +
'-o "' + filePath + fileExt + '"', {
maxBuffer: Infinity
}, done);
}
else if (mode == "HLS")
{
console.info("Experimental FFMPEG, MAY FAIL!!!");
var cmd=command("ffmpeg") + ' ' +
'-i "' + rtmpInputPath + '" ' +
'-c copy -bsf:a aac_adtstoasc ' +
'"' + filePath + '.mp4"';
childProcess.exec(cmd, {
maxBuffer: Infinity
}, done);
}
else
{
console.error("No such mode: " + mode);
}
}
/**
* Determines the command for the operating system.
*/
function command(): string {
if (os.platform() !== 'win32') return 'rtmpdump';
return '"' + path.join(__dirname, '../../bin/rtmpdump.exe') + '"';
function command(exe: string): string {
if (os.platform() !== 'win32') return exe;
return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
}