Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- # Shift amount in seconds
- shift = 33.640
- # Load the .srt file
- with open('After.Yang.BluRay.x264.AAC-RARBG.srt', 'r') as f:
- lines = f.readlines()
- # Regex pattern to match timestamps
- pattern = r'(\d{2}):(\d{2}):(\d{2}),(\d{3})'
- # Shift the timestamps
- for i, line in enumerate(lines):
- # Find all the timestamps in the line
- matches = list(re.finditer(pattern, line))
- # Shift each timestamp
- for match in matches:
- # Parse the timestamp
- hours = int(match.group(1))
- minutes = int(match.group(2))
- seconds = int(match.group(3))
- milliseconds = int(match.group(4))
- # Convert the timestamp to seconds
- total_seconds = hours * 3600 + minutes * 60 + seconds + milliseconds / 1000
- # Add the shift amount
- total_seconds += shift
- # Convert the shifted timestamp back to hh:mm:ss,ms format
- hours = int(total_seconds // 3600)
- minutes = int((total_seconds % 3600) // 60)
- seconds = int(total_seconds % 60)
- milliseconds = int((total_seconds % 1) * 1000)
- # Replace the timestamp in the line with the shifted timestamp
- line = line[:match.start()] + f"{hours:02d}:{minutes:02d}:{seconds:02d},{milliseconds:03d}" + line[match.end():]
- lines[i] = line
- # Write the modified subtitles to a new .srt file
- with open('output.srt', 'w') as f:
- f.writelines(lines)
Add Comment
Please, Sign In to add comment