From 6761d4541c25f5b115de7506c188ef01b934e900 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Date: Tue, 8 Jun 2021 18:25:15 +0530 Subject: [PATCH 1/2] Trying to avoid repetition --- VTT Formatter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VTT Formatter.py b/VTT Formatter.py index f9af72f..514774d 100644 --- a/VTT Formatter.py +++ b/VTT Formatter.py @@ -28,6 +28,7 @@ print "Formating : "+file #Shows current File with open(os.path.join(sys.argv[1], file)) as f: + previous = '0' for line in f: #a line for each file if not line.startswith('0') : #Couldnt Get the "or" working if not line.startswith('WEBVTT') :#Cleaning @@ -35,6 +36,8 @@ if not line.startswith('Language:') :#Cleaning if not line.startswith('\n') :#Cleaning if not line.startswith('[BLANK_AUDIO]') :#Cleaning + if not line.startswith(previous) :#Avoiding repetitions newfile.write("%s" % line) #Add new line to new file combined.write("%s" % line) #Add new line to combinedfile + previous = line print "DONE!" #NEXT ONE! From f2901f9a164c81f006e65c5000a42daec9075497 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Date: Tue, 8 Jun 2021 18:41:30 +0530 Subject: [PATCH 2/2] This one works with python3 and avoids any repetition in consecutive lines! --- VTT Formatter.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/VTT Formatter.py b/VTT Formatter.py index 514774d..ea2709a 100644 --- a/VTT Formatter.py +++ b/VTT Formatter.py @@ -14,7 +14,7 @@ # $ VTT Formatter.py [DIR] # $ VTT Formatter.py ./subs -print "Searching inside : "+sys.argv[1] +print(f"Searching inside : {sys.argv[1]}") newdirectory = sys.argv[1]+"txt" if not os.path.exists(newdirectory): @@ -25,19 +25,19 @@ newfile = open(os.path.join(newdirectory,file.replace(".vtt", ".txt")),'w') #Creates a newfile if file.endswith(".vtt"): - print "Formating : "+file #Shows current File + print("Formating : "+file) #Shows current File with open(os.path.join(sys.argv[1], file)) as f: previous = '0' for line in f: #a line for each file - if not line.startswith('0') : #Couldnt Get the "or" working + if line.find('-->') == -1 : #Avoid timestanps if not line.startswith('WEBVTT') :#Cleaning if not line.startswith('Kind:') :#Cleaning if not line.startswith('Language:') :#Cleaning if not line.startswith('\n') :#Cleaning if not line.startswith('[BLANK_AUDIO]') :#Cleaning if not line.startswith(previous) :#Avoiding repetitions - newfile.write("%s" % line) #Add new line to new file - combined.write("%s" % line) #Add new line to combinedfile - previous = line - print "DONE!" #NEXT ONE! + newfile.write("%s" % line) #Add new line to new file + combined.write("%s" % line) #Add new line to combinedfile + previous = line + print("DONE!") #NEXT ONE!