From 2b963634bc89ce5ed4e3c086b42f93b2e2f3f733 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 2 Jul 2017 23:57:41 +0530 Subject: [PATCH] Add option -e to use exiftool --- README.md | 11 ++++++----- config.def.h | 10 +++++----- nnn.1 | 11 +++++++---- nnn.c | 43 +++++++++++++++++++++++-------------------- 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index e68fa78e..513dd093 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i - Information - Basic and detail view - Detailed file information - - Media information (needs mediainfo) + - Media information (needs mediainfo or exiftool, if specified) - Ordering - Numeric order (1, 2, ... 10, 11, ...) for numeric names - Sort by modification time, size @@ -140,8 +140,9 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i PATH directory to open [default: current dir] optional arguments: - -l start in light mode (fewer details) + -e use exiftool instead of mediainfo -i start in navigate-as-you-type mode + -l start in light mode (fewer details) -n disable color for directory entries -p path to custom nlay -S start in disk usage analyzer mode @@ -174,8 +175,8 @@ Right, Enter, l, ^M | Open file or enter dir c | Show change dir prompt d | Toggle detail view D | Toggle current file details screen - m | Show concise mediainfo - M | Show full mediainfo + m | Show concise media info + M | Show full media info s | Toggle sort by file size S | Toggle disk usage analyzer mode t | Toggle sort by modified time @@ -228,7 +229,7 @@ The following abbreviations are used in the detail view: export NNN_DE_FILE_MANAGER=thunar export NNN_DE_FILE_MANAGER=nautilus -- [mediainfo](https://mediaarea.net/en/MediaInfo) is required to view media information +- [mediainfo](https://mediaarea.net/en/MediaInfo) (or exiftool, if specified) is required to view media information #### Help diff --git a/config.def.h b/config.def.h index af53cc94..7bf1465a 100644 --- a/config.def.h +++ b/config.def.h @@ -120,16 +120,16 @@ static struct key bindings[] = { { 'd', SEL_DETAIL, "", "" }, /* File details */ { 'D', SEL_STATS, "", "" }, - /* Show mediainfo short */ - { 'm', SEL_MEDIA, "", "" }, - /* Show mediainfo full */ - { 'M', SEL_FMEDIA, "", "" }, + /* Show media info short, run is hacked */ + { 'm', SEL_MEDIA, NULL, "" }, + /* Show media info full, run is hacked */ + { 'M', SEL_FMEDIA, "-f", "" }, /* Open dir in desktop file manager */ { 'o', SEL_DFB, "", "" }, /* Toggle sort by size */ { 's', SEL_FSIZE, "", "" }, /* Sort by total block count including dir contents */ - { 'S', SEL_BSIZE, "", "" }, + { 'S', SEL_BSIZE, "", "" }, /* Toggle sort by time */ { 't', SEL_MTIME, "", "" }, { CONTROL('L'), SEL_REDRAW, "", "" }, diff --git a/nnn.1 b/nnn.1 index 5b2d7e23..d16e3f0c 100644 --- a/nnn.1 +++ b/nnn.1 @@ -66,9 +66,9 @@ Toggle detail view .It Ic D Toggle current file details screen .It Ic m -Show concise mediainfo +Show concise media info .It Ic M -Show full mediainfo +Show full media info .It Ic s Toggle sort by file size .It Ic S @@ -101,12 +101,15 @@ directory you came out of. .Nm supports the following options: .Pp -.Fl l - start in light mode (fewer details) +.Fl e + use exiftool instead of mediainfo .Pp .Fl i start in navigate-as-you-type mode .Pp +.Fl l + start in light mode (fewer details) +.Pp .Fl n disable color for directory entries .Pp diff --git a/nnn.c b/nnn.c index b6df7744..7bd90a1f 100644 --- a/nnn.c +++ b/nnn.c @@ -180,15 +180,19 @@ static const double div_2_pow_10 = 1.0 / 1024.0; static uint _WSHIFT; /* Utilities to open files, run actions */ -static char *utils[] = { +static char * const utils[] = { #ifdef __APPLE__ "/usr/bin/open", #else "/usr/bin/xdg-open", #endif - "nlay" + "nlay", + "mediainfo", + "exiftool" }; +static char *metaviewer; + /* For use in functions which are isolated and don't return the buffer */ static char g_buf[MAX_CMD_LEN]; @@ -1440,11 +1444,11 @@ show_stats(char *fpath, char *fname, struct stat *sb) static int show_mediainfo(char *fpath, char *arg) { - if (!get_output(g_buf, MAX_CMD_LEN, "which", "mediainfo", NULL, 0)) + if (!get_output(g_buf, MAX_CMD_LEN, "which", metaviewer, NULL, 0)) return -1; exitcurses(); - get_output(NULL, 0, "mediainfo", fpath, arg, 1); + get_output(NULL, 0, metaviewer, fpath, arg, 1); initcurses(); return 0; } @@ -1475,8 +1479,8 @@ show_help(void) c | Show change dir prompt\n\ d | Toggle detail view\n\ D | Toggle current file details screen\n\ - m | Show concise mediainfo\n\ - M | Show full mediainfo\n\ + m | Show concise media info\n\ + M | Show full media info\n\ s | Toggle sort by file size\n\ S | Toggle disk usage analyzer mode\n\ t | Toggle sort by modified time\n\ @@ -2360,23 +2364,14 @@ nochange: break; } case SEL_MEDIA: - if (ndents > 0) { - mkpath(path, dents[cur].name, oldpath, - PATH_MAX); - - if (show_mediainfo(oldpath, NULL) == -1) { - printmsg("mediainfo missing"); - goto nochange; - } - } - break; case SEL_FMEDIA: if (ndents > 0) { mkpath(path, dents[cur].name, oldpath, PATH_MAX); - if (show_mediainfo(oldpath, "-f") == -1) { - printmsg("mediainfo missing"); + if (show_mediainfo(oldpath, run) == -1) { + sprintf(g_buf, "%s missing", metaviewer); + printmsg(g_buf); goto nochange; } } @@ -2470,8 +2465,9 @@ The missing terminal file browser for X.\n\n\ positional arguments:\n\ PATH directory to open [default: current dir]\n\n\ optional arguments:\n\ - -l start in light mode (fewer details)\n\ + -e use exiftool instead of mediainfo\n\ -i start in navigate-as-you-type mode\n\ + -l start in light mode (fewer details)\n\ -n disable color for directory entries\n\ -p path to custom nlay\n\ -S start in disk usage analyzer mode\n\ @@ -2497,7 +2493,7 @@ main(int argc, char *argv[]) exit(1); } - while ((opt = getopt(argc, argv, "lSinp:vh")) != -1) { + while ((opt = getopt(argc, argv, "lSinep:vh")) != -1) { switch (opt) { case 'S': cfg.blkorder = 1; @@ -2512,6 +2508,9 @@ main(int argc, char *argv[]) case 'n': cfg.showcolor = 0; break; + case 'e': + metaviewer = utils[3]; + break; case 'p': player = optarg; break; @@ -2560,6 +2559,10 @@ main(int argc, char *argv[]) if (getenv("NNN_USE_EDITOR")) editor = xgetenv("EDITOR", "vi"); + /* Set metadata viewer if not set */ + if (!metaviewer) + metaviewer = utils[2]; + /* Set player if not set already */ if (!player) player = utils[1];