emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/subed 7f6f020f5f 1/3: Refer to media files instead of audi


From: ELPA Syncer
Subject: [nongnu] elpa/subed 7f6f020f5f 1/3: Refer to media files instead of audio; limit subed-align to audio
Date: Wed, 16 Nov 2022 18:59:29 -0500 (EST)

branch: elpa/subed
commit 7f6f020f5fba990afadd87e8e0f43740d95cd229
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>

    Refer to media files instead of audio; limit subed-align to audio
    
    Updating the function names and documentations to refer to media
    instead of video files can help people think of using subed for audio
    files as well. Distinguishing between video and audio extensions can
    be useful for tools like aeneas, which expect audio files.
    
    * subed/subed-align.el (subed-align): Limit autodetection to files
    matching subed-audio-extensions, since that's what aeneas expects.
    * README.org (subed): Update documentation to refer to media files.
    * subed/subed-common.el (split-subtitle): Update documentation to
    refer to media files.
    (subed-guess-media-file): Renamed from subed-guess-video-file.
    * subed/subed-config.el (subed-video-extensions): Removed audio extensions.
    (subed-audio-extensions): New variable.
    (subed-auto-find-video): Obsolete variable alias for subed-auto-play-media.
    (subed-auto-play-media): Renamed from subed-auto-find-video.
    (subed-playback-speed-while-typing, subed-mpv-playback-speed,
    subed-playback-speed-while-not-typing): Remove reference to video.
    * subed/subed-mpv.el: Remove reference to video.
    (subed-mpv-media-file): Rename from subed-mpv-video-file. Can't define
    an alias for it because it's buffer-local.
    (subed-mpv--is-video-file-p): Obsolete function alias.
    (subed-mpv--is-media-file-p): Renamed from subed-mpv--is-video-file-p.
    (subed-mpv--play): Change name of argument.
    (subed-mpv-play-video-from-url): Obsolete function alias.
    (subed-mpv-play-from-url): Renamed from subed-mpv-play-video-from-url.
    (subed-mpv-play-from-file): Renamed from subed-mpv-find-video.
    (subed-mpv-find-video): Obsolete function alias.
    * subed/subed.el (subed-mpv-frame-step-map): Update documentation to
    refer to media files.
    (subed-mode-map): Change function names.
    (subed-auto-play-media-maybe): Rename from subed-auto-find-video-maybe.
    (subed-auto-find-video-maybe): Obsolete function alias.
    (subed-mode): Call subed-auto-play-media-maybe.
    * tests/test-subed-common.el ("COMMON"): Refer to media instead of video.
---
 NEWS.org                   | 16 ++++++++++++++++
 README.org                 |  9 +++++----
 subed/subed-align.el       | 12 ++++++++++--
 subed/subed-common.el      | 35 +++++++++++++++++++----------------
 subed/subed-config.el      | 17 +++++++++++------
 subed/subed-mpv.el         | 45 +++++++++++++++++++++++++--------------------
 subed/subed.el             | 27 ++++++++++++++-------------
 tests/test-subed-common.el |  2 +-
 8 files changed, 101 insertions(+), 62 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 5464719584..5140085216 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,6 +1,22 @@
 #+OPTIONS: toc:nil
 
 * subed news
+** Version 1.0.20 - 2022-11-16 - Sacha Chua
+
+subed now talks about media files instead of video files, since audio
+files are fine too. Updating the function names and documentations to
+refer to media instead of video files can help people think of using
+subed for audio files as well. Distinguishing between video and audio
+extensions can be useful for tools like aeneas, which expect audio
+files.
+
+I defined obsolete function and variable aliases for most things, but
+subed-mpv-media-file (used to be subed-mpv-video-file) uses
+defvar-local, so it didn't work well with
+define-obsolete-variable-alias. If you have any code that uses
+subed-mpv-video-file, please rewrite it to refer to
+subed-mpv-media-file instead.
+
 ** Version 1.0.19 - 2022-11-11 - Sacha Chua
 
 New commands subed-merge-dwim, subed-merge-region,
diff --git a/README.org b/README.org
index b79ff50a10..8d89c4cdb6 100644
--- a/README.org
+++ b/README.org
@@ -6,7 +6,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
 
 * subed
 subed is an Emacs major mode for editing subtitles while playing the
