Implement mediainfo as a plugin

This commit is contained in:
Arun Prakash Jana 2019-08-28 00:00:52 +05:30
parent f781fbe78c
commit 94c3af873c
No known key found for this signature in database
GPG key ID: A75979F35C080412
9 changed files with 36 additions and 64 deletions

View file

@ -85,7 +85,7 @@ Visit the **[Wiki](https://github.com/jarun/nnn/wiki)** for operational concepts
- Option to open all text files in EDITOR - Option to open all text files in EDITOR
- Information - Information
- Detailed file information - Detailed file information
- Media information (needs mediainfo/exiftool) - Media information (using plugin)
- Convenience - Convenience
- Minimal configuration - Minimal configuration
- Plugin keybinds - 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 | | 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 | | 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 | | 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 | | sshfs, fusermount(3) | if needed | mount, unmount over SSHFS |
| trash-cli | optional | trash files (default action: delete) | | 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)) | | 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 #### Cmdline options
``` ```
usage: nnn [-b key] [-d] [-e] [-H] [-i] [-n] [-o] usage: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]
[-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
The missing terminal file manager for X. The missing terminal file manager for X.
@ -214,7 +213,6 @@ positional args:
optional args: optional args:
-b key open bookmark key -b key open bookmark key
-d detail mode -d detail mode
-e use exiftool for media info
-H show hidden files -H show hidden files
-i nav-as-you-type mode -i nav-as-you-type mode
-n version sort -n version sort
@ -253,20 +251,20 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
K ^Y Toggle selection y List selection K ^Y Toggle selection y List selection
P Copy selection X Delete selection P Copy selection X Delete selection
V Move selection ^X Delete entry 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 ^F Extract archive F List archive
e Edit in EDITOR p Open in PAGER e Edit in EDITOR p Open in PAGER
ORDER TOGGLES ORDER TOGGLES
^J du S Apparent du ^J du S Apparent du
s Size E Extn t Time modified s Size E Extn t Time modified
MISC MISC
! ^] Shell L Lock C Execute entry ! ^] Shell ^N Note L Lock
R ^V Pick plugin F12 xK Run plugin key K R ^V Pick plugin F12 xK Run plugin key K
c SSHFS mount u Unmount 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 | | Mouse click | Function |
|---| --- | |---| --- |

View file

