Browse Source

Add an option to make ffmpeg, mkvmerge and rtmpdump running verbosely.

Godzil 6 years ago
parent
commit
65c9032839
5 changed files with 33 additions and 15 deletions
  1. 1 0
      src/batch.ts
  2. 3 3
      src/episode.ts
  3. 1 0
      src/interface/IConfig.d.ts
  4. 10 2
      src/video/merge.ts
  5. 18 10
      src/video/stream.ts

+ 1 - 0
src/batch.ts

@@ -187,5 +187,6 @@ function parse(args: string[]): IConfigLine
             '1080')
     .option('-g, --rebuildcrp', 'Rebuild the crpersistant file.')
     .option('-b, --batch <s>', 'Batch file', 'CrunchyRoll.txt')
+    .option('--verbose', 'Make tool verbose')
     .parse(args);
 }

+ 3 - 3
src/episode.ts

@@ -141,7 +141,7 @@ function download(config: IConfig, page: IEpisodePage, player: IEpisodePlayer, d
           const isSubtited = Boolean(player.subtitle);
 
           log.dispEpisode(fileName, 'Merging...', false);
-          video.merge(config, isSubtited, player.video.file, filePath, player.video.mode, (errVM) =>
+          video.merge(config, isSubtited, player.video.file, filePath, player.video.mode, config.verbose, (errVM) =>
           {
             if (errVM)
             {
@@ -198,11 +198,11 @@ function downloadSubtitle(config: IConfig, player: IEpisodePlayer, filePath: str
 /**
  * Streams the video to disk.
  */
-function downloadVideo(ignored/*config*/: IConfig,  page: IEpisodePage, player: IEpisodePlayer,
+function downloadVideo(config: IConfig,  page: IEpisodePage, player: IEpisodePlayer,
                        filePath: string, done: (err: Error) => void)
 {
   video.stream(player.video.host, player.video.file, page.swf, filePath,
-               path.extname(player.video.file), player.video.mode, done);
+               path.extname(player.video.file), player.video.mode, config.verbose, done);
 }
 
 /**

+ 1 - 0
src/interface/IConfig.d.ts

@@ -19,4 +19,5 @@ interface IConfig {
   video_quality?: string;
   rebuildcrp?: boolean;
   batch?: string;
+  verbose?: boolean;
 }

+ 10 - 2
src/video/merge.ts

@@ -10,10 +10,11 @@ import subtitle from '../subtitle/index';
  * Merges the subtitle and video files into a Matroska Multimedia Container.
  */
 export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: string, filePath: string,
-                        streamMode: string, done: (err: Error) => void)
+                        streamMode: string, verbose: boolean, done: (err: Error) => void)
 {
   const subtitlePath = filePath + '.' + (subtitle.formats[config.format] ? config.format : 'ass');
   let videoPath = filePath;
+  let cp;
 
   if (streamMode === 'RTMP')
   {
@@ -24,7 +25,7 @@ export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: st
     videoPath += '.mp4';
   }
 
-  childProcess.exec(command() + ' ' +
+  cp = childProcess.exec(command() + ' ' +
         '-o "' + filePath + '.mkv" ' +
         '"' + videoPath + '" ' +
         (isSubtitled ? '"' + subtitlePath + '"' : ''), {
@@ -46,6 +47,13 @@ export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: st
       done(null);
     });
   });
+
+  if (verbose === true)
+  {
+    cp.stdin.pipe(process.stdin);
+    cp.stdout.pipe(process.stdout);
+    cp.stderr.pipe(process.stderr);
+  }
 }
 
 /**

+ 18 - 10
src/video/stream.ts

@@ -9,33 +9,41 @@ import log  = require('../log');
  * Streams the video to disk.
  */
 export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string,
-                        fileExt: string, mode: string, done: (err: Error) => void)
+                        fileExt: string, mode: string, verbose: boolean, done: (err: Error) => void)
 {
+  let cp;
+  let cmd;
   if (mode === 'RTMP')
   {
-      childProcess.exec(command('rtmpdump') + ' ' +
+       cmd = command('rtmpdump') + ' ' +
           '-r "' + rtmpUrl + '" ' +
           '-y "' + rtmpInputPath + '" ' +
           '-W "' + swfUrl + '" ' +
-          '-o "' + filePath + fileExt + '"', {
-          maxBuffer: Infinity,
-      }, done);
+          '-o "' + filePath + fileExt + '"';
   }
   else if (mode === 'HLS')
   {
-      const cmd = command('ffmpeg') + ' ' +
+      cmd = command('ffmpeg') + ' ' +
           '-i "' + rtmpInputPath + '" ' +
           '-c copy -bsf:a aac_adtstoasc ' +
           '"' + filePath + '.mp4"';
-      childProcess.exec(cmd,
-      {
-          maxBuffer: Infinity,
-      }, done);
   }
   else
   {
     log.error('No such mode: ' + mode);
   }
+
+  cp = childProcess.exec(cmd,
+  {
+      maxBuffer: Infinity,
+  }, done);
+
+  if (verbose === true)
+  {
+    cp.stdin.pipe(process.stdin);
+    cp.stdout.pipe(process.stdout);
+    cp.stderr.pipe(process.stderr);
+  }
 }
 
 /**