From a918a598564b18518f4e918b94dfb24a520f8609 Mon Sep 17 00:00:00 2001 From: johnnybash Date: Mon, 21 Dec 2020 16:24:18 +0100 Subject: [PATCH 1/3] video thumbnails in preview-tui --- plugins/preview-tui | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/preview-tui b/plugins/preview-tui index 255c35dc..7ef9566b 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -26,6 +26,10 @@ # To use: # 1. install pistol # 2. set/export $USE_PISTOL as 1 +# - optional: ffmpegthumbnailer for video thumbnails (https://github.com/dirkvdb/ffmpegthumbnailer). +# To use: +# 1. install ffmpegthumbnailer +# 2. set/export USE_VIDEOTHUMB as 1 # # Usage: # You need to set a NNN_FIFO path and a key for the plugin with NNN_PLUG, @@ -63,6 +67,7 @@ SPLIT="$SPLIT" # you can set a permanent split here TERMINAL="$TERMINAL" # same goes for the terminal USE_SCOPE="${USE_SCOPE:-0}" USE_PISTOL="${USE_PISTOL:-0}" +USE_VIDEOTHUMB="${USE_VIDEOTHUMB:-0}" PAGER="${PAGER:-less -R}" [ "$PAGER" = "most" ] && PAGER="less -R" @@ -163,6 +168,19 @@ preview_file () { else fifo_pager print_bin_info "$1" fi + elif [ "${mimetype%%/*}" = "video" ] && [ "$USE_VIDEOTHUMB" -ne 0 ] && exists ffmpegthumbnailer; then + ffmpegthumbnailer -s 0 -i "$1" -o "/tmp/videothumb.png" + if [ "$TERMINAL" = "kitty" ]; then + # Kitty terminal users can use the native image preview method. + kitty +kitten icat --silent --transfer-mode=stream --stdin=no \ + "/tmp/videothumb.png" & + elif exists catimg; then + catimg "/tmp/videothumb.png" + elif exists viu; then + viu -t "/tmp/videothumb.png" + else + fifo_pager print_bin_info "$1" + fi elif [ "$mimetype" = "application/zip" ] ; then fifo_pager unzip -l "$1" elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ] ; then From 4d77066b621e6c0a8fb17e384eba822f5d08248d Mon Sep 17 00:00:00 2001 From: johnnybash Date: Sat, 26 Dec 2020 14:16:12 +0100 Subject: [PATCH 2/3] reuse image code, use more variables --- plugins/preview-tui | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/plugins/preview-tui b/plugins/preview-tui index 7ef9566b..6358b4fa 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -156,7 +156,12 @@ preview_file () { fifo_pager ls --color=always fi elif [ "$encoding" = "binary" ]; then - if [ "${mimetype%%/*}" = "image" ] ; then + if [ "${mimetype%%/*}" = "image" ] || [ "${mimetype%%/*}" = "video" ]; then + if [ "${mimetype%%/*}" = "video" ] && [ "$USE_VIDEOTHUMB" -ne 0 ] && exists ffmpegthumbnailer; then + videothumb="/tmp/videothumb.$$.png" + ffmpegthumbnailer -s 0 -i "$1" -o "$videothumb" + set "$videothumb" + fi if [ "$TERMINAL" = "kitty" ]; then # Kitty terminal users can use the native image preview method. kitty +kitten icat --silent --transfer-mode=stream --stdin=no \ @@ -168,19 +173,6 @@ preview_file () { else fifo_pager print_bin_info "$1" fi - elif [ "${mimetype%%/*}" = "video" ] && [ "$USE_VIDEOTHUMB" -ne 0 ] && exists ffmpegthumbnailer; then - ffmpegthumbnailer -s 0 -i "$1" -o "/tmp/videothumb.png" - if [ "$TERMINAL" = "kitty" ]; then - # Kitty terminal users can use the native image preview method. - kitty +kitten icat --silent --transfer-mode=stream --stdin=no \ - "/tmp/videothumb.png" & - elif exists catimg; then - catimg "/tmp/videothumb.png" - elif exists viu; then - viu -t "/tmp/videothumb.png" - else - fifo_pager print_bin_info "$1" - fi elif [ "$mimetype" = "application/zip" ] ; then fifo_pager unzip -l "$1" elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ] ; then @@ -222,6 +214,7 @@ if [ "$PREVIEW_MODE" ] ; then kitty @ last-used-layout --no-response >/dev/null 2>&1 fi + rm $videothumb exit 0 fi From 37de198303a613186a9ca311c59511f21c963dd7 Mon Sep 17 00:00:00 2001 From: johnnybash Date: Sun, 27 Dec 2020 19:27:11 +0100 Subject: [PATCH 3/3] use trap to delete the temp files --- plugins/preview-tui | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/preview-tui b/plugins/preview-tui index 6358b4fa..a24ac413 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -158,10 +158,11 @@ preview_file () { elif [ "$encoding" = "binary" ]; then if [ "${mimetype%%/*}" = "image" ] || [ "${mimetype%%/*}" = "video" ]; then if [ "${mimetype%%/*}" = "video" ] && [ "$USE_VIDEOTHUMB" -ne 0 ] && exists ffmpegthumbnailer; then - videothumb="/tmp/videothumb.$$.png" - ffmpegthumbnailer -s 0 -i "$1" -o "$videothumb" - set "$videothumb" - fi + videothumb="/tmp/videothumb.$$.png" + ffmpegthumbnailer -s 512 -i "$1" -o "$videothumb" >/dev/null 2>&1 + set "$videothumb" + trap 'rm "$videothumb"' EXIT + fi if [ "$TERMINAL" = "kitty" ]; then # Kitty terminal users can use the native image preview method. kitty +kitten icat --silent --transfer-mode=stream --stdin=no \ @@ -214,7 +215,6 @@ if [ "$PREVIEW_MODE" ] ; then kitty @ last-used-layout --no-response >/dev/null 2>&1 fi - rm $videothumb exit 0 fi