[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed e528c001d9: Add new command subed-convert
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed e528c001d9: Add new command subed-convert |
Date: |
Sun, 23 Oct 2022 10:59:09 -0400 (EDT) |
branch: elpa/subed
commit e528c001d98fcd526fd04ff49caef5c475d74f3b
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
Add new command subed-convert
* subed/subed-common.el (subed-convert): New command.
(auto-insert): New generic function for setting up an empty file.
* subed/subed-vtt.el (subed--auto-insert): Set up WEBVTT.
* subed/subed-ass.el (subed--auto-insert): Set up ASS header.
* tests/test-subed-common.el: Add test.
---
NEWS.org | 5 +++++
README.org | 48 ++++++++++++++++++++++++----------------------
subed/subed-ass.el | 15 +++++++++++++++
subed/subed-common.el | 26 ++++++++++++++++++++++++-
subed/subed-vtt.el | 5 +++++
subed/subed.el | 2 +-
tests/test-subed-common.el | 23 ++++++++++++++++++++++
7 files changed, 99 insertions(+), 25 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 2e74852272..f092274fb3 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,4 +1,9 @@
* subed news
+
+** Version 1.0.12 - 2022-10-23 - Sacha Chua
+
+Added new command ~subed-convert~.
+
** Version 1.0.11 - 2022-10-23 - Sacha Chua
Added subed-tsv.el for Audacity label exports. Use M-x subed-tsv-mode to load
it.
diff --git a/README.org b/README.org
index 4e1c42e92f..b09d4701cf 100644
--- a/README.org
+++ b/README.org
@@ -17,28 +17,6 @@ corresponding video with [[https://mpv.io/][mpv]]. At the
moment, the only supp
[[file:https://raw.githubusercontent.com/rndusr/subed/master/screenshot.jpg]]
-Using network sockets to control MPV works on Linux and on Mac OS X,
-but not on Microsoft Windows due to the lack of Unix-style sockets. On
-Microsoft Windows, you will not be able to synchronize with MPV.
-
-** Important change in v1.0.0
-
-~subed~ now uses ~subed-srt-mode~, ~subed-vtt-mode~, and
-~subed-ass-mode~ instead of directly using ~subed-mode~. These modes
-should be automatically associated with the ~.vtt~, ~.srt~, and ~.ass~
-extensions. If the generic ~subed-mode~ is loaded instead of the
format-specific mode,
-you may get an error such as:
-
-#+begin_example
-Error in post-command-hook (subed--post-command-handler):
(cl-no-applicable-method subed--subtitle-id)
-#+end_example
-
-If you set ~auto-mode-alist~ manually in your config, please make sure
-you associate extensions the appropriate format-specific mode instead
-of ~subed-mode~. The specific backend functions (ex:
-~subed-srt--jump-to-subtitle-id~) are also deprecated in favor of
-using generic functions such as ~subed-jump-to-subtitle-id~.
-
** Features
- Quickly jump to next (~M-n~) and previous (~M-p~) subtitle text.
- Quickly jump to the beginning (~C-M-a~) and end (~C-M-e~) of the current
@@ -81,8 +59,14 @@ using generic functions such as ~subed-jump-to-subtitle-id~.
starts. Use ~M-x customize-group~ ~subed~ to configure trimming
to happen automatically when buffers are loaded or saved, which
time is adjusted, and how much time to leave between subtitles.
-
+ - Convert between formats with ~M-x subed-convert~.
+
*** mpv integration (optional)
+
+Using network sockets to control MPV works on Linux and on Mac OS X,
+but not on Microsoft Windows due to the lack of Unix-style sockets. On
+Microsoft Windows, you will not be able to synchronize with MPV.
+
- Open videos with ~C-c C-v~ or automatically when opening a subtitle file
if the
video file is named like the subtitle file but with a video extension
(e.g. ~.mkv~ or ~.avi~).
@@ -191,6 +175,24 @@ is probably because the path to the socket used to
communicate with
MPV is too long for your operating system. You can use =M-x customize=
to set =subed-mpv-socket-dir= to a shorter path.
+** Important change in v1.0.0
+
+~subed~ now uses ~subed-srt-mode~, ~subed-vtt-mode~, and
+~subed-ass-mode~ instead of directly using ~subed-mode~. These modes
+should be automatically associated with the ~.vtt~, ~.srt~, and ~.ass~
+extensions. If the generic ~subed-mode~ is loaded instead of the
format-specific mode,
+you may get an error such as:
+
+#+begin_example
+Error in post-command-hook (subed--post-command-handler):
(cl-no-applicable-method subed--subtitle-id)
+#+end_example
+
+If you set ~auto-mode-alist~ manually in your config, please make sure
+you associate extensions the appropriate format-specific mode instead
+of ~subed-mode~. The specific backend functions (ex:
+~subed-srt--jump-to-subtitle-id~) are also deprecated in favor of
+using generic functions such as ~subed-jump-to-subtitle-id~.
+
** Contributions
Contributions would be really appreciated! subed conforms to the
[[https://reuse.software/spec/][REUSE
Specification]]; this means that every file has copyright and license
diff --git a/subed/subed-ass.el b/subed/subed-ass.el
index 5eb8e24c6a..b31a2a4638 100644
--- a/subed/subed-ass.el
+++ b/subed/subed-ass.el
@@ -269,6 +269,21 @@ function for MAJOR-MODE."
(subed-set-subtitle-time-stop new-end))
(error "No subtitle to merge into")))))
+(cl-defmethod subed--auto-insert (&context (major-mode subed-ass-mode))
+ "Set up an empty SubStation Alpha file.
+Use the format-specific function for MAJOR-MODE."
+ (insert "[Script Info]
+ScriptType: v4.00+
+PlayResX: 384
+PlayResY: 288
+ScaledBorderAndShadow: yes
+
+[V4+ Styles]
+Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,
OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY,
Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR,
MarginV, Encoding
+Style:
Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
+
+[Events]
+Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect,
Text\n"))
;;;###autoload
(define-derived-mode subed-ass-mode subed-mode "Subed-ASS"
diff --git a/subed/subed-common.el b/subed/subed-common.el
index fd6e5d03b8..91553aeee6 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -1807,8 +1807,32 @@ If LIST is nil, use the subtitles in the current buffer."
#'subed-subtitle-msecs-start))
(subed-regenerate-ids)))))
-;;; Initialization
+;;; Conversion
+(subed-define-generic-function auto-insert ()
+ "Add header text for the current format."
+ (interactive)
+ nil)
+
+(defun subed-convert (format)
+ "Create a buffer with the current subtitles converted to FORMAT.
+You may need to add some extra information to the buffer."
+ (interactive (list (completing-read "To format: " '("VTT" "SRT" "ASS"
"TSV"))))
+ (let ((subtitles (subed-subtitle-list))
+ (buf (generate-new-buffer
+ (concat (file-name-base (or (buffer-file-name) (buffer-name)))
"." (downcase format)))))
+ (with-current-buffer buf
+ (pcase format
+ ("VTT" (require 'subed-vtt) (subed-vtt-mode))
+ ("SRT" (require 'subed-srt) (subed-srt-mode))
+ ("ASS" (require 'subed-ass) (subed-ass-mode))
+ ("TSV" (require 'subed-tsv) (subed-tsv-mode)))
+ (save-excursion
+ (subed-auto-insert)
+ (mapc (lambda (sub) (apply #'subed-append-subtitle nil (cdr sub)))
subtitles)
+ (subed-regenerate-ids)))
+ (switch-to-buffer buf)
+ buf))
(provide 'subed-common)
;;; subed-common.el ends here
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index 904166d794..9a9a44a46d 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -353,6 +353,11 @@ Use the format-specific function for MAJOR-MODE."
(error "Found invalid stop time: %S" (substring (or
(thing-at-point 'line :no-properties) "\n") 0 -1))))
(goto-char orig-point)))))
+(cl-defmethod subed--auto-insert (&context (major-mode subed-vtt-mode))
+ "Set up an empty WebVTT file.
+Use the format-specific function for MAJOR-MODE."
+ (insert "WEBVTT\n"))
+
;;;###autoload
(define-derived-mode subed-vtt-mode subed-mode "Subed-VTT"
"Major mode for editing WebVTT subtitle files."
diff --git a/subed/subed.el b/subed/subed.el
index d851553830..4c7b7505b0 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.11
+;; Version: 1.0.12
;; 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 df7f29adf2..266ebe692c 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -17,6 +17,7 @@ Bar.
Baz.
")
+
(defmacro with-temp-srt-buffer (&rest body)
"Call `subed-srt--init' in temporary buffer before running BODY."
(declare (indent defun))
@@ -3211,3 +3212,25 @@ This is another.
(buttercup-fail "%s is not a function"
function-name))))
'("srt" "vtt" "ass")))
function-list)))
+
+(describe "Conversion"
+ (describe "from SRT"
+ (describe "to VTT"
+ (it "creates subtitles in the expected format"
+ (with-temp-buffer
+ (insert mock-srt-data)
+ (subed-srt-mode)
+ (with-current-buffer (subed-convert "VTT")
+ (expect major-mode :to-equal 'subed-vtt-mode)
+ (expect (buffer-string) :to-equal "WEBVTT
+
+
+00:01:01.000 --> 00:01:05.123
+Foo.
+
+00:02:02.234 --> 00:02:10.345
+Bar.
+
+00:03:03.450 --> 00:03:15.500
+Baz.
+")))))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/subed e528c001d9: Add new command subed-convert,
ELPA Syncer <=