From 243c410775724e10237a19dd81cea9132739c736 Mon Sep 17 00:00:00 2001 From: kolaczyn Date: Thu, 25 Jun 2020 01:50:13 +0200 Subject: [PATCH] finished cleaning up --- clean.sh | 5 +++++ gen-script.py | 39 ++++++++++++--------------------------- run.sh | 3 +-- 3 files changed, 18 insertions(+), 29 deletions(-) create mode 100755 clean.sh diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..c9ad2af --- /dev/null +++ b/clean.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +rm list.txt rip.sh rm output.mp4 +rm -r ../out +mkdir ../out diff --git a/gen-script.py b/gen-script.py index 73b103d..3911eb2 100755 --- a/gen-script.py +++ b/gen-script.py @@ -1,13 +1,9 @@ import re -import sys 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 + +search = '(pesky|bird)' # the searched phrase + # make it so the script rips ~10 second before the subtitle and 10 seconds after # implement overlaping chunks recognition # use regex instead of hardcoding @@ -17,32 +13,21 @@ file_names = [] for file in os.listdir(path): file_names.append(file) -file_names.sort() # not necessary, but it makes the generated script look better +file_names.sort() -data =[] +data = [] for f in file_names: file = open(path + f) for i, line in enumerate(file): - if re.search('(pesky|bird)', line): - data.append({'fname': f, 'beg': prev[0:8], 'end': prev[17:25], 'desc': line}) # get file name, time stamps and desciption - prev = line + if re.search(search, line): + data.append({'fname':f, 'beg':prev[0:8], 'end':prev[17:25], 'desc':line}) # get file name, time stamps and desciption + prev = line # a line just before text is a timestamp -# datestring1 = data[-1][1] -# datestring2 = data[-1][2] -# -# #!!!! t1 = time.strptime(datestring1, "%M:%S") -# #!!!! t2 = time.strptime('00:12', '%M:%S') -# #!!!! start = time.mktime(t1)-time.mktime(t2) -# #!!!! print -# -# 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') + name = d['fname'][:2] # get a name without an extension + outname ="../out/{}-{:0>2}.mp4".format(name, i) + file_list.write("file '{}'\n".format(outname)) + file_rip .write('ffmpeg -ss {} -i ../original/{}.mp4 -to 00:00:12 -c copy {}\n'.format(d['beg'], name, outname)) diff --git a/run.sh b/run.sh index 7fe374e..1c80eec 100755 --- a/run.sh +++ b/run.sh @@ -4,6 +4,5 @@ # is an URL of a youtube playlist/ video you want to edit python gen-script.py -bash rip.bash +bash rip.sh ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4 # splice all the clips -rm list.txt rip.sh # cleanup