Skip to content

Instantly share code, notes, and snippets.

@otsaloma
Last active June 25, 2017 22:37
Show Gist options
  • Save otsaloma/0e54c27ef061c636cf9d338ad058da7d to your computer and use it in GitHub Desktop.
Save otsaloma/0e54c27ef061c636cf9d338ad058da7d to your computer and use it in GitHub Desktop.
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, 0, -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