[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 7a90fd74d3 3/3: subed-split-subtitle: Accept offset
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 7a90fd74d3 3/3: subed-split-subtitle: Accept offset as a timestamp |
Date: |
Wed, 16 Nov 2022 18:59:30 -0500 (EST) |
branch: elpa/subed
commit 7a90fd74d3e1b16b17eb4e46a223b1afb1448625
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
subed-split-subtitle: Accept offset as a timestamp
* subed/subed-common.el (split-subtitle): Accept offset as a
timestamp.
* tests/test-subed-common.el ("COMMON"): Add test for splitting with a
timestamp.
---
NEWS.org | 10 ++++++++++
subed/subed-common.el | 22 ++++++++++++++++------
subed/subed.el | 2 +-
tests/test-subed-common.el | 11 ++++++++++-
4 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 5140085216..2ca917fd27 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,6 +1,16 @@
#+OPTIONS: toc:nil
* subed news
+
+** Version 1.0.21 - 2022-11-16 - Sacha Chua
+
+- subed-align-options is a new variable that will be passed to aeneas
+ during execution.
+- Calling subed-split-subtitle with the C-u prefix will now allow you
+ to specify either an offset or a timestamp. If a timestamp is
+ specified, it will be used as the starting timestamp of the second
+ subtitle.
+
** Version 1.0.20 - 2022-11-16 - Sacha Chua
subed now talks about media files instead of video files, since audio
diff --git a/subed/subed-common.el b/subed/subed-common.el
index 558434108a..62c1267d1a 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -1184,7 +1184,8 @@ inserted after the current subtitle.
If OFFSET is a number, it is used as the offset in milliseconds
from the starting timestamp if positive or from the ending
-timestamp if negative. Otherwise, if
+timestamp if negative. If OFFSET is a timestamp, it is used
+as the starting timestamp of the second subtitle. Otherwise, if
`subed-mpv-playback-position' is within the current subtitle, it
is used as the new stop time of the current subtitle. Otherwise,
the timestamp proportional to the point's position between start
@@ -1206,7 +1207,7 @@ position of the point."
(interactive (list
(cond
((equal current-prefix-arg '(4))
- (read-number "Offset (ms): "))
+ (read-string "Offset (ms or timestamp): "))
((equal current-prefix-arg '(16)) t))))
(let ((text-beg (save-excursion (subed-jump-to-subtitle-text)))
(text-end (save-excursion (or (subed-jump-to-subtitle-end) (point)))))
@@ -1214,12 +1215,21 @@ position of the point."
(unless (and text-beg (>= (point) text-beg))
(subed-jump-to-subtitle-text))
(let* ((orig-end (subed-subtitle-msecs-stop))
+ (offset-ms
+ (cond
+ ((null offset) nil)
+ ((numberp offset) offset)
+ ((and (stringp offset) (string-match "^-?[0-9]*\\.[0-9]*" offset))
+ (string-to-number offset))))
(split-timestamp
(cond
- ((and (numberp offset) (> offset 0))
- (+ (subed-subtitle-msecs-start) offset))
- ((and (numberp offset) (< offset 0))
- (+ orig-end offset))
+ (offset-ms
+ (if (> offset-ms 0)
+ (+ (subed-subtitle-msecs-start) offset-ms)
+ (+ orig-end offset-ms)))
+ ((stringp offset)
+ (- (subed-timestamp-to-msecs offset)
+ subed-subtitle-spacing))
(t (run-hook-with-args-until-success
'subed-split-subtitle-timestamp-functions))))
(new-text (string-trim (buffer-substring (point) text-end)))
(new-start-timestamp (and split-timestamp (+ split-timestamp
subed-subtitle-spacing))))
diff --git a/subed/subed.el b/subed/subed.el
index 0c8244965e..e5f340109f 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.20
+;; Version: 1.0.21
;; Maintainer: Sacha Chua <sacha@sachachua.com>
;; Author: Random User
;; Keywords: convenience, files, hypermedia, multimedia
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index 444f38338f..3cc3db05a7 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -2325,7 +2325,16 @@ This is another.
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
(subed-regenerate-ids)
- (expect (subed-subtitle-text 2) :to-equal "")))))
+ (expect (subed-subtitle-text 2) :to-equal "")))
+ (it "accepts a timestamp."
+ (with-temp-srt-buffer
+ (insert text)
+ (re-search-backward "subtitle")
+ (end-of-line)
+ (subed-split-subtitle "00:01:03,100")
+ (expect (subed-subtitle-msecs-start) :to-equal 63100)
+ (subed-backward-subtitle-time-start)
+ (expect (subed-subtitle-msecs-stop) :to-equal (- 63100
subed-subtitle-spacing))))))
(describe "when playing the media in MPV"
(it "splits at point in the middle of the subtitle."
(with-temp-srt-buffer