]> Sergey Matveev's repositories - nnn.git/commitdiff
Implement mediainfo as a plugin
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 27 Aug 2019 18:30:52 +0000 (00:00 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 27 Aug 2019 18:32:33 +0000 (00:02 +0530)
README.md
misc/auto-completion/bash/nnn-completion.bash
misc/auto-completion/fish/nnn.fish
misc/auto-completion/zsh/_nnn
nnn.1
plugins/README.md
plugins/mediainf [new file with mode: 0755]
src/nnn.c
src/nnn.h

index 3e40ff9854b3f043fdddec800b18ad4f447d0e3d..f8b3b8f6849c42c57242ce304029c79f3b022725 100644 (file)
--- a/README.md
+++ b/README.md
@@ -85,7 +85,7 @@ Visit the **[Wiki](https://github.com/jarun/nnn/wiki)** for operational concepts
   - Option to open all text files in EDITOR
 - Information
   - Detailed file information
-  - Media information (needs mediainfo/exiftool)
+  - Media information (using plugin)
 - Convenience
   - Minimal configuration
   - Plugin keybinds
@@ -118,7 +118,6 @@ Visit the **[Wiki](https://github.com/jarun/nnn/wiki)** for operational concepts
 | xdg-open (Linux), open(1) (macOS), cygstart (Cygwin) | base | desktop opener |
 | file, coreutils (cp, mv, rm), findutils (xargs) | base | file type, copy, move and remove |
 | tar, (un)zip [atool/bsdtar for more formats] | base | create, list, extract tar, gzip, bzip2, zip |
-| mediainfo / exiftool | if needed | multimedia file details |
 | sshfs, fusermount(3) | if needed | mount, unmount over SSHFS |
 | trash-cli | optional | trash files (default action: delete) |
 | vlock (Linux), bashlock (macOS), lock(1) (BSD) | optional | terminal locker (fallback: [cmatrix](https://github.com/abishekvashok/cmatrix)) |
@@ -203,8 +202,8 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd
 #### Cmdline options
 
 ```
-usage: nnn [-b key] [-d] [-e] [-H] [-i] [-n] [-o]
-           [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
+usage: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]
+           [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
 
 The missing terminal file manager for X.
 
@@ -214,7 +213,6 @@ positional args:
 optional args:
  -b key  open bookmark key
  -d      detail mode
- -e      use exiftool for media info
  -H      show hidden files
  -i      nav-as-you-type mode
  -n      version sort
@@ -253,20 +251,20 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
          K ^Y  Toggle selection  y  List selection
             P  Copy selection    X  Delete selection
             V  Move selection   ^X  Delete entry
-            f  Create archive  m M  Brief/full mediainfo
+            f  Create archive    C  Execute entry
            ^F  Extract archive   F  List archive
             e  Edit in EDITOR    p  Open in PAGER
  ORDER TOGGLES
            ^J  du                S  Apparent du
             s  Size    E  Extn   t  Time modified
  MISC
-         ! ^]  Shell   L  Lock   C  Execute entry
+         ! ^]  Shell   ^N  Note  L  Lock
          R ^V  Pick plugin  F12 xK  Run plugin key K
             c  SSHFS mount       u  Unmount
-           ^P  Prompt  ^N  Note  =  Launcher
+           ^P  Prompt            =  Launcher
 ```
 
-Note: Help & settings, file details, media info and archive listing are shown in the PAGER. Use the PAGER-specific keys in these screens.
+Note: Help & settings, file details and archive listing are shown in the PAGER. Use the PAGER-specific keys in these screens.
 
 | Mouse click | Function |
 |---| --- |
index 698b588232452220e24e19fc3f2e384a5a0d6bd5..56d2bebcb60ae6ffe1bfd02b7f68ead6509e40d2 100644 (file)
@@ -13,7 +13,6 @@ _nnn () {
     opts=(
         -b
         -d
-        -e
         -H
         -i
         -n
index 4dd91d27dc83e53656c0e36ec779e7c4ccecbd12..970c24aba36054bb6d53dfef8d81f16cf1c82746 100644 (file)
@@ -7,7 +7,6 @@
 
 complete -c nnn -s b -r -d 'bookmark key to open'
 complete -c nnn -s d    -d 'start in detail mode'
-complete -c nnn -s e    -d 'use exiftool instead of mediainfo'
 complete -c nnn -s H    -d 'show hidden files'
 complete -c nnn -s i    -d 'start in navigate-as-you-type mode'
 complete -c nnn -s n    -d 'use version compare to sort files'
index 3fb17391bab689348dc8b341ec4502b709ef367e..119fc5a06b4b93fdfa5a5558e76ff5305c715bfc 100644 (file)
@@ -11,7 +11,6 @@ local -a args
 args=(
     '(-b)-b[bookmark key to open]:key char'
     '(-d)-d[start in detail mode]'
-    '(-e)-e[use exiftool instead of mediainfo]'
     '(-H)-H[show hidden files]'
     '(-i)-i[start in navigate-as-you-type mode]'
     '(-n)-n[use version compare to sort files]'
diff --git a/nnn.1 b/nnn.1
index bc5eabb5d874ca9f1ac05f918df9ea012a66f2c9..71127b6f9d9fa711e7dd734806d955cb69aa6324 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -8,7 +8,6 @@
 .Nm
 .Op Ar -b key
 .Op Ar -d
-.Op Ar -e
 .Op Ar -H
 .Op Ar -i
 .Op Ar -n
@@ -43,9 +42,6 @@ supports the following options:
 .Fl d
         detail mode
 .Pp
-.Fl e
-        use exiftool instead of mediainfo
-.Pp
 .Fl H
         show hidden files
 .Pp
index 3e66adfa713613f9e79327159a505bba24febc4b..7a10a1c156a08fe9c475c646472d1af7fce0f40e 100644 (file)
@@ -14,6 +14,7 @@ The currently available plugins are listed below.
 | imgur | bash | - | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) |
 | ipinfo | sh | curl, whois | Fetch external IP address and whois information |
 | kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device |
+| mediainf | sh | mediainfo | Show media information |
 | moclyrics | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) | Show lyrics of the track playing in moc |
 | mocplay | sh | [moc](http://moc.daper.net/) | Appends (and plays, see script) selection/dir/file in moc|
 | ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |
diff --git a/plugins/mediainf b/plugins/mediainf
new file mode 100755 (executable)
index 0000000..f76b56b
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+
+# Description: Show media information of a file in pager
+#
+# Requires: mediainfo
+#
+# Shell: POSIX compliant
+# Author: Arun Prakash Jana
+
+if ! [ -z "$1" ] && [ -f "$1" ]; then
+    mediainfo "$1" | $PAGER
+    # exiftool "$1" | $PAGER
+fi
index ce1d20ff2be354eca71379d4a55bbb892728c03f..3cf2fd466b73472717ace91c001c647ce85dcbb4 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -332,22 +332,18 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
 #endif
 
 /* Macros for utilities */
-#define MEDIAINFO 0
-#define EXIFTOOL 1
-#define OPENER 2
-#define ATOOL 3
-#define BSDTAR 4
-#define UNZIP 5
-#define TAR 6
-#define LOCKER 7
-#define CMATRIX 8
-#define NLAUNCH 9
-#define UNKNOWN 10
+#define OPENER 0
+#define ATOOL 1
+#define BSDTAR 2
+#define UNZIP 3
+#define TAR 4
+#define LOCKER 5
+#define CMATRIX 6
+#define NLAUNCH 7
+#define UNKNOWN 8
 
 /* Utilities to open files, run actions */
 static char * const utils[] = {
-       "mediainfo",
-       "exiftool",
 #ifdef __APPLE__
        "/usr/bin/open",
 #elif defined __CYGWIN__
@@ -2607,17 +2603,6 @@ static size_t get_fs_info(const char *path, bool type)
        return svb.f_bavail << ffs((int)(svb.f_frsize >> 1));
 }
 
-static bool show_mediainfo(const char *fpath, const char *arg)
-{
-       if (!getutil(utils[cfg.metaviewer]))
-               return FALSE;
-
-       exitcurses();
-       get_output(NULL, 0, utils[cfg.metaviewer], fpath, arg, TRUE);
-       refresh();
-       return TRUE;
-}
-
 /* List or extract archive */
 static void handle_archive(char *fpath, const char *dir, char op)
 {
@@ -2835,17 +2820,17 @@ static bool show_help(const char *path)
               "9K ^Y  Toggle selection  y  List selection\n"
                  "cP  Copy selection    X  Delete selection\n"
                  "cV  Move selection   ^X  Delete entry\n"
-                 "cf  Create archive  m M  Brief/full mediainfo\n"
+                 "cf  Create archive    C  Execute entry\n"
                 "b^F  Extract archive   F  List archive\n"
                  "ce  Edit in EDITOR    p  Open in PAGER\n"
                "1ORDER TOGGLES\n"
                 "b^J  du                S  Apparent du\n"
                  "cs  Size    E  Extn   t  Time modified\n"
                "1MISC\n"
-              "9! ^]  Shell   L  Lock   C  Execute entry\n"
+              "9! ^]  Shell   ^N  Note  L  Lock   \n"
               "9R ^V  Pick plugin  F12 xK  Run plugin key K\n"
                  "cc  SSHFS mount       u  Unmount\n"
-                "b^P  Prompt  ^N  Note  =  Launcher\n"};
+                "b^P  Prompt            =  Launcher\n"};
 
        fd = create_tmp_file();
        if (fd == -1)
@@ -3925,8 +3910,6 @@ nochange:
                                goto nochange;
                        }
                        break;
-               case SEL_MEDIA: // fallthrough
-               case SEL_FMEDIA: // fallthrough
                case SEL_ARCHIVELS: // fallthrough
                case SEL_EXTRACT: // fallthrough
                case SEL_RUNEDIT: // fallthrough
@@ -3944,12 +3927,6 @@ nochange:
                        r = TRUE;
 
                        switch (sel) {
-                       case SEL_MEDIA: // fallthrough
-                       case SEL_FMEDIA:
-                               tmp = (sel == SEL_FMEDIA) ? "-f" : NULL;
-                               show_mediainfo(newpath, tmp);
-                               setdirwatch();
-                               goto nochange;
                        case SEL_ARCHIVELS:
                                handle_archive(newpath, path, 'l');
                                break;
@@ -4559,15 +4536,14 @@ nochange:
 static void usage(void)
 {
        fprintf(stdout,
-               "%s: nnn [-b key] [-d] [-e] [-H] [-i] [-n] [-o]\n"
-               "           [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n"
+               "%s: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]\n"
+               "           [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n"
                "The missing terminal file manager for X.\n\n"
                "positional args:\n"
                "  PATH   start dir [default: current dir]\n\n"
                "optional args:\n"
                " -b key  open bookmark key\n"
                " -d      detail mode\n"
-               " -e      use exiftool for media info\n"
                " -H      show hidden files\n"
                " -i      nav-as-you-type mode\n"
                " -n      version sort\n"
@@ -4712,7 +4688,7 @@ int main(int argc, char *argv[])
        bool progress = FALSE;
 #endif
 
-       while ((opt = getopt(argc, argv, "HSib:denop:rstvh")) != -1) {
+       while ((opt = getopt(argc, argv, "HSib:dnop:rstvh")) != -1) {
                switch (opt) {
                case 'S':
                        cfg.blkorder = 1;
@@ -4728,9 +4704,6 @@ int main(int argc, char *argv[])
                case 'b':
                        arg = optarg;
                        break;
-               case 'e':
-                       cfg.metaviewer = EXIFTOOL;
-                       break;
                case 'H':
                        cfg.showhidden = 1;
                        break;
index 9732ad9bf6eee828ac6b79edb445e499a370bd60..8dbf734834e68507c7c2e62a8379c4b1b1db46eb 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -64,8 +64,6 @@ enum action {
        SEL_TOGGLEDOT,
        SEL_DETAIL,
        SEL_STATS,
-       SEL_MEDIA,
-       SEL_FMEDIA,
        SEL_ARCHIVE,
        SEL_ARCHIVELS,
        SEL_EXTRACT,
@@ -178,10 +176,6 @@ static struct key bindings[] = {
        { 'd',            SEL_DETAIL },
        /* File details */
        { 'D',            SEL_STATS },
-       /* Show media info short, run is hacked */
-       { 'm',            SEL_MEDIA },
-       /* Show media info full, run is hacked */
-       { 'M',            SEL_FMEDIA },
        /* Create archive */
        { 'f',            SEL_ARCHIVE },
        /* List archive */