branch: elpa/dirvish
commit a22021d05e7457232bd560161761cf61b6f4cfe0
Author: Alex Lu <hellosimon1...@hotmail.com>
Commit: Alex Lu <hellosimon1...@hotmail.com>

    fix(widgets): image/video preview on MS-Windows (closes #214)
    
    Thanks to @samb233!
    
    Ref: https://emacs-china.org/t/dirvish-dired/20189/256
---
 README.org           |  6 ++++--
 dirvish-widgets.el   | 23 +++++++++++++++++++----
 dirvish.el           |  6 ++++--
 docs/CUSTOMIZING.org | 10 ++++++----
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/README.org b/README.org
index 4611c1f181..6a98c8e4a0 100644
--- a/README.org
+++ b/README.org
@@ -37,7 +37,7 @@ This package requires =GNU ls= (~gls~ on macOS), and 
/optionally/:
 + =fd= as a faster alternative to =find=
 + =imagemagick= for image preview
 + =poppler= | =pdf-tools= for pdf preview
-+ =ffmpegthumbnailer= for video preview
++ =ffmpegthumbnailer= (Linux/macOS) | =mtn= (Windows) for video preview
 + =mediainfo= for audio/video metadata generation
 + =tar= and =unzip= for archive files preview
 
@@ -64,12 +64,14 @@ This package requires =GNU ls= (~gls~ on macOS), and 
/optionally/:
   pkg install gnuls fd-find poppler ffmpegthumbnailer ImageMagick7 gtar
 #+end_src
 
-@@html:<h2>@@Windows (untested)@@html:</h2>@@
+@@html:<h2>@@Windows@@html:</h2>@@
 #+begin_src bash
   # install via Scoop: https://scoop.sh/
   scoop install coreutils fd poppler imagemagick unzip
 #+end_src
 
+You might also want to install 
[[https://gitlab.com/movie_thumbnailer/mtn][mtn]] for video preview.
+
 @@html:</details>@@
 
 * Installation
diff --git a/dirvish-widgets.el b/dirvish-widgets.el
index e3164a0827..bf73a6c08e 100644
--- a/dirvish-widgets.el
+++ b/dirvish-widgets.el
@@ -61,7 +61,7 @@ variable is nil, the auto caching is disabled."
                  (run-with-timer 0 0.25 #'dirvish-media--autocache)))))
 
 (defcustom dirvish-show-media-properties
-  (and (executable-find "mediainfo") (executable-find "pdfinfo") t)
+  (and (executable-find "mediainfo") t)
   "Show media properties automatically in preview window."
   :group 'dirvish :type 'boolean)
 
@@ -562,8 +562,8 @@ Require: `mediainfo' (executable)"
 
 (dirvish-define-preview image (file ext preview-window)
   "Preview image files.
-Require: `convert' (executable from `imagemagick' suite)"
-  :require ("convert")
+Require: `magick' (executable from `imagemagick' suite)"
+  :require ("magick")
   (when (member ext dirvish-image-exts)
     (let* ((w (dirvish-media--img-size preview-window))
            (h (dirvish-media--img-size preview-window 'height))
@@ -573,7 +573,7 @@ Require: `convert' (executable from `imagemagick' suite)"
             ((and (< (file-attribute-size (file-attributes file)) 250000)
                   (member ext '("jpg" "jpeg" "png" "ico" "icns" "bmp" "svg")))
              `(img . ,(create-image file nil nil :max-width w :max-height h)))
-            (t `(cache . ("convert" ,file "-define" "jpeg:extent=300kb" 
"-resize"
+            (t `(cache . ("magick" ,file "-define" "jpeg:extent=300kb" 
"-resize"
                           ,(number-to-string w) ,cache)))))))
 
 (dirvish-define-preview gif (file ext)
@@ -600,6 +600,21 @@ Require: `ffmpegthumbnailer' (executable)"
                          ,(number-to-string width)
                          ,(if dirvish-media--embedded-video-thumb "-m" 
"")))))))
 
+(dirvish-define-preview video-mtn (file ext preview-window)
+  "Preview video files on MS-Windows.
+Require: `mtn' (executable)"
+  :require ("mtn")
+  (when (member ext dirvish-video-exts)
+    (let* ((width (dirvish-media--img-size preview-window))
+           (height (dirvish-media--img-size preview-window 'height))
+           (cache (dirvish-media--cache-path file (format "images/%s" width) 
".jpg"))
+           (path (dirvish--get-parent-path cache)))
+      (if (file-exists-p cache)
+          `(img . ,(create-image cache nil nil :max-width width :max-height 
height))
+        `(cache . ("mtn" "-P" "-i" "-c" "1" "-r" "1" "-O" ,path ,file "-o"
+                   ,(format ".%s.jpg" ext) "-w"
+                   ,(number-to-string width)))))))
+
 (dirvish-define-preview epub (file preview-window)
   "Preview epub files.
 Require: `epub-thumbnailer' (executable)"
diff --git a/dirvish.el b/dirvish.el
index d9a276b515..5d54b2355e 100644
--- a/dirvish.el
+++ b/dirvish.el
@@ -49,7 +49,8 @@ Dirvish ships with these attributes:
   :group 'dirvish :type '(repeat (symbol :tag "Dirvish attribute")))
 
 (defcustom dirvish-preview-dispatchers
-  '(image gif video audio epub archive pdf dired)
+  `(,(if (memq system-type '(ms-dos windows-nt)) 'video-mtn 'video)
+    image gif audio epub archive pdf dired)
   "List of preview dispatchers.
 Each dispatcher in this list handles the validation and preview
 content generation for the corresponding filetype.
@@ -58,7 +59,8 @@ The default value contains:
 
 - image: preview image files, requires `imagemagick'.
 - gif: preview GIF image files with animation.
-- video: preview videos files with thumbnail, requires `ffmpegthumbnailer'.
+- video: preview videos files with thumbnail.
+    requires `ffmpegthumbnailer' on Linux/macOS | `mtn' on Windows
 - audio: preview audio files with metadata, requires `mediainfo'.
 - epub: preview epub documents, requires `epub-thumbnailer'.
 - pdf: preview pdf documents via `pdf-tools'.
diff --git a/docs/CUSTOMIZING.org b/docs/CUSTOMIZING.org
index 16dec3aa07..8bd630a7de 100644
--- a/docs/CUSTOMIZING.org
+++ b/docs/CUSTOMIZING.org
@@ -188,7 +188,9 @@ dispatchers, has the default value looks like:
 
 + ~image~: preview image files, requires =imagemagick=
 + ~gif~: preview GIF image files with animation
-+ ~video~: preview videos files with thumbnail, requires =ffmpegthumbnailer=
++ ~video~: preview videos files with thumbnail,
+    requires =ffmpegthumbnailer= on Linux/macOS
+    requires =mtn= on Windows (special thanks to @samb233!)
 + ~audio~: preview audio files with metadata, requires =mediainfo=
 + ~epub~: preview epub documents, requires 
[[https://github.com/alexluigit/dirvish/issues/85][epub-thumbnail]]
 + ~pdf~: preview pdf documents via =pdf-tools=
@@ -295,7 +297,7 @@ you don't have to require them explicitly if you installed 
dirvish from MELPA or
     (setq dirvish-mode-line-format
           '(:left (sort symlink) :right (omit yank index)))
     (setq dirvish-attributes
-          '(all-the-icons file-time file-size collapse subtree-state vc-state 
git-msg))
+          '(nerd-icons file-time file-size collapse subtree-state vc-state 
git-msg))
     (setq delete-by-moving-to-trash t)
     (setq dired-listing-switches
           "-l --almost-all --human-readable --group-directories-first 
--no-group")
@@ -387,8 +389,8 @@ These packages are only listed here for discoverability.
     :config
     (set-face-attribute 'diredfl-dir-name nil :bold t))
 
-  ;; Use `all-the-icons' as Dirvish's icon backend
-  (use-package all-the-icons)
+  ;; Use `nerd-icons' as Dirvish's icon backend
+  (use-package nerd-icons)
 
   ;; Or, use `vscode-icon' instead
   ;; (use-package vscode-icon

Reply via email to