[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 7563c61b7e 2/2: subed-align: Keep comments, don't re
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 7563c61b7e 2/2: subed-align: Keep comments, don't remove silences by default |
Date: |
Wed, 30 Nov 2022 15:00:01 -0500 (EST) |
branch: elpa/subed
commit 7563c61b7e152e0c7e06387edf98809c08cb134f
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
subed-align: Keep comments, don't remove silences by default
* subed/subed-align.el (subed-align-options): Don't remove silences by
default.
(subed-align-reinsert-comments): Reinsert comments.
(subed-align): Reinsert comments in VTT files.
* subed/subed-common.el (jump-to-subtitle-id-at-msecs): Jump even when
not on a sub.
* subed/subed-vtt.el (subed--subtitle-id-at-msecs): Don't try to
optimize by hour/minute.
---
NEWS.org | 6 ++++++
subed/subed-align.el | 21 +++++++++++++++++++--
subed/subed-common.el | 2 +-
subed/subed-vtt.el | 8 --------
subed/subed.el | 2 +-
5 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 5e9753ddcc..152c244ce1 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,6 +1,12 @@
#+OPTIONS: toc:nil
* subed news
+** Version 1.0.26 - 2022-11-30 - Sacha Chua
+
+subed-align now keeps VTT comments. It also doesn't remove silences by
+default now, since aeneas turned out to be a little too aggressive
+about silence detection.
+
** Version 1.0.25 - 2022-11-30 - Sacha Chua
subed-move-subtitles and subed-scale-subtitles are now interactive
diff --git a/subed/subed-align.el b/subed/subed-align.el
index b096d59323..4c8def2adb 100644
--- a/subed/subed-align.el
+++ b/subed/subed-align.el
@@ -38,7 +38,8 @@
(defvar subed-align-options nil
"Other options to include in the aeneas invocation.
-Ex:
task_adjust_boundary_nonspeech_min=0.500|task_adjust_boundary_nonspeech_string=REMOVE")
+Ex:
task_adjust_boundary_nonspeech_min=0.500|task_adjust_boundary_nonspeech_string=REMOVE
+will remove silence and other non-speech spans.")
;;;###autoload
(defun subed-align (audio-file text-file format)
@@ -91,7 +92,23 @@ Return a buffer with FORMAT."
(when (derived-mode-p 'subed-mode)
(subed-trim-overlaps))
(when (derived-mode-p 'subed-vtt-mode)
- (flush-lines "^[0-9]+$")))))
+ (goto-char (point-min))
+ (flush-lines "^[0-9]+$")
+ ;; reinsert comments
+ (subed-align-reinsert-comments subtitles)))))
+
+(defun subed-align-reinsert-comments (subtitles)
+ "Reinsert the comments from SUBTITLES."
+ (goto-char (point-min))
+ (mapc
+ (lambda (sub)
+ (when (elt sub 4)
+ ;; find the first subtitle that matches the sub, although the times may
have changed.
+ ;; Probably the midpoint of the subtitle will still be within the sub
+ ;; TODO: Accommodate comments in other formats
+ (when (subed-jump-to-subtitle-id-at-msecs (/ (+ (elt sub 2) (elt sub
1)) 2))
+ (insert (elt sub 4)))))
+ subtitles))
(provide 'subed-align)
;;; subed-align.el ends here
diff --git a/subed/subed-common.el b/subed/subed-common.el
index c7881d5e9e..1a0d8e7b51 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -224,7 +224,7 @@ Return point or nil if point is still on the same subtitle.
See also `subed-subtitle-id-at-msecs'."
(let ((current-sub-id (subed-subtitle-id))
(target-sub-id (subed-subtitle-id-at-msecs msecs)))
- (when (and target-sub-id current-sub-id (not (equal target-sub-id
current-sub-id)))
+ (when (and target-sub-id (not (equal target-sub-id current-sub-id)))
(subed-jump-to-subtitle-id target-sub-id))))
(subed-define-generic-function jump-to-subtitle-text-at-msecs (msecs)
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index c2a364968a..e41b6a4928 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -84,14 +84,6 @@ Return nil if there is no subtitle at MSECS. Use the
format-specific function for MAJOR-MODE."
(save-excursion
(goto-char (point-min))
- (let* ((secs (/ msecs 1000))
- (only-hours (truncate (/ secs 3600)))
- (only-mins (truncate (/ (- secs (* only-hours 3600)) 60))))
- ;; Move to first subtitle in the relevant hour
- (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:"
subed--regexp-separator only-hours) nil t)
- (beginning-of-line)
- ;; Move to first subtitle in the relevant hour and minute
- (re-search-forward (format "\\(\n\n\\|\\`\\)%02d:%02d" only-hours
only-mins) nil t)))
;; Move to first subtitle that starts at or after MSECS
(catch 'subtitle-id
(while (<= (or (subed-subtitle-msecs-start) -1) msecs)
diff --git a/subed/subed.el b/subed/subed.el
index 307aa2438f..e71c3112dd 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -1,6 +1,6 @@
;;; subed.el --- A major mode for editing subtitles -*- lexical-binding: t;
-*-
-;; Version: 1.0.25
+;; Version: 1.0.26
;; Maintainer: Sacha Chua <sacha@sachachua.com>
;; Author: Random User
;; Keywords: convenience, files, hypermedia, multimedia