]> Sergey Matveev's repositories - nnn.git/commitdiff
Show media information using mediainfo
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 21 Apr 2017 18:26:48 +0000 (23:56 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 21 Apr 2017 18:26:48 +0000 (23:56 +0530)
README.md
config.def.h
nnn.1
nnn.c

index a5bc652271525b82ac62a617c1e3a2ed38ae6fac..5addd18d443577a4e8ef52f3276adf9027b1ebf8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -56,7 +56,9 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
 - Desktop opener integration to handle mime types
 - Disk usage analyzer mode
 - Basic and detail views
-- Sort by modificaton time, size
+- Show stat and file information
+- Show media information (needs mediainfo)
+- Sort by modification time, size
 - Sort numeric names in numeric order (1, 2, ... 10, 11, ...)
 - Search directory contents using regex expressions
 - Spawn a shell in the current directory
@@ -138,6 +140,8 @@ nnn needs libreadline and libncursesw (on Linux or ncurses on OS X) and standard
 | `c` | Show change dir prompt |
 | `d` | Toggle detail view |
 | `D` | Toggle current file details screen |
+| `m` | Show concise mediainfo in less |
+| `M` | Show full mediainfo in less |
 | `.` | Toggle hide .dot files |
 | `s` | Toggle sort by file size |
 | `S` | Toggle disk usage analyzer mode |
index e2812e235a52a56b61bf234a5280fcf0dd44da00..689aab5b7dfdfa749a66797d3a8bd1e6e7f3f667 100644 (file)
@@ -75,6 +75,10 @@ struct key bindings[] = {
        { 'd',            SEL_DETAIL,    "",     "" },
        /* File details */
        { 'D',            SEL_STATS,     "",     "" },
+       /* Show mediainfo short */
+       { 'm',            SEL_MEDIA,     "",     "" },
+       /* Show mediainfo full */
+       { 'M',            SEL_FMEDIA,    "",     "" },
        /* Open dir in desktop file manager */
        { 'o',            SEL_DFB,       "",     "" },
        /* Toggle sort by size */
diff --git a/nnn.1 b/nnn.1
index adacf14761f2abddea00506b6d9c0aa8f22c2a91..ea676254029d457a50fb88f2d97be172785e09b4 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -55,6 +55,10 @@ Change into the given directory
 Toggle detail view
 .It Ic D
 Toggle current file details screen
+.It Ic m
+Show concise mediainfo in less
+.It Ic M
+Show full mediainfo in less
 .It Ic \&.
 Toggle hide .dot files
 .It Ic s
diff --git a/nnn.c b/nnn.c
index 6943109473bd2029d767288b3b51d6a49c288ddc..e6c4ab47b8914d0ac38ec6d7d51b6109d33bb452 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -90,6 +90,8 @@ enum action {
        SEL_TOGGLEDOT,
        SEL_DETAIL,
        SEL_STATS,
+       SEL_MEDIA,
+       SEL_FMEDIA,
        SEL_DFB,
        SEL_FSIZE,
        SEL_BSIZE,
@@ -135,6 +137,7 @@ static char *opener;
 static char *fallback_opener;
 static char *copier;
 static char *desktop_manager;
+static char *nnn_tmpfile = "/tmp/nnn";
 static off_t blk_size;
 static size_t fs_free;
 static int open_max;
@@ -816,6 +819,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
        char *p, *begin = buf;
 
        clear();
+       scrollok(stdscr, TRUE);
 
        /* Show file name or 'symlink' -> 'target' */
        if (perms[0] == 'l') {
@@ -823,7 +827,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
                ssize_t len = readlink(fpath, symtgt, PATH_MAX);
                if (len != -1) {
                        symtgt[len] = '\0';
-                       printw("\n\n    File: '%s' -> '%s'", fname, symtgt);
+                       printw("\n    File: '%s' -> '%s'", fname, symtgt);
                }
        } else
                printw("\n    File: '%s'", fname);
@@ -910,21 +914,41 @@ show_stats(char* fpath, char* fname, struct stat *sb)
        }
 
        /* Show exit keys */
-       printw("\n\n  << (D/q)");
+       printw("\n  << (D/q)");
        while ((*buf = getch()))
                if (*buf == 'D' || *buf == 'q')
                        break;
+
+       scrollok(stdscr, FALSE);
        return;
 }
 
+static int
+show_mediainfo(const char* fpath, int full)
+{
+       static char buf[MAX_CMD_LEN];
+
+       snprintf(buf, MAX_CMD_LEN, "which mediainfo");
+       if (get_output(buf, MAX_CMD_LEN) == NULL)
+               return -1;
+
+       if (full)
+               sprintf(buf, "mediainfo -f \"%s\" 2>&1 | less", fpath);
+       else
+               sprintf(buf, "mediainfo \"%s\" 2>&1 | less", fpath);
+
+       return system(buf);
+}
+
 static void
 show_help(void)
 {
        char c;
 
        clear();
+       scrollok(stdscr, TRUE);
 
-       printw("\n\
+       printw("\
     << Key >>                   << Function >>\n\n\
     [Up], k, ^P                 Previous entry\n\
     [Down], j, ^N               Next entry\n\
@@ -941,6 +965,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 in less\n\
+    M                           Show full mediainfo in less\n\
     .                           Toggle hide .dot files\n\
     s                           Toggle sort by file size\n\
     S                           Toggle disk usage analyzer mode\n\
@@ -956,10 +982,12 @@ show_help(void)
     Q                           Quit and change directory\n");
 
        /* Show exit keys */
-       printw("\n\n    << (?/q)");
+       printw("\n    << (?/q)");
        while ((c = getch()))
                if (c == '?' || c == 'q')
                        break;
+
+       scrollok(stdscr, FALSE);
        return;
 }
 
@@ -1262,13 +1290,10 @@ nochange:
                switch (sel) {
                case SEL_CDQUIT:
                {
-                       char *tmpfile = getenv("NNN_TMPFILE");
-                       if (tmpfile) {
-                               FILE *fp = fopen(tmpfile, "w");
-                               if (fp) {
-                                       fprintf(fp, "cd \"%s\"", path);
-                                       fclose(fp);
-                               }
+                       FILE *fp = fopen(nnn_tmpfile, "w");
+                       if (fp) {
+                               fprintf(fp, "cd \"%s\"", path);
+                               fclose(fp);
                        }
                }
                case SEL_QUIT:
@@ -1458,7 +1483,7 @@ nochange:
                                mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
 
                        if (tmp[0] == '\0')
-                               goto begin;
+                               break;
                        else
                                add_history(tmp);
 
@@ -1466,7 +1491,7 @@ nochange:
                        tmp = strstrip(tmp);
                        if (tmp[0] == '\0') {
                                free(input);
-                               goto begin;
+                               break;
                        }
 
                        if (tmp[0] == '~') {
@@ -1513,7 +1538,7 @@ nochange:
 
                                printwarn();
                                free(input);
-                               goto begin;
+                               break;
                        }
 
                        /* Save last working directory */
@@ -1582,6 +1607,26 @@ nochange:
 
                        goto begin;
                }
+               case SEL_MEDIA:
+                       if (ndents > 0)
+                               mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
+
+                       exitcurses();
+                       r = show_mediainfo(oldpath, FALSE);
+                       initcurses();
+                       if (r < 0)
+                               printmsg("mediainfo missing");
+                       goto nochange;
+               case SEL_FMEDIA:
+                       if (ndents > 0)
+                               mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
+
+                       exitcurses();
+                       r = show_mediainfo(oldpath, TRUE);
+                       initcurses();
+                       if (r < 0)
+                               printmsg("mediainfo missing");
+                       goto nochange;
                case SEL_DFB:
                        if (!desktop_manager)
                                goto nochange;
@@ -1734,6 +1779,10 @@ main(int argc, char *argv[])
 
        open_max = max_openfds();
 
+       /* Get temporary file name (ifilter used as temporary variable) */
+       if ((ifilter = getenv("NNN_TMPFILE")) != NULL)
+               nnn_tmpfile = ifilter;
+
        if (getuid() == 0)
                showhidden = 1;
        initfilter(showhidden, &ifilter);