diff --git a/README.md b/README.md index 3fa719c..b59e473 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/ffmpeg.exe b/bin/ffmpeg.exe new file mode 100755 index 0000000..9b1df89 Binary files /dev/null and b/bin/ffmpeg.exe differ diff --git a/src/episode.ts b/src/episode.ts index a2eeacb..f5963cf 100644 --- a/src/episode.ts +++ b/src/episode.ts @@ -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 } diff --git a/src/video/stream.ts b/src/video/stream.ts index 6a116c5..8cbf320 100644 --- a/src/video/stream.ts +++ b/src/video/stream.ts @@ -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') + '"'; }