[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 70561f0 381/389: Make hours optional in VTT files, f
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 70561f0 381/389: Make hours optional in VTT files, following the spec |
Date: |
Fri, 3 Dec 2021 11:01:02 -0500 (EST) |
branch: elpa/subed
commit 70561f065c48f938addfc43a1a75c5d2e22d84f5
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
Make hours optional in VTT files, following the spec
* subed/subed-vtt.el (subed-vtt-font-lock-keywords): Make hours optional.
(subed-vtt--regexp-timestamp): Make hours optional.
(subed-vtt--timestamp-to-msecs): Make hours optional.
(subed-vtt--jump-to-subtitle-id): Make hours optional.
* tests/test-subed-vtt.el ("VTT"): Add test for optional hours.
---
subed/subed-vtt.el | 14 +++++++-------
tests/test-subed-vtt.el | 5 +++++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index 20124e8..f0fd28f 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -35,7 +35,7 @@
(defconst subed-vtt-font-lock-keywords
(list
- '("[0-9]+:[0-9]+:[0-9]+\\.[0-9]+" . 'subed-vtt-time-face)
+ '("\\([0-9]+:\\)?[0-9]+:[0-9]+\\.[0-9]+" . 'subed-vtt-time-face)
'(",[0-9]+ \\(-->\\) [0-9]+:" 1 'subed-vtt-time-separator-face t)
'("^.*$" . 'subed-vtt-text-face))
"Highlighting expressions for `subed-mode'.")
@@ -43,7 +43,7 @@
;;; Parsing
-(defconst subed-vtt--regexp-timestamp
"\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)")
+(defconst subed-vtt--regexp-timestamp
"\\(\\([0-9]+\\):\\)?\\([0-9]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)")
(defconst subed-vtt--regexp-separator "\\(?:[[:blank:]]*\n\\)+[[:blank:]]*\n")
(defun subed-vtt--timestamp-to-msecs (time-string)
@@ -51,10 +51,10 @@
Return nil if TIME-STRING doesn't match the pattern."
(save-match-data
(when (string-match subed-vtt--regexp-timestamp time-string)
- (let ((hours (string-to-number (match-string 1 time-string)))
- (mins (string-to-number (match-string 2 time-string)))
- (secs (string-to-number (match-string 3 time-string)))
- (msecs (string-to-number (subed--right-pad (match-string 4
time-string) 3 ?0))))
+ (let ((hours (string-to-number (or (match-string 2 time-string) "0")))
+ (mins (string-to-number (match-string 3 time-string)))
+ (secs (string-to-number (match-string 4 time-string)))
+ (msecs (string-to-number (subed--right-pad (match-string 5
time-string) 3 ?0))))
(+ (* (truncate hours) 3600000)
(* (truncate mins) 60000)
(* (truncate secs) 1000)
@@ -170,7 +170,7 @@ WebVTT doesn't use IDs, so we use the starting timestamp
instead."
(when match-found
(goto-char (match-beginning 2)))))
;; Make extra sure we're on a timestamp, return nil if we're not
- (when (looking-at "^\\([0-9]+:[0-9]+:[0-9]+\\.[0-9]+\\)")
+ (when (looking-at "^\\(\\([0-9]+:\\)?[0-9]+:[0-9]+\\.[0-9]+\\)")
(point))))
(defun subed-vtt--jump-to-subtitle-id-at-msecs (msecs)
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index 71b4de9..04c244c 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -39,6 +39,11 @@ Baz.
(thing-at-point 'line)) :to-equal
"00:03:03.45 --> 00:03:15.5\n")
(expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000)
(* 3 1000) 450))
(expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000)
(* 15 1000) 500))))
+ (it "handles lack of hours in milliseconds gracefully."
+ (with-temp-vtt-buffer
+ (insert "WEBVTT\n\n01:02.000 --> 03:04.000\nHello\n")
+ (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 1 60 1000)
(* 2 1000)))
+ (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000)
(* 4 1000)))))
(it "returns nil if time can't be found."
(with-temp-vtt-buffer
(expect (subed-vtt--subtitle-msecs-start) :to-be nil)
- [nongnu] elpa/subed 5de6f21 377/389: Add msecs-to-timestamp as a common function, (continued)
- [nongnu] elpa/subed 5de6f21 377/389: Add msecs-to-timestamp as a common function, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b42f563 378/389: Add audio extensions, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 6b1a6f2 367/389: Add computing and displaying characters per second, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3ba295b 336/389: Fix "service name too long", ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 961e5eb 343/389: More subed-vtt fixes: require subed-vtt, validate better, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 87b3823 353/389: subed-split-subtitle works at the beginning or end of subtitle text, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3b4b56a 384/389: Merge pull request #49 from sachac/fix-vtt-spaces, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed bee9e63 342/389: subed-vtt: Fix syncing point with player, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 016c6a5 363/389: subed-split-subtitle: Handle more cases, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 6164f88 380/389: Keep track of video being played, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 70561f0 381/389: Make hours optional in VTT files, following the spec,
ELPA Syncer <=
- [nongnu] elpa/subed bf3e832 382/389: Check if subed--cps-overlay exists before trying to update it, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b6e08c2 383/389: Handle spaces in between VTT subtitles, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 564b6fe 386/389: Add preliminary support for comments in VTT files, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d5751c5 334/389: Change default faces to inherit color values, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 65ed21c 350/389: Add tests/test-subed-vtt.el, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 6eba992 376/389: Add ability to proportionally scale subtitles., ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 7d1aa59 385/389: Make timestamp-to-msecs a generic function, ELPA Syncer, 2021/12/03