Browse Source

Show media information using mediainfo

master
Arun Prakash Jana 7 years ago
parent
commit
07d4252b63
No known key found for this signature in database GPG Key ID: A75979F35C080412
4 changed files with 76 additions and 15 deletions
  1. +5
    -1
      README.md
  2. +4
    -0
      config.def.h
  3. +4
    -0
      nnn.1
  4. +63
    -14
      nnn.c

+ 5
- 1
README.md View File

@@ -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 - Desktop opener integration to handle mime types
- Disk usage analyzer mode - Disk usage analyzer mode
- Basic and detail views - 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, ...) - Sort numeric names in numeric order (1, 2, ... 10, 11, ...)
- Search directory contents using regex expressions - Search directory contents using regex expressions
- Spawn a shell in the current directory - 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 | | `c` | Show change dir prompt |
| `d` | Toggle detail view | | `d` | Toggle detail view |
| `D` | Toggle current file details screen | | `D` | Toggle current file details screen |
| `m` | Show concise mediainfo in less |
| `M` | Show full mediainfo in less |
| `.` | Toggle hide .dot files | | `.` | Toggle hide .dot files |
| `s` | Toggle sort by file size | | `s` | Toggle sort by file size |
| `S` | Toggle disk usage analyzer mode | | `S` | Toggle disk usage analyzer mode |


+ 4
- 0
config.def.h View File

@@ -75,6 +75,10 @@ struct key bindings[] = {
{ 'd', SEL_DETAIL, "", "" }, { 'd', SEL_DETAIL, "", "" },
/* File details */ /* File details */
{ 'D', SEL_STATS, "", "" }, { 'D', SEL_STATS, "", "" },
/* Show mediainfo short */
{ 'm', SEL_MEDIA, "", "" },
/* Show mediainfo full */
{ 'M', SEL_FMEDIA, "", "" },
/* Open dir in desktop file manager */ /* Open dir in desktop file manager */
{ 'o', SEL_DFB, "", "" }, { 'o', SEL_DFB, "", "" },
/* Toggle sort by size */ /* Toggle sort by size */


+ 4
- 0
nnn.1 View File

@@ -55,6 +55,10 @@ Change into the given directory
Toggle detail view Toggle detail view
.It Ic D .It Ic D
Toggle current file details screen Toggle current file details screen
.It Ic m
Show concise mediainfo in less
.It Ic M
Show full mediainfo in less
.It Ic \&. .It Ic \&.
Toggle hide .dot files Toggle hide .dot files
.It Ic s .It Ic s


+ 63
- 14
nnn.c View File

@@ -90,6 +90,8 @@ enum action {
SEL_TOGGLEDOT, SEL_TOGGLEDOT,
SEL_DETAIL, SEL_DETAIL,
SEL_STATS, SEL_STATS,
SEL_MEDIA,
SEL_FMEDIA,
SEL_DFB, SEL_DFB,
SEL_FSIZE, SEL_FSIZE,
SEL_BSIZE, SEL_BSIZE,
@@ -135,6 +137,7 @@ static char *opener;
static char *fallback_opener; static char *fallback_opener;
static char *copier; static char *copier;
static char *desktop_manager; static char *desktop_manager;
static char *nnn_tmpfile = "/tmp/nnn";
static off_t blk_size; static off_t blk_size;
static size_t fs_free; static size_t fs_free;
static int open_max; static int open_max;
@@ -816,6 +819,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
char *p, *begin = buf; char *p, *begin = buf;


clear(); clear();
scrollok(stdscr, TRUE);


/* Show file name or 'symlink' -> 'target' */ /* Show file name or 'symlink' -> 'target' */
if (perms[0] == 'l') { 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); ssize_t len = readlink(fpath, symtgt, PATH_MAX);
if (len != -1) { if (len != -1) {
symtgt[len] = '\0'; symtgt[len] = '\0';
printw("\n\n File: '%s' -> '%s'", fname, symtgt);
printw("\n File: '%s' -> '%s'", fname, symtgt);
} }
} else } else
printw("\n File: '%s'", fname); printw("\n File: '%s'", fname);
@@ -910,21 +914,41 @@ show_stats(char* fpath, char* fname, struct stat *sb)
} }


/* Show exit keys */ /* Show exit keys */
printw("\n\n << (D/q)");
printw("\n << (D/q)");
while ((*buf = getch())) while ((*buf = getch()))
if (*buf == 'D' || *buf == 'q') if (*buf == 'D' || *buf == 'q')
break; break;

scrollok(stdscr, FALSE);
return; 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 static void
show_help(void) show_help(void)
{ {
char c; char c;


clear(); clear();
scrollok(stdscr, TRUE);


printw("\n\
printw("\
<< Key >> << Function >>\n\n\ << Key >> << Function >>\n\n\
[Up], k, ^P Previous entry\n\ [Up], k, ^P Previous entry\n\
[Down], j, ^N Next entry\n\ [Down], j, ^N Next entry\n\
@@ -941,6 +965,8 @@ show_help(void)
c Show change dir prompt\n\ c Show change dir prompt\n\
d Toggle detail view\n\ d Toggle detail view\n\
D Toggle current file details screen\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\ . Toggle hide .dot files\n\
s Toggle sort by file size\n\ s Toggle sort by file size\n\
S Toggle disk usage analyzer mode\n\ S Toggle disk usage analyzer mode\n\
@@ -956,10 +982,12 @@ show_help(void)
Q Quit and change directory\n"); Q Quit and change directory\n");


/* Show exit keys */ /* Show exit keys */
printw("\n\n << (?/q)");
printw("\n << (?/q)");
while ((c = getch())) while ((c = getch()))
if (c == '?' || c == 'q') if (c == '?' || c == 'q')
break; break;

scrollok(stdscr, FALSE);
return; return;
} }


@@ -1262,13 +1290,10 @@ nochange:
switch (sel) { switch (sel) {
case SEL_CDQUIT: 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: case SEL_QUIT:
@@ -1458,7 +1483,7 @@ nochange:
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath)); mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));


if (tmp[0] == '\0') if (tmp[0] == '\0')
goto begin;
break;
else else
add_history(tmp); add_history(tmp);


@@ -1466,7 +1491,7 @@ nochange:
tmp = strstrip(tmp); tmp = strstrip(tmp);
if (tmp[0] == '\0') { if (tmp[0] == '\0') {
free(input); free(input);
goto begin;
break;
} }


if (tmp[0] == '~') { if (tmp[0] == '~') {
@@ -1513,7 +1538,7 @@ nochange:


printwarn(); printwarn();
free(input); free(input);
goto begin;
break;
} }


/* Save last working directory */ /* Save last working directory */
@@ -1582,6 +1607,26 @@ nochange:


goto begin; 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: case SEL_DFB:
if (!desktop_manager) if (!desktop_manager)
goto nochange; goto nochange;
@@ -1734,6 +1779,10 @@ main(int argc, char *argv[])


open_max = max_openfds(); 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) if (getuid() == 0)
showhidden = 1; showhidden = 1;
initfilter(showhidden, &ifilter); initfilter(showhidden, &ifilter);


Loading…
Cancel
Save