@ -13,7 +13,6 @@ _nnn () {
opts=( opts=(
-b -b
-d -d
-e
-H -H
-i -i
-n -n

View file

@ -7,7 +7,6 @@
complete -c nnn -s b -r -d 'bookmark key to open' 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 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 H -d 'show hidden files'
complete -c nnn -s i -d 'start in navigate-as-you-type mode' 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' complete -c nnn -s n -d 'use version compare to sort files'

View file

@ -11,7 +11,6 @@ local -a args
args=( args=(
'(-b)-b[bookmark key to open]:key char' '(-b)-b[bookmark key to open]:key char'
'(-d)-d[start in detail mode]' '(-d)-d[start in detail mode]'
'(-e)-e[use exiftool instead of mediainfo]'
'(-H)-H[show hidden files]' '(-H)-H[show hidden files]'
'(-i)-i[start in navigate-as-you-type mode]' '(-i)-i[start in navigate-as-you-type mode]'
'(-n)-n[use version compare to sort files]' '(-n)-n[use version compare to sort files]'

4
nnn.1
View file

@ -8,7 +8,6 @@
.Nm .Nm
.Op Ar -b key .Op Ar -b key
.Op Ar -d .Op Ar -d
.Op Ar -e
.Op Ar -H .Op Ar -H
.Op Ar -i .Op Ar -i
.Op Ar -n .Op Ar -n
@ -43,9 +42,6 @@ supports the following options:
.Fl d .Fl d
detail mode detail mode
.Pp .Pp
.Fl e
use exiftool instead of mediainfo
.Pp
.Fl H .Fl H
show hidden files show hidden files
.Pp .Pp

View 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)) | | 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 | | ipinfo | sh | curl, whois | Fetch external IP address and whois information |
| kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device | | 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 | | 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| | 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) | | ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |

13
plugins/mediainf Executable file
View file

@ -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

View file

@ -332,22 +332,18 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
#endif #endif
/* Macros for utilities */ /* Macros for utilities */
#define MEDIAINFO 0 #define OPENER 0
#define EXIFTOOL 1 #define ATOOL 1
#define OPENER 2 #define BSDTAR 2
#define ATOOL 3 #define UNZIP 3
#define BSDTAR 4 #define TAR 4
#define UNZIP 5 #define LOCKER 5
#define TAR 6 #define CMATRIX 6
#define LOCKER 7 #define NLAUNCH 7
#define CMATRIX 8 #define UNKNOWN 8
#define NLAUNCH 9
#define UNKNOWN 10
/* Utilities to open files, run actions */ /* Utilities to open files, run actions */
static char * const utils[] = { static char * const utils[] = {
"mediainfo",
"exiftool",
#ifdef __APPLE__ #ifdef __APPLE__
"/usr/bin/open", "/usr/bin/open",
#elif defined __CYGWIN__ #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)); 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 */ /* List or extract archive */
static void handle_archive(char *fpath, const char *dir, char op) 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" "9K ^Y Toggle selection y List selection\n"
"cP Copy selection X Delete selection\n" "cP Copy selection X Delete selection\n"
"cV Move selection ^X Delete entry\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" "b^F Extract archive F List archive\n"
"ce Edit in EDITOR p Open in PAGER\n" "ce Edit in EDITOR p Open in PAGER\n"
"1ORDER TOGGLES\n" "1ORDER TOGGLES\n"
"b^J du S Apparent du\n" "b^J du S Apparent du\n"
"cs Size E Extn t Time modified\n" "cs Size E Extn t Time modified\n"
"1MISC\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" "9R ^V Pick plugin F12 xK Run plugin key K\n"
"cc SSHFS mount u Unmount\n" "cc SSHFS mount u Unmount\n"
"b^P Prompt ^N Note = Launcher\n"}; "b^P Prompt = Launcher\n"};
fd = create_tmp_file(); fd = create_tmp_file();
if (fd == -1) if (fd == -1)
@ -3925,8 +3910,6 @@ nochange:
goto nochange; goto nochange;
} }
break; break;
case SEL_MEDIA: // fallthrough
case SEL_FMEDIA: // fallthrough
case SEL_ARCHIVELS: // fallthrough case SEL_ARCHIVELS: // fallthrough
case SEL_EXTRACT: // fallthrough case SEL_EXTRACT: // fallthrough
case SEL_RUNEDIT: // fallthrough case SEL_RUNEDIT: // fallthrough
@ -3944,12 +3927,6 @@ nochange:
r = TRUE; r = TRUE;
switch (sel) { 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: case SEL_ARCHIVELS:
handle_archive(newpath, path, 'l'); handle_archive(newpath, path, 'l');
break; break;
@ -4559,15 +4536,14 @@ nochange:
static void usage(void) static void usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"%s: nnn [-b key] [-d] [-e] [-H] [-i] [-n] [-o]\n" "%s: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]\n"
" [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n" " [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n"
"The missing terminal file manager for X.\n\n" "The missing terminal file manager for X.\n\n"
"positional args:\n" "positional args:\n"
" PATH start dir [default: current dir]\n\n" " PATH start dir [default: current dir]\n\n"
"optional args:\n" "optional args:\n"
" -b key open bookmark key\n" " -b key open bookmark key\n"
" -d detail mode\n" " -d detail mode\n"
" -e use exiftool for media info\n"
" -H show hidden files\n" " -H show hidden files\n"
" -i nav-as-you-type mode\n" " -i nav-as-you-type mode\n"
" -n version sort\n" " -n version sort\n"
@ -4712,7 +4688,7 @@ int main(int argc, char *argv[])
bool progress = FALSE; bool progress = FALSE;
#endif #endif
while ((opt = getopt(argc, argv, "HSib:denop:rstvh")) != -1) { while ((opt = getopt(argc, argv, "HSib:dnop:rstvh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
cfg.blkorder = 1; cfg.blkorder = 1;
@ -4728,9 +4704,6 @@ int main(int argc, char *argv[])
case 'b': case 'b':
arg = optarg; arg = optarg;
break; break;
case 'e':
cfg.metaviewer = EXIFTOOL;
break;
case 'H': case 'H':
cfg.showhidden = 1; cfg.showhidden = 1;
break; break;

View file

@ -64,8 +64,6 @@ enum action {
SEL_TOGGLEDOT, SEL_TOGGLEDOT,
SEL_DETAIL, SEL_DETAIL,
SEL_STATS, SEL_STATS,
SEL_MEDIA,
SEL_FMEDIA,
SEL_ARCHIVE, SEL_ARCHIVE,
SEL_ARCHIVELS, SEL_ARCHIVELS,
SEL_EXTRACT, SEL_EXTRACT,
@ -178,10 +176,6 @@ static struct key bindings[] = {
{ 'd', SEL_DETAIL }, { 'd', SEL_DETAIL },
/* File details */ /* File details */
{ 'D', SEL_STATS }, { '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 */ /* Create archive */
{ 'f', SEL_ARCHIVE }, { 'f', SEL_ARCHIVE },
/* List archive */ /* List archive */