Browse Source

Add ffmpeg when using HLS instead of RTMP.

Godzil 7 years ago
parent
commit
546a849aa5
4 changed files with 38 additions and 14 deletions
  1. 2 2
      README.md
  2. BIN
      bin/ffmpeg.exe
  3. 7 1
      src/episode.ts
  4. 29 11
      src/video/stream.ts

+ 2 - 2
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

BIN
bin/ffmpeg.exe


+ 7 - 1
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
           }

+ 29 - 11
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') + '"';
 }