-corresponding video with [[https://mpv.io/][mpv]].  At the moment, the only 
supported formats are:
+corresponding media file with [[https://mpv.io/][mpv]]. At the moment, the 
only supported
+formats are:
+
 - SubRip ( ~.srt~)
 - WebVTT ( ~.vtt~ )
 - Advanced SubStation Alpha ( ~.ass~, experimental )
@@ -78,9 +80,8 @@ 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.
 
-- Automatically open the associated media file in MPV based on the filename, 
open a media file manually with ~C-c C-v~ (~subed-mpv-find-video~), or play 
media directly from a URL with ~C-c C-u~ (~subed-mpv-play-video-from-url~) .
-  This works for audio files as well.
-- Pause and resume video playback without leaving Emacs (~M-SPC~).
+- Automatically open the associated media file in MPV based on the filename, 
open a media file manually with ~C-c C-v~ (~subed-mpv-play-from-file~), or play 
media directly from a URL with ~C-c C-u~ (~subed-mpv-play-from-url~) . You can 
customize the automatic detection of files by changing ~subed-video-extensions~ 
and ~subed-audio-extensions~.
+- Pause and resume playback without leaving Emacs (~M-SPC~).
 - Jump to the current subtitle in the MPV player with ~M-j~
   (~subed-mpv-jump-to-current-subtitle~). Toggle looping over the
   current subtitle with ~C-c C-l~
diff --git a/subed/subed-align.el b/subed/subed-align.el
index 6e3871d076..2ef76c3961 100644
--- a/subed/subed-align.el
+++ b/subed/subed-align.el
@@ -40,9 +40,17 @@
 Return a buffer with FORMAT."
   (interactive
    (list
-    (or subed-mpv-video-file (read-file-name "Audio file: "))
+    (or
+     (when (and subed-mpv-media-file
+                (member (file-name-extension subed-mpv-media-file)
+                        subed-audio-extensions))
+       subed-mpv-media-file)
+     (subed-guess-media-file subed-audio-extensions)
+     (read-file-name "Audio file: "))
     (buffer-file-name)
-    (completing-read "Format: " '("AUD" "CSV" "EAF" "JSON" "SMIL" "SRT" "SSV" 
"SUB" "TEXTGRID" "TSV" "TTML" "TXT" "VTT" "XML"))))
+    (completing-read "Format: "
+                     '("AUD" "CSV" "EAF" "JSON" "SMIL" "SRT"
+                       "SSV" "SUB" "TEXTGRID" "TSV" "TTML" "TXT" "VTT" 
"XML"))))
   (let ((new-file
          (and (buffer-file-name)
               (expand-file-name
diff --git a/subed/subed-common.el b/subed/subed-common.el
index ce0ff90663..558434108a 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -1195,7 +1195,7 @@ argument (e.g. \\[universal-argument] 
\\[subed-split-subtitle])
 prompts for the offset in milliseconds.  Calling it with two
 prefix arguments (e.g. \\[universal-argument]
 \\[universal-argument] \\[subed-split-subtitle]) uses the
-relative position of the point even if the video is playing in
+relative position of the point even if the media is playing in
 MPV.
 
 The newly inserted subtitle starts `subed-subtitle-spacing'
@@ -1588,13 +1588,14 @@ and therefore gets ARGS, which is ignored."
                              (setq subed--player-is-auto-paused nil)
                              (subed-mpv-playback-speed 
subed-playback-speed-while-not-typing))))))))
 
+(defun subed-guess-media-file (&optional extensions)
+  "Find media file with same base name as the opened file in the buffer.
 
-(defun subed-guess-video-file ()
-  "Find video file with same base name as the opened file in the buffer.
-
-The file extension of the return value of the function
-`buffer-file-name' is replaced with each item in
-`subed-video-extensions' and the first existing file is returned.
+The optional EXTENSIONS argument can be a list of extensions to
+look for. If not, check against the extensions in
+`subed-video-extensions' and `subed-audio-extensions'.  The file
+extension of the `buffer-file-name' is replaced with each item in
+the extension list and the first existing file is returned.
 
 Language codes are also handled; e.g. \"foo.en.srt\" or
 \"foo.estonian.srt\" -> \"foo.{mkv,mp4,...}\" (this actually
@@ -1603,16 +1604,18 @@ name).
 
 Return nil if function `buffer-file-name' returns nil."
   (when (buffer-file-name)
-    (catch 'found-videofile
+    (catch 'found-file
       (let* ((file-base (file-name-sans-extension (buffer-file-name)))
-                (file-stem (file-name-sans-extension file-base)))
-           (dolist (extension subed-video-extensions)
-             (let ((file-base-video (format "%s.%s" file-base extension))
-                       (file-stem-video (format "%s.%s" file-stem extension)))
-               (when (file-exists-p file-base-video)
-                 (throw 'found-videofile file-base-video))
-               (when (file-exists-p file-stem-video)
-                 (throw 'found-videofile file-stem-video))))))))
+                  (file-stem (file-name-sans-extension file-base)))
+             (dolist (extension
+                 (or extensions (append subed-video-extensions 
subed-audio-extensions)))
+               (let ((file-base-media (format "%s.%s" file-base extension))
+                           (file-stem-media (format "%s.%s" file-stem 
extension)))
+                 (when (file-exists-p file-base-media)
+                   (throw 'found-file file-base-media))
+                 (when (file-exists-p file-stem-media)
+                   (throw 'found-file file-stem-media))))))))
+(define-obsolete-function-alias 'subed-guess-video-file 
'subed-guess-media-file "1.0.20")
 
 ;;; Inserting HTML-like tags
 
diff --git a/subed/subed-config.el b/subed/subed-config.el
index 78a74fd3b2..84ee0b3141 100644
--- a/subed/subed-config.el
+++ b/subed/subed-config.el
@@ -85,16 +85,21 @@
   :type 'hook
   :group 'subed)
 
-(defcustom subed-video-extensions '("mkv" "mp4" "webm" "avi" "ts" "ogv" "wav" 
"ogg" "mp3")
+(defcustom subed-video-extensions '("mkv" "mp4" "webm" "avi" "ts" "ogv")
   "Video file name extensions."
   :type 'list
   :group 'subed)
 
-(defcustom subed-auto-find-video t
-  "Whether to open the video automatically when opening a subtitle file."
-  :type 'boolean
+(defcustom subed-audio-extensions '("wav" "ogg" "mp3" "opus")
+  "Audio file name extensions."
+  :type 'list
   :group 'subed)
 
+(define-obsolete-variable-alias 'subed-auto-find-video 'subed-auto-play-media 
"1.20")
+(defcustom subed-auto-play-media t
+  "Whether to open the video or audio automatically when opening a subtitle 
file."
+  :type 'boolean
+  :group 'subed)
 
 (defcustom subed-milliseconds-adjust 100
   "Milliseconds to add or subtract from start/stop time.
@@ -125,13 +130,13 @@ Return new `subed-milliseconds-adjust' value."
 
 
 (defcustom subed-playback-speed-while-typing 0
-  "Video playback speed while the user is editing the buffer.
+  "Playback speed while the user is editing the buffer.
 If set to zero or smaller, playback is paused."
   :type 'float
   :group 'subed)
 
 (defcustom subed-playback-speed-while-not-typing 1.0
-  "Video playback speed while the user is not editing the buffer."
+  "Playback speed while the user is not editing the buffer."
   :type 'float
   :group 'subed)
 
diff --git a/subed/subed-mpv.el b/subed/subed-mpv.el
index af2451492d..4ddc6d0968 100644
--- a/subed/subed-mpv.el
+++ b/subed/subed-mpv.el
@@ -34,7 +34,7 @@
   "Whether mpv is currently playing or paused.")
 
 (defvar-local subed-mpv-playback-speed nil
-  "How fast mpv is playing the video.
+  "How fast mpv is playing the media file.
 1.0 is normal speed, 0.5 is half speed, etc.")
 
 (defvar-local subed-mpv-playback-position nil
@@ -47,7 +47,7 @@
                                            subed-mpv-jump-to-current-subtitle)
   "Functions to call when mpv has loaded a file and starts playing.")
 
-(defvar-local subed-mpv-video-file nil "Current file or URL.")
+(defvar-local subed-mpv-media-file nil "Current file or URL.")
 
 (defvar-local subed-mpv--server-proc nil
   "Running mpv process.")
@@ -301,7 +301,7 @@ See \"List of events\" in mpv(1)."
   (if subed-mpv-is-playing (subed-mpv-pause) (subed-mpv-unpause)))
 
 (defun subed-mpv-playback-speed (factor)
-  "Play video slower (FACTOR < 1) or faster (FACTOR > 1)."
+  "Play slower (FACTOR < 1) or faster (FACTOR > 1)."
   (interactive "NFactor: ")
   (unless (eq subed-mpv-playback-speed factor)
     (when (subed-mpv--client-send `(set_property speed ,factor))
@@ -347,21 +347,24 @@ by frames until any other key is pressed."
   "Reload subtitle file from disk."
   (subed-mpv--client-send '(sub-reload)))
 
-(defun subed-mpv--is-video-file-p (filename)
-  "Return whether FILENAME is a video file or directory."
+(define-obsolete-function-alias 'subed-mpv--is-video-file-p 
'subed-mpv--is-media-file-p "1.20")
+(defun subed-mpv--is-media-file-p (filename)
+  "Return non-nil if FILENAME is a media file.
+Files should match `subed-video-extensions' or `subed-audio-extensions'."
   (and (not (or (string= filename ".") (string= filename "..")))
        (let ((filepath (expand-file-name filename)))
          (or (file-directory-p filepath)
-             (member (file-name-extension filename) subed-video-extensions)))))
+             (member (file-name-extension filename) subed-video-extensions)
+             (member (file-name-extension filename) subed-audio-extensions)))))
 
-(defun subed-mpv--play (video)
-  "Open VIDEO and play it in mpv."
+(defun subed-mpv--play (file)
+  "Open FILE and play it in mpv."
   (when (subed-mpv--server-started-p)
     (subed-mpv-kill))
   (when (apply #'subed-mpv--server-start subed-mpv-arguments)
-      (subed-debug "Opening video: %s" video)
+      (subed-debug "Opening file: %s" file)
       (subed-mpv--client-connect subed-mpv--retry-delays)
-      (subed-mpv--client-send `(loadfile ,video replace))
+      (subed-mpv--client-send `(loadfile ,file replace))
       ;; mpv won't add the subtitles if the file doesn't exist yet, so we add 
it
       ;; via after-save-hook.
       (if (file-exists-p (buffer-file-name))
@@ -370,23 +373,25 @@ by frames until any other key is pressed."
       (subed-mpv--client-send `(observe_property 1 time-pos))
       (subed-mpv-playback-speed subed-playback-speed-while-not-typing)))
 
-(defun subed-mpv-play-video-from-url (url)
-  "Open video file from URL in mpv.
+(define-obsolete-function-alias 'subed-mpv-play-video-from-url 
'subed-mpv-play-from-url "1.20")
+(defun subed-mpv-play-from-url (url)
+  "Open file from URL in mpv.
 See the mpv manual for a list of supported URL types.  If you
-have youtube-dl installed, mpv can open videos from a variety of
+have youtube-dl or yt-dlp installed, mpv can open videos from a variety of
 hosting providers."
   (interactive "MURL: ")
-  (setq subed-mpv-video-file url)
+  (setq subed-mpv-media-file url)
   (subed-mpv--play url))
 
-(defun subed-mpv-find-video (file)
-  "Open video file FILE in mpv.
+(defun subed-mpv-play-from-file (file)
+  "Open FILE in mpv.
 
-Video files are expected to have any of the extensions listed in
-`subed-video-extensions'."
-  (interactive (list (read-file-name "Find video: " nil nil t nil 
#'subed-mpv--is-video-file-p)))
-  (setq subed-mpv-video-file (expand-file-name file))
+Files are expected to have any of the extensions listed in
+`subed-video-extensions' or `subed-audio-extensions'."
+  (interactive (list (read-file-name "Find media: " nil nil t nil 
#'subed-mpv--is-media-file-p)))
+  (setq subed-mpv-media-file (expand-file-name file))
   (subed-mpv--play (expand-file-name file)))
+(define-obsolete-function-alias 'subed-mpv-find-video 
'subed-mpv-play-from-file "1.20")
 
 (defun subed-mpv--add-subtitle-after-first-save ()
   "Tell mpv to load subtitles from function `buffer-file-name'.
diff --git a/subed/subed.el b/subed/subed.el
index c27a8c2db2..0c8244965e 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.19
+;; Version: 1.0.20
 ;; Maintainer: Sacha Chua <sacha@sachachua.com>
 ;; Author: Random User
 ;; Keywords: convenience, files, hypermedia, multimedia
@@ -44,7 +44,7 @@
     (define-key map "." #'subed-mpv-frame-step)
     (define-key map "," #'subed-mpv-frame-back-step)
     map)
-  "A keymap for stepping the video by frames.")
+  "A keymap for stepping through the media file by frames.")
 
 (defconst subed-mode-map
   (let ((subed-mode-map (make-keymap)))
@@ -72,8 +72,8 @@
     (define-key subed-mode-map (kbd "M-SPC") #'subed-mpv-toggle-pause)
     (define-key subed-mode-map (kbd "M-j") 
#'subed-mpv-jump-to-current-subtitle)
     (define-key subed-mode-map (kbd "C-c C-d") #'subed-toggle-debugging)
-    (define-key subed-mode-map (kbd "C-c C-v") #'subed-mpv-find-video)
-    (define-key subed-mode-map (kbd "C-c C-u") #'subed-mpv-play-video-from-url)
+    (define-key subed-mode-map (kbd "C-c C-v") #'subed-mpv-play-from-file)
+    (define-key subed-mode-map (kbd "C-c C-u") #'subed-mpv-play-from-url)
     (define-key subed-mode-map (kbd "C-c C-f") subed-mpv-frame-step-map)
     (define-key subed-mode-map (kbd "C-c C-p") 
#'subed-toggle-pause-while-typing)
     (define-key subed-mode-map (kbd "C-c C-l") 
#'subed-toggle-loop-over-current-subtitle)
@@ -90,15 +90,16 @@
     subed-mode-map)
   "A keymap for editing subtitles.")
 
-(defun subed-auto-find-video-maybe ()
-  "Load video associated with this subtitle file."
-  (let ((video-file (subed-guess-video-file)))
-    (when video-file
-      (subed-debug "Auto-discovered video file: %s" video-file)
+(defun subed-auto-play-media-maybe ()
+  "Load media file associated with this subtitle file."
+  (let ((file (subed-guess-media-file)))
+    (when file
+      (subed-debug "Auto-discovered media file: %s" file)
       (condition-case err
-          (subed-mpv-find-video video-file)
-        (error (message "%s -- Set subed-auto-find-video to nil to avoid this 
error."
+          (subed-mpv-play-from-file file)
+        (error (message "%s -- Set subed-auto-find-media to nil to avoid this 
error."
                         (car (cdr err))))))))
+(define-obsolete-function-alias 'subed-auto-find-video-maybe 
'subed-auto-play-media-maybe "1.20")
 
 ;; TODO: Make these more configurable.
 (defun subed-set-up-defaults ()
@@ -135,8 +136,8 @@ Key bindings:
   (when subed-trim-overlap-check-on-load
     (add-hook 'subed-mode-hook #'subed-trim-overlap-check :append :local))
   (add-hook 'subed-mode-hook #'subed-set-up-defaults :append :local)
-  (when subed-auto-find-video
-    (add-hook 'subed-mode-hook #'subed-auto-find-video-maybe :append :local)))
+  (when subed-auto-play-media
+    (add-hook 'subed-mode-hook #'subed-auto-play-media-maybe :append :local)))
 
 (defun subed-guess-format ()
   "Set this buffer's format to a more specific subed mode format.
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index 68154cc77f..444f38338f 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -2326,7 +2326,7 @@ This is another.
            (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 "")))))
-    (describe "when playing the video in MPV"
+    (describe "when playing the media in MPV"
       (it "splits at point in the middle of the subtitle."
         (with-temp-srt-buffer
          (insert mock-srt-data)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]