Browse Source

Add strip-first/strip-last logic to offset fixer

Breandan Dezendorf 2 năm trước cách đây
mục cha
commit
5d5d05c743
1 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 14 1
      dezendorf/applications/offset-fixer/offset-fixer.py

+ 14 - 1
dezendorf/applications/offset-fixer/offset-fixer.py

@@ -54,6 +54,8 @@ def main():
   parser.add_argument("--file", help="Subtitle file to shift", type=str, required=True)
   parser.add_argument("--inplace", required=False, help="Shift file in place, creating a backup", action='store_true')
   parser.add_argument("--outfile", required=False, help="New subtitle filename", type=str)
+  parser.add_argument("--strip-first", required=False, help="Clear first subtitle entry", action='store_true')
+  parser.add_argument("--strip-last", required=False, help="Clear last subtitle entry", action='store_true')
 
   args = parser.parse_args()
 
@@ -97,9 +99,20 @@ def main():
         print(entry.formatEntry(), file=o)
 
   print("Updating subtitle file: " + args.outfile)
+  lastEntryNumber = Subtitles[-1].entryNumber
   with open(args.outfile, 'w') as o:
     print("Shifting all entries by {} seconds".format(args.seconds))
-    for entry in Subtitles:
+    for idx, entry in enumerate(Subtitles):
+      if idx == 0:
+        print("First subtitle line: {}".format(entry.text))
+        if args.strip_first and entry.text != "":
+          print("Stripping first line - {}".format(entry.text))
+          entry.text = ""
+      if idx == lastEntryNumber - 1:
+        print("Last subtitle line: {}".format(entry.text))
+        if args.strip_last and entry.text != "":
+          print("Stripping last line - {}".format(entry.text))
+          entry.text = ""
       entry.shift(args.seconds)
       print(entry.formatEntry(), file=o)