iwatch and inotify-triggered conversions…

$SO wanted to take $music_site videos and strip/reencode the audio track to mp3.  they already have an SSHFS mount to my file server, so i set up a directory structure where they can deposit mp4 and flv files, and the files will automatically be converted and saved to an output directory.  after conversion, the source files are moved to a processed directory.

launch.sh

#!/bin/sh

iwatch -d -f ./encode.xml

encode.xml

<?xml version="1.0" ?>
<!DOCTYPE config SYSTEM "/etc/iwatch/iwatch.dtd" >
   
<config>
  <guard email="root@localhost" name="IWatch"/>
  <watchlist>
    <title>test script</title>
    <contactpoint email="root@localhost" name="root"/>
    <path type="single" alert="off" exec="find %f \( -iname '*.mp4' -o -iname '*.flv' \) -execdir /data/convert/encode.sh {} \;" events="close_write">/data/convert/input</path>
  </watchlist>
</config>

 

encode.sh

#!/bin/bash
echo "[$(date +%H:%M:%S)] encode attempt of $1 starting..." >> /data/convert/encode.log

f=$(basename "${1%.*}")
ffmpeg -i "$1" -acodec libmp3lame -aq 0 "/data/convert/output/$f.mp3"
mv "$1" /data/convert/processed/

echo "[$(date +%H:%M:%S)] encode attempt of $1 complete" >> /data/convert/encode.log