I had to change
with
in 3 places for it to work for me.
What do you mean exactly by it fails?
I've tried it with a 5 chunk one and it did produce a combined SRT but it does seem to skip the last line of each chunk(hard to say for sure though), unless something else caused those in the 1 long srt I tested so wondering if your issue is the same and I should look further into it or if it was something else.
Edit: I see that it does throw an error when combining but it does still create the file mostly(minus a few lines) but I don't know how it acted before.
Edit2: If you also get similar result than I do, basically the following portion of code(that merges the chunks together) throws some kind of error but I don't know python enough to debug so hard to tell what exactly does:
Code:
with open(mysrt, 'r', encoding='utf-8') as f:
srt = f.read()
match = re.findall(r'\d+:\d+:\d+,\d+ --> \d+:\d+:\d+,\d+', srt)
linerList = []
liner = ""
with open(wordtxt, "r", encoding="utf-8", errors='ignore') as wordfile:
lines = wordfile.readlines()
for line in lines:
if line != '\n' and line is not lines[-1]:
liner += line
elif line != '\n' and len(linerList) == len(match)-1:
liner += line
linerList.append(liner)
break
else:
linerList.append(liner)
liner = ""
count = 0
with open(finalsrt, 'w', encoding='utf-8') as resfile:
for timeline in match:
resfile.write(f"{count+1}\n")
resfile.write(timeline+'\n')
resfile.write(linerList[count])
resfile.write("\n")
count += 1
Edit3: And to get rid of various warnings and errors, you can replace:
Code:
# Start a Selenium driver
driver_path=r'C:\Program Files (x86)\chromedriver.exe'
driver = webdriver.Chrome(driver_path)
with
Code:
s = Service("C:\Program Files (x86)\chromedriver.exe")
chrome_options = Options()
chrome_options.add_argument("--ignore-ssl-errors")
# The following 2 are probably unnecessary but doesn't hurt
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.AcceptInsecureCertificates = True
# Gets rid of USB error
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
# Start a Selenium driver with chosen chrome options
driver = webdriver.Chrome(service=s, options=chrome_options)
And add the following at the beginning(I did after line 3):
Code:
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service