[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 2b9d3ebbac 1/3: mpv: New commands for screenshots an
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 2b9d3ebbac 1/3: mpv: New commands for screenshots and copying position |
Date: |
Thu, 19 Dec 2024 10:01:14 -0500 (EST) |
branch: elpa/subed
commit 2b9d3ebbacda57169d313626dd1debb7b7c99023
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
mpv: New commands for screenshots and copying position
* subed/subed-mpv.el (subed-mpv-screenshot): New command.
(subed-mpv-screenshot-with-subtitles): New command.
(subed-mpv-copy-position-as-timestamp): New command.
(subed-mpv-copy-position-as-seconds): New command.
(subed-mpv-copy-position-as-msecs): New command.
---
subed/subed-mpv.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
subed/subed.el | 7 ++++++
2 files changed, 71 insertions(+)
diff --git a/subed/subed-mpv.el b/subed/subed-mpv.el
index f6e3e8925b..26e2651606 100644
--- a/subed/subed-mpv.el
+++ b/subed/subed-mpv.el
@@ -421,6 +421,70 @@ by frames until any other key is pressed."
"Reload subtitle file from disk."
(subed-mpv--client-send '(sub-reload)))
+(defun subed-mpv-screenshot (&optional file flags)
+ "Take a screenshot without subtitles.
+Save to FILE if specified.
+Use \\[universal-argument] to save to a specific file.
+Returns the filename."
+ (setq flags (or flags 'video))
+ (interactive (list (if current-prefix-arg (read-file-name "Filename: "))))
+ (if file
+ (subed-mpv--client-send `(screenshot-to-file ,file ,flags))
+ (let ((old-latest
+ (car (sort (seq-remove #'file-directory-p
+ (directory-files default-directory 'full
"mpv-shot[0-9]+\\.jpg" t))
+ #'file-newer-than-file-p))))
+ (subed-mpv--client-send `(screenshot ,flags))
+ (while (string=
+ (car (sort (seq-remove #'file-directory-p
+ (directory-files default-directory 'full
"mpv-shot[0-9]+\\.jpg" t))
+ #'file-newer-than-file-p))
+ old-latest)
+ (sit-for 0.5)
+ (setq file (car (sort (seq-remove #'file-directory-p
+ (directory-files default-directory
'full "mpv-shot[0-9]+\\.jpg" t))
+ #'file-newer-than-file-p))))))
+ (kill-new file)
+ (message "Copied %s" file)
+ file)
+
+(defun subed-mpv-screenshot-with-subtitles (&optional file)
+ "Take a screenshot including subtitles.
+Save to FILE if specified.
+Use \\[universal-argument] to save to a specific file.
+Returns the filename."
+ (interactive (list (if current-prefix-arg (read-file-name "Filename: "))))
+ (subed-mpv-screenshot file 'subtitles))
+
+(defun subed-mpv-copy-position-as-timestamp ()
+ "Copy current playback position as a timestamp."
+ (interactive)
+ (if subed-mpv-playback-position
+ (progn
+ (let ((pos (subed-msecs-to-timestamp subed-mpv-playback-position)))
+ (kill-new pos)
+ (message "Copied %s" pos)))
+ (error "No playback position yet")))
+
+(defun subed-mpv-copy-position-as-seconds ()
+ "Copy current playback position as seconds.
+This might be helpful for ffmpeg."
+ (interactive)
+ (if subed-mpv-playback-position
+ (let ((pos (number-to-string (/ subed-mpv-playback-position 1000.0))))
+ (kill-new pos)
+ (message "Copied %s" pos))
+ (error "No playback position yet")))
+
+(defun subed-mpv-copy-position-as-msecs ()
+ "Copy current playback position as msecs."
+ (interactive)
+ (if subed-mpv-playback-position
+ (let ((pos (number-to-string subed-mpv-playback-position)))
+ (kill-new pos)
+ (message "Copied %s" pos))
+ (error "No playback position yet")))
+
(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.
diff --git a/subed/subed.el b/subed/subed.el
index 367db92d23..a597d28834 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -54,11 +54,13 @@
"S-<right>" #'subed-mpv-small-step
"SPC" #'subed-mpv-toggle-pause
"u" #'subed-mpv-undo-seek
+ "S-<backspace>" #'subed-mpv-undo-seek
"j" #'subed-mpv-jump-to-current-subtitle
"J" #'subed-mpv-jump-to-current-subtitle-near-end
"s" #'subed-mpv-seek
"S" #'subed-mpv-jump
"l" #'subed-toggle-loop-over-current-subtitle
+ ;; hmm, should we change these to work with the playback speed instead?
"[" #'subed-copy-player-pos-to-start-time
"]" #'subed-copy-player-pos-to-stop-time
"{" #'subed-copy-player-pos-to-start-time-and-copy-to-previous
@@ -67,6 +69,11 @@
"f" #'subed-forward-subtitle-text
"p" #'subed-backward-subtitle-text
"n" #'subed-forward-subtitle-text
+ "i" #'subed-mpv-screenshot
+ "I" #'subed-mpv-screenshot-with-subtitles ; note that this is the
opposite of MPV's s/S
+ "t" #'subed-mpv-copy-position-as-timestamp
+ "T" #'subed-mpv-copy-position-as-seconds
+ "M-t" #'subed-mpv-copy-position-as-msecs
"<up>" #'subed-backward-subtitle-text
"<down>" #'subed-forward-subtitle-text
"S-<up>" #'subed-mpv-backward-subtitle-and-jump