FFMPEG Converter
Zur Navigation springen
Zur Suche springen
1 #!/bin/bash
2 # shell script to set path and run webm to mp3 converter IF no other instance of ffmpeg is running
3
4 export PATH="$PATH:/home/pi"
5 cd /home/pi/matrixOne/ui/youtube_dl/
6
7 # remove illegal chars
8 for f in *.mp3; do nf=$(echo "$f" |sed -e 's/[^A-Za-z0-9.]/./g;s/\.\.\././g;s/\.\././g'); test "$f" != "$nf" && mv "$f" "$nf" && cat "$f"|tr -cd '\11\12\15\40-\176' && echo "$nf"; done
9 sleep 1
10 # test for running ffmpeg encoder, if so do not encode
11 if pgrep -x "ffmpeg" >/dev/null
12 then
13 exit 0
14 else
15 # search for webm and convert to mp3
16 find . -type f -iname "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 256k -ar 44100 -y "${FILE%.webm}.mp3";' _ '{}' \;
17 # cleanup & remove webm
18 rm -f *.webm
19 sleep 1
20 find . -type f -iname "*.m4a" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 256k -ar 44100 -y "${FILE%.m4a}.mp3";' _ '{}' \;
21 # cleanup & remove m4a
22 rm -f *.m4a
23 sleep 1
24 # build index.html for downloading
25 find -name "*[äëöüÄÖÜß]*" -exec rename 's/ë/ee/g;s/ä/ae/g;s/ü/ue/g;s/ß/ss/g;s/Ä/Ae/g;s/Ü/Ue/g;s/Ö/Oe/g;s/ö/oe/g' {} \;
26 sleep 2
27 # old generated index.html version was using tree, now we use html4tree
28 # tree -H '.' -L 1 --noreport --charset utf-8 -P "*.mp3" > index.html
29 java -jar /home/pi/html4tree/build/libs/html4tree.jar /home/pi/matrixOne/ui/youtube_dl/
30 touch -c -d now *.mp3
31 sed -i "3i <link rel=\"stylesheet\" type=\"text/css\" href=\"..\/global.css\">" index.html
32 exit 0
33 fi