]> Sergey Matveev's repositories - nnn.git/commitdiff
Plugin mp3conv to extract audio from media as mp3
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 23 Feb 2020 07:31:15 +0000 (13:01 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 23 Feb 2020 07:39:24 +0000 (13:09 +0530)
plugins/README.md
plugins/mp3conv [new file with mode: 0755]

index f1401e28f8e84c29d6bec6010a32fb2167495941..1b327ffcce9ec48dd927793da908475aedd387dc 100644 (file)
@@ -48,6 +48,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
 | mediainf | Show media information | sh | mediainfo |
 | moclyrics | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) |
 | mocplay | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) |
+| mp3conv | Extract audio from multimedia as mp3 | sh | ffmpeg |
 | nmount | Toggle mount status of a device as normal user | sh | pmount, udisks2 |
 | nuke | Sample file opener (CLI-only by default) | sh | various |
 | oldbigfile | List large files by access time | sh | find, sort |
diff --git a/plugins/mp3conv b/plugins/mp3conv
new file mode 100755 (executable)
index 0000000..b60b891
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env sh
+
+# Description: Extract audio from multimedia files and convert to mp3
+#
+# Dependency: ffmpeg compiled with libmp3lame audio codec support
+#
+# Shell: POSIX compliant
+# Author: Arun Prakash Jana
+
+outdir=_mp3files
+
+if ! [ -e "${outdir}" ]; then
+    mkdir "${outdir}"
+fi
+
+handle_multimedia() {
+    mime="${1}"
+    file="${2}"
+
+    case "${mime}" in
+        audio/* | video/*)
+            ffmpeg -i "${file}" -vn -codec:a libmp3lame -q:a 2 "${outdir}"/"${file%.*}.mp3"
+            ;;
+        *)
+            ;;
+    esac
+}
+
+for f in *; do
+    if [ -f "${f}" ]; then
+        mimestr="$( file --dereference --brief --mime-type -- "${f}" )"
+        handle_multimedia "${mimestr}" "${f}"
+    fi
+done