From b4aa216c99a34f4c9313b9b713f52f4a56b2ce4a Mon Sep 17 00:00:00 2001 From: kolaczyn Date: Thu, 25 Jun 2020 00:27:18 +0200 Subject: [PATCH] after refactoring, it works! --- .gitignore | 3 ++- gen-script.py | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 191b2a4..70a1484 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ list.txt -script.sh +rip.sh +output.mp4 diff --git a/gen-script.py b/gen-script.py index 8c012ff..73b103d 100755 --- a/gen-script.py +++ b/gen-script.py @@ -4,12 +4,13 @@ from pathlib import Path import os import time from datetime import datetime, timedelta - +# jargon explanation: rip - 10-20 second part of a video # # TODO: # remove not used imports # searched string is hardcoded. fix that # make it so the script rips ~10 second before the subtitle and 10 seconds after # implement overlaping chunks recognition +# use regex instead of hardcoding path = os.getcwd() + '/../subs/' # subtitles location file_names = [] @@ -35,13 +36,13 @@ for f in file_names: # #!!!! start = time.mktime(t1)-time.mktime(t2) # #!!!! print # -# out_file = open('rip.sh', 'w') -# out_list = open('list.txt', 'w') -# for (i, t) in enumerate(data): -# name = t[0][:2] -# vid_fil = 'out/'+ name + '-' + str(i)+'.mp4' -# out_list.write('file \'' + vid_fil + "'\n") -# out_file.write('ffmpeg -ss ' + t[1] + ' -i ' + name + '.mp4 -to ' + '00:00:12' + ' -c copy out/' + name + '-' + str(i) + '.mp4\n' ) -# -# os.system('bash script.sh') -# #!!!!os.system('ffmpeg -f concat -safe 0 -i list.txt -c copy out.mp4') +# TODO I am using enumerato to make it so different rips from the same video +# have a different name and are in order. the order won't work if there is more +# than 9 rips from the same video +file_rip = open('rip.sh', 'w') +file_list = open('list.txt', 'w') +for (i, d) in enumerate(data): + name = d['fname'][:2] # get a name without an extension, eg. 02.srt -> 02 + outname = '../out/' + name + '-' + str(i) + ".mp4" # name of a rip, eg ../out/02-4.mp4 + file_list.write("file '" + outname + "''\n") # TODO use {} or %s instead of + + file_rip .write('ffmpeg -ss ' + d['beg'] + ' -i ../original/' + name + '.mp4 -to ' + '00:00:12' + ' -c copy ' +outname+'\n')