From 53de34da5124c10bd6b9ecc39f805164a785ca23 Mon Sep 17 00:00:00 2001
From: rlaphoenix <rlaphoenix@pm.me>
Date: Fri, 29 Dec 2023 16:20:04 +0000
Subject: [PATCH] Add `remove_multi_lang_srt_header()` method to Subtitle class

---
 devine/core/tracks/subtitle.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/devine/core/tracks/subtitle.py b/devine/core/tracks/subtitle.py
index d7e4fbb..8cbc73e 100644
--- a/devine/core/tracks/subtitle.py
+++ b/devine/core/tracks/subtitle.py
@@ -418,6 +418,27 @@ class Subtitle(Track):
             stdout=subprocess.DEVNULL
         )
 
+    def remove_multi_lang_srt_header(self) -> None:
+        """
+        Remove Multi-Language SRT Header from Subtitle.
+
+        Sometimes a SubRip (SRT) format Subtitle has a "MULTI-LANGUAGE SRT" line,
+        when it shouldn't. This can cause Subtitle format/syntax errors in some
+        programs including mkvmerge/MKVToolNix.
+
+        This should only be used if it truly is a normal SubRip (SRT) subtitle
+        just with this line added by mistake.
+        """
+        if not self.path or not self.path.exists():
+            raise ValueError("You must download the subtitle track first.")
+
+        if self.codec != Subtitle.Codec.SubRip:
+            raise ValueError("Only SubRip (SRT) format Subtitles have the 'MULTI-LANGUAGE SRT' header.")
+
+        srt_text = self.path.read_text("utf8")
+        fixed_srt_text = srt_text.replace("MULTI-LANGUAGE SRT\n", "")
+        self.path.write_text(fixed_srt_text, "utf8")
+
     def __str__(self) -> str:
         return " | ".join(filter(bool, [
             "SUB",