456 """ |
458 """ |
457 if not self.command: |
459 if not self.command: |
458 return None |
460 return None |
459 if not self.info["msg_eit"]: |
461 if not self.info["msg_eit"]: |
460 self.info["msg_eit"] = "No EIT file found, sorry - no description" |
462 self.info["msg_eit"] = "No EIT file found, sorry - no description" |
461 fd = open(self.outfilebase + ".txt", "wb") |
463 if not self.config["dryrun"]: |
462 fd.write(self.info["msg_eit"]) |
464 fd = open(self.outfilebase + ".txt", "wb") |
463 fd.write("\n\n# ---DEBUG---\n\n") |
465 fd.write(self.info["msg_eit"]) |
464 fd.write(self.info["msg_prepare"]) |
466 fd.write("\n\n# ---DEBUG---\n\n") |
465 fd.write(self.info["msg_ffmpeg"]) |
467 fd.write(self.info["msg_prepare"]) |
466 fd.close() |
468 fd.write(self.info["msg_ffmpeg"]) |
|
469 fd.close() |
467 #print self.info["msg_ffmpeg"] |
470 #print self.info["msg_ffmpeg"] |
468 |
471 |
469 for cmd in self.command: |
472 for cmd in self.command: |
470 print "Executing ffmpeg:\n%s\n" % cmd |
473 print "Executing ffmpeg:\n%s\n" % cmd |
471 #return run_command(cmd, self.total_frames) |
474 #return run_command(cmd, self.total_frames) |
472 return run_ffmpeg_watch(cmd, frames_total=self.info["frames_total"]) |
475 if not self.config["dryrun"]: |
|
476 return run_ffmpeg_watch(cmd, frames_total=self.info["frames_total"]) |
|
477 else: |
|
478 return 0 |
473 |
479 |
474 |
480 |
475 |
481 |
476 if __name__ == "__main__": |
482 if __name__ == "__main__": |
477 # parse command line options |
483 # parse command line options |
482 help='h264 crf (default 19)') |
488 help='h264 crf (default 19)') |
483 parser.add_argument('--tune', default='film', \ |
489 parser.add_argument('--tune', default='film', \ |
484 help='ffmpeg tune preset [film, animation] (default is film)') |
490 help='ffmpeg tune preset [film, animation] (default is film)') |
485 parser.add_argument('--ns', action='store_true', default=False, \ |
491 parser.add_argument('--ns', action='store_true', default=False, \ |
486 help='no rescaling (default is scale to 720p)') |
492 help='no rescaling (default is scale to 720p)') |
487 parser.add_argument('--rename', action='store_true', default=False, \ |
|
488 help='rename file basename to name and genre from EIT file if present') |
|
489 parser.add_argument('input', metavar='input', nargs='+', \ |
|
490 help='one or more files, glob style syntax') |
|
491 parser.add_argument('-f', action='store_true', default=False, \ |
493 parser.add_argument('-f', action='store_true', default=False, \ |
492 help='force overwrite of existing file') |
494 help='force overwrite of existing file') |
493 parser.add_argument('--fa', action='store_true', default=False, \ |
495 parser.add_argument('--fa', action='store_true', default=False, \ |
494 help='use first audio stream found') |
496 help='force use first audio stream') |
|
497 parser.add_argument('--rename', action='store_true', default=False, \ |
|
498 help='rename file basename to name and genre from EIT file if present') |
|
499 parser.add_argument('--moveto', default='', \ |
|
500 help='specify base directory to move processed files to') |
|
501 parser.add_argument('--dryrun', action='store_true', default=False, \ |
|
502 help='Dry-run, dont touch anything') |
|
503 parser.add_argument('input', metavar='input', nargs='+', \ |
|
504 help='one or more files, glob style syntax') |
495 |
505 |
496 args = parser.parse_args() |
506 args = parser.parse_args() |
497 processor = ts2mkv(crf=args.crf, tune=args.tune) |
507 processor = ts2mkv(crf=args.crf, tune=args.tune) |
498 processor.config["scaledown"] = not args.ns |
508 processor.config["scaledown"] = not args.ns |
499 processor.config["rename"] = args.rename |
509 processor.config["rename"] = args.rename |
500 processor.config["overwrite"] = args.f |
510 processor.config["overwrite"] = args.f |
501 processor.config["firstaudio"] = args.fa |
511 processor.config["firstaudio"] = args.fa |
|
512 processor.config["dryrun"] = args.dryrun |
502 |
513 |
503 src = [] |
514 src = [] |
504 for srcstr in args.input: |
515 for srcstr in args.input: |
505 src.extend(glob.glob(srcstr)) |
516 src.extend(glob.glob(srcstr)) |
506 idx = 1 |
517 idx = 1 |
507 for srcfile in src: |
518 for srcfile in src: |
508 print "\nProcessing file %i/%i: %s" % (idx, len(src), srcfile) |
519 print "\nProcessing file %i/%i: %s" % (idx, len(src), srcfile) |
509 processor.load(srcfile) |
520 processor.load(srcfile) |
510 processor.convert() |
521 exitcode = processor.convert() |
|
522 if exitcode == 0: |
|
523 print "Successful conversion." |
|
524 if args.moveto: |
|
525 mvlist = glob.glob(os.path.splitext(srcfile)[0] + ".*") |
|
526 mvtarget = os.path.dirname(srcfile).replace('../', '') |
|
527 mvtarget = os.path.join( |
|
528 args.moveto, mvtarget) |
|
529 mvsource = os.path.dirname(srcfile) |
|
530 print "Moving processed files from %s to %s" % ( |
|
531 mvsource, mvtarget) |
|
532 if not args.dryrun: |
|
533 os.makedirs(mvtarget) |
|
534 for mvsrc in mvlist: |
|
535 mvfn = os.path.basename(mvsrc) |
|
536 if os.path.splitext(mvfn)[1] in ['.txt', '.mkv', '.nfo']: |
|
537 continue |
|
538 print mvfn |
|
539 if not args.dryrun: |
|
540 os.rename( |
|
541 os.path.join(mvsource, mvfn), |
|
542 os.path.join(mvtarget, mvfn)) |
|
543 else: |
|
544 print "ERROR while executing ffmpeg!" |
511 idx += 1 |
545 idx += 1 |
512 |
546 |
513 |
547 |