FFMPEG Converter

Aus AirSpaceWatch & More
Zur Navigation springen Zur Suche springen

<syntaxhighlight lang="bash" line='line'>

  1. !/bin/bash
  2. shell script to set path and run webm to mp3 converter IF no other instance of ffmpeg is running

export PATH="$PATH:/home/pi" cd /home/pi/matrixOne/ui/youtube_dl/

  1. remove illegal chars

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 sleep 1

  1. test for running ffmpeg encoder, if so do not encode

if pgrep -x "ffmpeg" >/dev/null then

   exit 0

else

   # search for webm and convert to mp3
   find . -type f -iname "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 256k -ar 44100 -y "${FILE%.webm}.mp3";' _ '{}' \;
   # cleanup & remove webm
   rm -f *.webm
   sleep 1
   find . -type f -iname "*.m4a" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 256k -ar 44100 -y "${FILE%.m4a}.mp3";' _ '{}' \;
   # cleanup & remove m4a
   rm -f *.m4a
   sleep 1
   # build index.html for downloading
   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' {} \;
   sleep 2
   # old generated index.html version was using tree, now we use html4tree
   # tree -H '.' -L 1 --noreport --charset utf-8 -P "*.mp3" > index.html
   java -jar /home/pi/html4tree/build/libs/html4tree.jar /home/pi/matrixOne/ui/youtube_dl/
   touch -c -d now *.mp3
   sed -i "3i <link rel=\"stylesheet\" type=\"text/css\" href=\"..\/global.css\">" index.html
   exit 0

fi </sytaxhighlight>