Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove duplicate subtitles with aeidon
#!/usr/bin/env python3
import aeidon, sys, time
if len(sys.argv) < 2:
print("Usage: {} SUBTITLE_FILE...".format(__file__))
raise SystemExit(1)
for fname in sys.argv[1:]:
print("{}:".format(fname))
project = aeidon.Project()
project.open_main(fname, "utf_8")
before = len(project.subtitles)
for i in range(before - 1, 1, -1):
if project.subtitles[i] == project.subtitles[i-1]:
del project.subtitles[i]
after = len(project.subtitles)
print("Removed {:d} subtitles.".format(before - after))
ext = project.main_file.format.extension
project.main_file.path = project.main_file.path[:-len(ext)]
project.main_file.path += ".{:.0f}{}".format(time.time(), ext)
print(project.main_file.path)
project.save_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment