[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 774e5b3f07 9/9: subed-vtt: Handle subtitles with sho
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 774e5b3f07 9/9: subed-vtt: Handle subtitles with short timestamps and comments |
Date: |
Sat, 25 Nov 2023 16:00:55 -0500 (EST) |
branch: elpa/subed
commit 774e5b3f07e064a5ba22ba39d18cf237900e3e92
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
subed-vtt: Handle subtitles with short timestamps and comments
* subed/subed-vtt.el (subed--jump-to-subtitle-id): Jump to timestamp
* tests/test-subed-vtt.el ("VTT"): Add test cases for subtitles with
short timestamps and comments.
---
subed/subed-vtt.el | 4 ++--
tests/test-subed-vtt.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index f8b5a232fe..45de9b99cd 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -130,9 +130,9 @@ Use the format-specific function for MAJOR-MODE."
(if (re-search-forward
(concat
subed--regexp-separator
- (concat "\\(.*\n\\)?" subed-vtt--regexp-timestamp " *--> *"
subed-vtt--regexp-timestamp " *\n")) nil t)
+ (concat "\\(.*\n\\)?\\(" subed-vtt--regexp-timestamp " *--> *"
subed-vtt--regexp-timestamp "\\) *\n")) nil t)
(progn
- (goto-char (or (match-beginning 1) (match-beginning 2)))
+ (goto-char (or (match-beginning 1) (match-beginning 2) (point)))
(point))
(goto-char orig-point)
nil))
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index 7e54ad4c35..22b3a23179 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -215,6 +215,19 @@ Baz.
(expect (subed-jump-to-subtitle-time-start) :to-equal 9)
(expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01.000")))
+ (it "works with short timestamps from a comment."
+ (with-temp-vtt-buffer
+ (insert "WEBVTT\n\nNOTE A comment goes here
+
+09:34.900 --> 00:09:37.659
+Subtitle 1
+
+00:10:34.900 --> 00:11:37.659
+Subtitle 2")
+ (re-search-backward "NOTE")
+ (goto-char (line-beginning-position))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 35)))
+
)
(describe "to subtitle start pos"
(describe "in the current subtitle"
@@ -351,10 +364,34 @@ This is a comment
00:02:02.234 --> 00:02:10.345
Bar.
+
+00:03:02.234 --> 00:03:10.345
+Baz.
")
(re-search-backward "This is a
comment")
(expect (subed-jump-to-subtitle-id)
:not :to-be nil)
- (expect (looking-at (regexp-quote
"00:02:02.234")) :to-be t)))))
+ (expect (looking-at (regexp-quote
"00:02:02.234")) :to-be t)))
+ (it "goes to the timestamp of the subtitle after the comment even
with a short timestamp."
+ (with-temp-vtt-buffer
+ (insert "WEBVTT
+
+1
+00:01:01.000 --> 00:01:05.123
+Foo.
+
+NOTE
+This is a comment
+
+02:02.234 --> 00:02:10.345
+Bar.
+
+00:03:02.234 --> 00:03:10.345
+Baz.
+")
+ (re-search-backward "This is a
comment")
+ (expect (subed-jump-to-subtitle-id)
:not :to-be nil)
+ (expect (looking-at (regexp-quote
"02:02.234")) :to-be t)))
+ ))
(describe "when given an ID"
(it "returns ID's point if wanted time exists."
(with-temp-vtt-buffer
@@ -458,6 +495,18 @@ Bar.
(it "returns nil if movement failed."
(with-temp-vtt-buffer
(expect (subed-jump-to-subtitle-time-stop) :to-equal nil)))
+ (it "works with short timestamps from a comment."
+ (with-temp-vtt-buffer
+ (insert "WEBVTT\n\nNOTE A comment goes here
+
+09:34.900 --> 00:09:37.659
+Subtitle 1
+
+00:10:34.900 --> 00:11:37.659
+Subtitle 2")
+ (re-search-backward "NOTE")
+ (goto-char (line-beginning-position))
+ (expect (subed-jump-to-subtitle-text) :to-equal 62)))
)
(describe "to end of subtitle text"
(it "returns point if subtitle end can be found."
@@ -529,7 +578,18 @@ Bar.
(backward-char)
(expect (subed-jump-to-subtitle-end) :to-be 98)
(expect (looking-at "^$") :to-be t)))
- )
+ (it "works with short timestamps from a comment."
+ (with-temp-vtt-buffer
+ (insert "WEBVTT\n\nNOTE A comment goes here
+
+09:34.900 --> 00:09:37.659
+Subtitle 1
+
+00:10:34.900 --> 00:11:37.659
+Subtitle 2")
+ (re-search-backward "NOTE")
+ (goto-char (line-beginning-position))
+ (expect (subed-jump-to-subtitle-end) :to-equal 72))))
(describe "to next subtitle ID"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
- [nongnu] elpa/subed updated (c9e3ec9963 -> 774e5b3f07), ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed b1ad383ea8 5/9: subed-vtt: iterating shouldn't get confused by blank lines at end, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed a66d2206ee 6/9: New command subed-wpm calculates words per minute, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed 774e5b3f07 9/9: subed-vtt: Handle subtitles with short timestamps and comments,
ELPA Syncer <=
- [nongnu] elpa/subed 6812364955 1/9: test-subed-common.el: Clean up duplicated sexps, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed 63bd6a83a4 2/9: Add tests, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed 10b85e48a0 7/9: subed-vtt: Improve ID and comment handling, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed cea86bccd0 3/9: New hook: subed-subtitle-merged-hook, ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed 8acbd46e54 8/9: Add subed-jump-to-subtitle-start-pos and related function., ELPA Syncer, 2023/11/25
- [nongnu] elpa/subed 430ba0334f 4/9: subed-for-each-subtitle: handle WebVTT header, ELPA Syncer, 2023/11/25