It has 100 asynchronous Subtitles in Indonesian and 100 Synchronized Subtitles into English
Is there a script that adjusts the subtitle of the first line to be synchronous
SUB.Indonesian.srt
SUB.English.srtCode:1 00:00:02,040 --> 00:00:04,410 "Episode Satu" 2 00:00:05,179 --> 00:00:07,610 "Tujuh tahun lalu" 3 00:00:23,859 --> 00:00:25,800 Ada apa? Kenapa kalian tidak memakai baju olahraga?
after.sync.srtCode:1 00:00:07,551 --> 00:00:09,920 (Episode 1) 2 00:00:10,691 --> 00:00:13,231 (7 years ago) 3 00:00:29,440 --> 00:00:31,381 What's going on? Why aren't you in your gym clothes?
Code:1 00:00:07,551 --> 00:00:09,921 "Episode Satu" 2 00:00:10,690 --> 00:00:13,121 "Tujuh tahun lalu" 3 00:00:29,370 --> 00:00:31,311 Ada apa? Kenapa kalian tidak memakai baju olahraga?
batch
SUB.English_%%x.srt SUB.Indonesian_%%x.srt after.sync_%%x.srt
I know a Subtitle Edit , but it only works with one subtitle
All I need is sync from the first line only. Using Python Any suggestions?
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 5 of 5
Thread
-
-
this is an example calling for one pair, that could be fed from something, not sure how you store those srt's
Code:def sec2time(sec): ''' Convert seconds to 'D days, HH:MM:SS.FFF' ''' m, s = divmod(sec, 60) h, m = divmod(m, 60) d, h = divmod(h, 24) pattern = '%%02d:%%02d:%%0%d.%df' % (6, 3) if d == 0: return pattern % (h, m, s) return (f'{h:d}:{m:02d}:{s:02d}') def time2sec(time): time = time.replace(',','.') h, m, s = map(float, time.split(':')) return h * 3600 + m * 60 + s def get_first_time(filename): with open(filename, 'r+') as f: for line in f: if '-->' in line: time = line.split('-->')[0].strip() return time2sec(time) def sync_first_sub(used_subtitles_srt, for_first_time_srt, new_srt): delay_in_sec = get_first_time(for_first_time_srt) - get_first_time(used_subtitles_srt) with open(used_subtitles_srt, 'r+') as f, open(new_srt, 'w') as w: for line in f: if '-->' in line: new_start_sec = time2sec(line.split('-->')[0].strip()) + delay_in_sec new_start_time = sec2time(new_start_sec).replace('.',',') new_end_sec = time2sec(line.split('-->')[1].strip()) + delay_in_sec new_end_time = sec2time(new_end_sec).replace('.',',') w.write(new_start_time+ ' --> ' + new_end_time + '\n') else: w.write(line) sync_first_sub(used_subtitles_srt=r'F:\path\SUB.Indonesian.srt', for_first_time_srt=r'F:\path\SUB.English.srt', new_srt=r'F:\path\after_sync.srt')
Last edited by _Al_; 17th Nov 2021 at 23:37.
-
After trying, an error message appears
https://forum.videohelp.com/images/imgfiles/UNjZoKk.jpg
If you do a script that works on which path is better
Example
batch
Code:echo off sync.py "SUB.Indonesian.srt" "SUB.English.srt" "after_sync.srt" pause
-
you need three full correct paths for that script when calling sync_first_sub function
How do you have those srt's in your folder or folders and how are they named?
Code:echo off sync.py "SUB.Indonesian.srt" "SUB.English.srt" "after_sync.srt" pause
Code:if __name__ == '__main__': import os import sys source_paths = [] if len(sys.argv) > 1: for i, path in enumerate(sys.argv[1:]): if i < 2 and not os.path.isfile(path): raise ValueError(f'Not a valid path or file does not exist: {path}') source_paths.append(path) if i < 2: raise ValueError(f'Three path arguments needed') source_paths = source_paths[0:3] source_paths = [os.path.abspath(path) for path in source_paths] sync_first_sub(source_paths[0], source_paths[1], source_paths[2])
Last edited by _Al_; 18th Nov 2021 at 10:28.
Similar Threads
-
Multi-line, heavily stylized subtitles (ASS) possible on Blu-ray?
By Deli295 in forum Authoring (Blu-ray)Replies: 12Last Post: 25th Jan 2021, 15:41 -
Python Batch Creating avs Scripts
By pandachinoman in forum ProgrammingReplies: 5Last Post: 23rd Oct 2020, 09:18 -
Get a list of Youtube video titles from a list of URLs
By abolibibelot in forum Video Streaming DownloadingReplies: 3Last Post: 12th Oct 2020, 04:42 -
Help Needed With Python ffprobe Script
By chris319 in forum ProgrammingReplies: 11Last Post: 28th Jun 2019, 10:15 -
Synchronizing Subtitles - DVD / Bluray x Netflix / Youtube / Similar Sites
By devilcoelhodog in forum SubtitleReplies: 4Last Post: 2nd Feb 2018, 14:48