fix(dired): fix video-mtn preview filename mismatch in dirvish
mtn generates thumbnails with different filename than what dirvish expects. This wrapper renames mtn output to match dirvish's expected MD5-based filename.
This commit is contained in:
@@ -51,6 +51,51 @@
|
|||||||
(define-key dired-mode-map (kbd "M-,") 'scroll-other-window-down)
|
(define-key dired-mode-map (kbd "M-,") 'scroll-other-window-down)
|
||||||
(define-key dired-mode-map (kbd "M-.") 'scroll-other-window))
|
(define-key dired-mode-map (kbd "M-.") 'scroll-other-window))
|
||||||
|
|
||||||
|
(with-eval-after-load 'dirvish
|
||||||
|
(global-set-key (kbd "C-c d a") 'dirvish-quick-access)
|
||||||
|
(global-set-key (kbd "C-c d s") 'dirvish-side)
|
||||||
|
(global-set-key (kbd "C-c d h") 'dirvish-history-menu)
|
||||||
|
(global-set-key (kbd "C-x d") 'dired-jump)
|
||||||
|
(global-set-key (kbd "C-x C-j") 'dired)
|
||||||
|
(define-key dired-mode-map (kbd "h") 'dirvish-history-menu)
|
||||||
|
(define-key dired-mode-map (kbd "M-,") 'scroll-other-window-down)
|
||||||
|
(define-key dired-mode-map (kbd "M-.") 'scroll-other-window))
|
||||||
|
|
||||||
|
;; Fix video-mtn preview issue on Windows
|
||||||
|
;; The problem: mtn generates thumbnails with filename like "video.mp4.jpg",
|
||||||
|
;; but dirvish expects MD5-based filename like "a1b2c3d4.jpg"
|
||||||
|
(with-eval-after-load 'dirvish
|
||||||
|
;; Function to find mtn output file for a given video file in cache directory
|
||||||
|
(defun my/dirvish-find-mtn-output (video-file cache-dir ext)
|
||||||
|
"Find mtn-generated thumbnail for VIDEO-FILE in CACHE-DIR with extension EXT."
|
||||||
|
(let* ((file-base (file-name-base video-file))
|
||||||
|
;; mtn generates: [filename].[ext].jpg
|
||||||
|
(mtn-pattern (format "%s.%s.jpg" (regexp-quote file-base) ext))
|
||||||
|
(files (directory-files cache-dir t mtn-pattern)))
|
||||||
|
(car files)))
|
||||||
|
|
||||||
|
;; Advice to fix the sentinel after mtn generates the thumbnail
|
||||||
|
(defun my/dirvish-media--cache-sentinel-advice (orig-fun proc exit-code)
|
||||||
|
"Advice to rename mtn output to MD5 format after generation."
|
||||||
|
(let* ((video-path (process-get proc 'path))
|
||||||
|
(ext (downcase (or (file-name-extension video-path) "")))
|
||||||
|
(dv (dirvish-curr)))
|
||||||
|
(when (and (memq system-type '(ms-dos windows-nt))
|
||||||
|
(member ext dirvish-video-exts)
|
||||||
|
dv)
|
||||||
|
;; Try to find and rename mtn output to MD5 format
|
||||||
|
(let* ((width (dirvish-media--img-size (dv-preview-window dv)))
|
||||||
|
(cache (dirvish--img-thumb-name video-path width ".jpg"))
|
||||||
|
(cache-dir (dirvish--get-parent-path cache))
|
||||||
|
(mtn-file (my/dirvish-find-mtn-output video-path cache-dir ext)))
|
||||||
|
(when (and mtn-file (file-exists-p mtn-file) (not (file-exists-p cache)))
|
||||||
|
(rename-file mtn-file cache)))))
|
||||||
|
;; Call original function
|
||||||
|
(funcall orig-fun proc exit-code))
|
||||||
|
|
||||||
|
;; Apply advice
|
||||||
|
(advice-add 'dirvish-media--cache-sentinel :around #'my/dirvish-media--cache-sentinel-advice))
|
||||||
|
|
||||||
(provide 'init-dired)
|
(provide 'init-dired)
|
||||||
|
|
||||||
;;; init-dired.el ends here
|
;;; init-dired.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user