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) ### 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` 2. Run in *Terminal*: `sudo ln -s /usr/bin/nodejs /usr/bin/node`
3. Run in *Terminal*: `sudo npm install -g crunchyroll` 3. Run in *Terminal*: `sudo npm install -g crunchyroll`
### Mac OS X ### Mac OS X
1. Install *Homebrew* following the instructions at http://brew.sh/ 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` 3. Run in *Terminal*: `npm install -g crunchyroll`
### Windows ### 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.host,
player.video.file, player.video.file,
page.swf, page.swf,
filePath + path.extname(player.video.file), filePath, path.extname(player.video.file),
done); done);
} }
@ -152,6 +152,11 @@ function scrapePlayer(config: IConfig, address: string, id: number, done: (err:
if (err) return done(err); if (err) return done(err);
try { try {
var isSubtitled = Boolean(player['default:preload'].subtitle); var isSubtitled = Boolean(player['default:preload'].subtitle);
var streamMode="RTMP";
if (player['default:preload'].stream_info.host == "")
{
streamMode="HLS";
}
done(null, { done(null, {
subtitle: isSubtitled ? { subtitle: isSubtitled ? {
id: parseInt(player['default:preload'].subtitle.$.id, 10), 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 data: player['default:preload'].subtitle.data
} : null, } : null,
video: { video: {
mode: streamMode;
file: player['default:preload'].stream_info.file, file: player['default:preload'].stream_info.file,
host: player['default:preload'].stream_info.host host: player['default:preload'].stream_info.host
} }

View File

@ -6,20 +6,38 @@ import os = require('os');
/** /**
* Streams the video to disk. * Streams the video to disk.
*/ */
export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, done: (err: Error) => void) { export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, fileExt: string, done: (err: Error) => void) {
childProcess.exec(command() + ' ' + if (mode == "RTMP")
'-r "' + rtmpUrl + '" ' + {
'-y "' + rtmpInputPath + '" ' + childProcess.exec(command("rtmpdump") + ' ' +
'-W "' + swfUrl + '" ' + '-r "' + rtmpUrl + '" ' +
'-o "' + filePath + '"', { '-y "' + rtmpInputPath + '" ' +
maxBuffer: Infinity '-W "' + swfUrl + '" ' +
}, done); '-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. * Determines the command for the operating system.
*/ */
function command(): string { function command(exe: string): string {
if (os.platform() !== 'win32') return 'rtmpdump'; if (os.platform() !== 'win32') return exe;
return '"' + path.join(__dirname, '../../bin/rtmpdump.exe') + '"'; return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
} }