Skip to content

Commit

Permalink
Add "Keep old subtitles" button for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleeraphie committed Mar 8, 2024
1 parent 386f1b0 commit 2bbc27d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self):
[sg.Checkbox("Edit subtitles before muxing", key="-edit-")],
[sg.Checkbox("Save images of PGS subtitles", key="-save-")],
[sg.Checkbox("Keep original MKV files", key="-keep_old_mkvs-")],
[sg.Checkbox("Keep a copy of the new subtitle files", key="-keep_subs-")],
[sg.Checkbox("Keep a copy of the old subtitle files", key="-keep_old_subs-", default=True)],
[sg.Checkbox("Keep a copy of the new subtitle files", key="-keep_new_subs-")],
[sg.Checkbox("Use different language for some subtitles", enable_events=True, key="-diff-")],
[sg.Text(text="Usage: one change per line; old language code -> new language code, example: ger -> eng", visible=False, key="-diff_langs_text-")],
[sg.Multiline(enable_events=True, size=(89, 20), key="-diff_langs-", visible=False)]
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

if exit_code == 0:
diff_langs = values["-diff_langs-"] if values["-diff-"] else ""
sc = SubtitleConverter(gui.selected_paths, values["-edit-"], values["-save-"], values["-keep_old_mkvs-"], values["-keep_subs-"],
sc.diff_langs_from_text(diff_langs), sc.sub_format_extension(values["-format-"]))
sc = SubtitleConverter(gui.selected_paths, values["-edit-"], values["-save-"], values["-keep_old_mkvs-"], values["-keep_old_subs-"],
values["-keep_new_subs-"], sc.diff_langs_from_text(diff_langs), sc.sub_format_extension(values["-format-"]))

sc.convert()
elif exit_code == 1:
Expand Down
23 changes: 12 additions & 11 deletions subconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

class SubtitleConverter:

def __init__(self, files: list = None, edit_flag: bool = False, keep_imgs: bool = False, keep_old_mkvs: bool = False, keep_subs: bool = False, diff_langs: bool = False, sub_format: str = "SubRip Text (.srt)"):
def __init__(self, files: list = None, edit_flag: bool = False, keep_imgs: bool = False, keep_old_mkvs: bool = False, keep_old_subs: bool = False, keep_new_subs: bool = False, diff_langs: bool = False, sub_format: str = "SubRip Text (.srt)"):
if files is None:
files = []

self.file_paths = files
self.edit_flag = edit_flag
self.keep_imgs = keep_imgs
self.keep_old_mkvs = keep_old_mkvs
self.keep_subs = keep_subs
self.keep_old_subs = keep_old_subs
self.keep_new_subs = keep_new_subs
self.diff_langs = diff_langs
self.format = sub_format

Expand Down Expand Up @@ -256,17 +257,17 @@ def clean(self):

print("Cleaning up...\n")

if not self.keep_subs:
shutil.rmtree(self.sub_dir)
else:
if not (self.keep_old_subs or self.keep_new_subs):
if not self.keep_imgs:
shutil.rmtree(f"subtitles\{self.file_name}")
else:
shutil.rmtree(self.sub_dir)
elif not self.keep_old_subs:
for track_id in self.subtitle_ids:
self.silent_remove(f"{self.sub_dir}\{track_id}.sup")

if self.format != "srt":
self.silent_remove(f"{self.sub_dir}\{track_id}.srt")

if not self.keep_imgs and not self.keep_subs:
shutil.rmtree(f"subtitles\{self.file_name}")
elif not self.keep_new_subs:
for track_id in self.subtitle_ids:
self.silent_remove(f"{self.sub_dir}\{track_id}.srt")

if not self.keep_old_mkvs:
os.remove(self.file_path)
Expand Down

0 comments on commit 2bbc27d

Please sign in to comment.