diff --git a/video.py b/video.py index 73d16fb..c721881 100644 --- a/video.py +++ b/video.py @@ -31,29 +31,30 @@ def convert(origin, target): cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin, target) print("cmd:: {0}".format(cmd)) args = shlex.split(cmd) - status, output = sp.getstatusoutput(cmd) - print("status:: {0}, output {1}".format(status, output)) - if status ==0: - print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) - os.remove(origin) - else: - print("{0} convert fail".format(origin)) - #proc = sp.Popen(args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE) - #answer = b'Overwrite ? [y/N]' - #try: - # outs, errs = proc.communicate() - # print(outs, errs) - # print("answer in outs : {0}".format(answer in errs)) - # if answer in errs: - # print('write y') - # # proc.stdin.write(b'y') - # if proc.returncode == 0: - # print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) - # os.remove(origin) - # else: - # print("{0} convert fail".format(origin)) - #except sp.TimeoutExpired: - # proc.kill() + #status, output = sp.getstatusoutput(cmd) + #print("status:: {0}, output {1}".format(status, output)) + #if status ==0: + # print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) + # os.remove(origin) + #else: + # print("{0} convert fail".format(origin)) + proc = sp.Popen(args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE) + answer = b'Overwrite ? [y/N]' + try: + outs, errs = proc.communicate() + print(outs, errs) + print("answer in outs : {0}".format(answer in errs)) + if answer in errs: + print('write y') + continue + # proc.stdin.write(b'y') + if proc.returncode == 0: + print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) + os.remove(origin) + else: + print("{0} convert fail".format(origin)) + except sp.TimeoutExpired: + proc.kill() if __name__ == "__main__": @@ -62,4 +63,4 @@ if __name__ == "__main__": codec = sys.argv[1] # timeout=sys.argv[2] print("codec:: {0}".format(codec)) - list_folder(DAT_FOLDER, TARGET_FOLDER, codec) \ No newline at end of file + list_folder(DAT_FOLDER, TARGET_FOLDER, codec)