subsync icon indicating copy to clipboard operation
subsync copied to clipboard

Recursively split subtitles where spaces occur

Open tympanix opened this issue 5 years ago • 1 comments

tympanix avatar Jul 16 '18 12:07 tympanix

With srt3, you can use the following code to split subtitles and remove the space between them (once the timestamps of the space are found):

# Finds all subtitles up to :05, and after :08 using srt3 (version 1.0.0)
import srt

# Parse the srt file at some point.
subs = srt.parse("subtitle content")

# Use the find method to filter out space.
space_start = srt.timestamp_to_timedelta("00:00:05,00")
space_end = srt.timestamp_to_timedelta("00:00:08,00")
new_subs = srt.tools.find.find_by_timestamp(subs, space_end, space_start) # returns a generator of subtitles

srt3 also performs 30% faster than pysrt on typical workloads.

switchupcb avatar Jul 15 '21 23:07 switchupcb