I have a batch of files "srt" I want to merge
sub1.srt
sub2.srt1
00:00:21,601 --> 00:00:24,130
- What happened? - It's a mess, I heard.
2
00:00:24,131 --> 00:00:25,900
- What's that? - Dead bodies?
3
00:00:25,901 --> 00:00:28,839
- What's going on? - I wish I knew.
after merge1
00:00:28,840 --> 00:00:31,310
No one knows. They won't say.
2
00:00:31,311 --> 00:00:35,276
- My gosh. - How can so many die?
3
00:00:45,191 --> 00:00:46,556
When you starve,
I found this script that it works The problem is in the numbers The subtitle are not in order1
00:00:21,601 --> 00:00:24,130
- What happened? - It's a mess, I heard.
2
00:00:24,131 --> 00:00:25,900
- What's that? - Dead bodies?
3
00:00:25,901 --> 00:00:28,839
- What's going on? - I wish I knew.
4
00:00:28,840 --> 00:00:31,310
No one knows. They won't say.
5
00:00:31,311 --> 00:00:35,276
- My gosh. - How can so many die?
6
00:00:45,191 --> 00:00:46,556
When you starve,
numbers appear unorderedCode:filenames = ['sub1.srt', 'sub2.srt'] with open('output_file.srt', 'w') as outfile: for fname in filenames: with open(fname) as infile: for line in infile: outfile.write(line)
1
2
3
1
2
3
Note, I know a program "Subtitle Edit" Specialized in merging a group of Subtitles. I want a script to add to My project I'm working on. I hope for help, thank you
+ Reply to Thread
Results 1 to 3 of 3
-
-
try to rename those numbers at the same time as making copy
Code:filenames = ['sub1.srt', 'sub2.srt'] numbers = 0 with open('output_file.srt', 'w') as outfile: for fname in filenames: with open(fname) as infile: for line in infile: try: if 1 <len(line)<6 and isinstance(int(line),int): numbers += 1 line = f'{numbers}\n' except ValueError: pass finally: outfile.write(line) outfile.write('\n\n')
Last edited by _Al_; 7th Nov 2021 at 01:12.
Similar Threads
-
Any way to batch join .srt subtitle files in multiple parts?
By seanmcnally in forum SubtitleReplies: 4Last Post: 14th Apr 2024, 14:21 -
How to merge segmented webvtt subtitle files and output to SRT file?
By smokeweedevryday in forum SubtitleReplies: 0Last Post: 8th Mar 2020, 11:29 -
Copy an .ssa style to multiple subtitle files at once
By vitormathews in forum SubtitleReplies: 2Last Post: 19th Jul 2018, 22:37 -
How to merge multiple .m4s urls into a video file?
By danielko in forum Video Streaming DownloadingReplies: 7Last Post: 24th Oct 2017, 21:50 -
How do I merge two vobsub (idx/sub) subtitle files into one vobsub file
By gilgamesh-au in forum SubtitleReplies: 5Last Post: 2nd Jun 2017, 02:23