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
- Information
- Detailed file information
- Media information (needs mediainfo/exiftool)
- Media information (using plugin)
- Convenience
- Minimal configuration
- 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 |
| 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 |
| mediainfo / exiftool | if needed | multimedia file details |
| sshfs, fusermount(3) | if needed | mount, unmount over SSHFS |
| 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)) |
@ -203,8 +202,8 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd
#### Cmdline options
```
usage: nnn [-b key] [-d] [-e] [-H] [-i] [-n] [-o]
[-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
usage: nnn [-b key] [-d] [-H] [-i] [-n] [-o] [-p file]
[-r] [-s] [-S] [-t] [-v] [-h] [PATH]
The missing terminal file manager for X.
@ -214,7 +213,6 @@ positional args:
optional args:
-b key open bookmark key
-d detail mode
-e use exiftool for media info
-H show hidden files
-i nav-as-you-type mode
-n version sort
@ -253,20 +251,20 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
K ^Y Toggle selection y List selection
P Copy selection X Delete selection
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
e Edit in EDITOR p Open in PAGER
ORDER TOGGLES
^J du S Apparent du
s Size E Extn t Time modified
MISC
! ^] Shell L Lock C Execute entry
! ^] Shell ^N Note L Lock
R ^V Pick plugin F12 xK Run plugin key K
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 |
|---| --- |

View File

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

View File

@ -7,7 +7,6 @@
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 e -d 'use exiftool instead of mediainfo'
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 n -d 'use version compare to sort files'

View File

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

4
nnn.1
View File

@ -8,7 +8,6 @@
.Nm
.Op Ar -b key
.Op Ar -d
.Op Ar -e
.Op Ar -H
.Op Ar -i
.Op Ar -n
@ -43,9 +42,6 @@ supports the following options:
.Fl d
detail mode
.Pp
.Fl e
use exiftool instead of mediainfo
.Pp
.Fl H
show hidden files
.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)) |
| ipinfo | sh | curl, whois | Fetch external IP address and whois information |
| 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 |
| 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) |

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

View File

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