aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-21 23:56:48 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-21 23:56:48 +0530
commit07d4252b639ede2b051c3862d0368ba3fffbc847 (patch)
tree99a022cb6c1959f800031e65deb62f420a8179ae
parent4e7e8719905e4dc6b2f20315e5e969b2d891ce12 (diff)
downloadnnn-07d4252b639ede2b051c3862d0368ba3fffbc847.tar.gz
Show media information using mediainfo
-rw-r--r--README.md6
-rw-r--r--config.def.h4
-rw-r--r--nnn.14
-rw-r--r--nnn.c77
4 files changed, 76 insertions, 15 deletions
diff --git a/README.md b/README.md
index a5bc652..5addd18 100644
--- 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 |
diff --git a/config.def.h b/config.def.h
index e2812e2..689aab5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -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 adacf14..ea67625 100644
--- 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 6943109..e6c4ab4 100644
--- 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);