aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mp3conv
blob: b60b8916e10ccc340cf21c3670adae410e2f32bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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