in Android and IOS, it is indeed cropped . lingq supports only one digit in milliseconds, and will round down to .200 if it is .290
I make all my own subtitles, and the timestamps and audio are very accurate. So if I import with lingq, I have problems with the audio being cropped.
So I wrote a plugin for sublime text4 for python 3.3.6. It rounds up the milliseconds of the end time of the audio, which solves the problem.
This script doesn’t work directly through python, if you want a pure Python script, it may need some modification, feel free to post it after modification.
import sublime
import sublime_plugin
import re
import os
class SrtFixCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Get the entire text content of the file
content = self.view.substr(sublime.Region(0, self.view.size()))
# Define the regex pattern for the timestamps
pattern = r'(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})'
def fix_timestamps(match):
# Split the start and end timestamps
start, end = match.groups()
# Keep the start timestamp unchanged
# Fix the end timestamp
end = self.fix_end_time(end)
# Return the modified timestamp using 'format' method
return '{} --> {}'.format(start, end)
# Replace the timestamps in the content
new_content = re.sub(pattern, fix_timestamps, content)
# Get the current file name and directory
current_file = self.view.file_name()
current_dir = os.path.dirname(current_file)
# Create the new file name
base_name, ext = os.path.splitext(os.path.basename(current_file))
new_file_name = "{}-lingq{}".format(base_name, ext)
new_file_path = os.path.join(current_dir, new_file_name)
# Create a new view and insert the modified content
new_view = self.view.window().new_file()
new_view.insert(edit, 0, new_content)
# Save the new view with the new file name
new_view.retarget(new_file_path)
sublime.status_message("File saved as {}".format(new_file_name))
def fix_end_time(self, timestamp):
# Extract hours, minutes, seconds, and milliseconds
hours, minutes, seconds, milliseconds = map(int, re.split('[:,]', timestamp))
# Increment the milliseconds and handle carry-over
milliseconds = (milliseconds // 100 + 1) * 100
if milliseconds >= 1000:
milliseconds -= 1000
seconds += 1
if seconds >= 60:
seconds -= 60
minutes += 1
if minutes >= 60:
minutes -= 60
hours += 1
# Format the timestamp back with leading zeros
return '{:02}:{:02}:{:02},{}'.format(hours, minutes, seconds, str(milliseconds).ljust(3, '0'))