|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +INPUT_DIR=/var/www/archive.wmfo.org/archives |
| 4 | + |
| 5 | +MAX_AGE=` echo "$((365*24*3600))"` |
| 6 | +CONVERTED_EXTENSION=m4a |
| 7 | + |
| 8 | +for full_filename in $INPUT_DIR/2018-03*.s16 ; do |
| 9 | + filename=$(basename $full_filename) |
| 10 | + extension=${filename##*.} |
| 11 | + basefilename=${filename%.*} |
| 12 | + directory=$(dirname $full_filename) |
| 13 | + input_date=`echo "$basefilename:00:00" | sed 's/_/ /g' | sed 's/U//g'` |
| 14 | + utc_file_seconds=`date -u -d "$input_date" +%s` |
| 15 | + utc_current_seconds=`date -u +%s` |
| 16 | + seconds_age=`echo "$(($utc_current_seconds - $utc_file_seconds))"` |
| 17 | + output_filename="${full_filename%.s16}.m4a" |
| 18 | + if [ -f $output_filename ] ; then |
| 19 | + converted_filesize=`du -k "$output_filename" | cut -f1` |
| 20 | + original_filesize=`du -k "$full_filename" | cut -f1` |
| 21 | + ratio=`echo "$(($original_filesize / $converted_filesize))"` |
| 22 | + if [ $ratio -lt 13 ] ; then |
| 23 | + echo "File: $full_filename has $CONVERTED_EXTENSION file of sufficient size. Removing." |
| 24 | + mv -n $full_filename ${full_filename}.to-delete |
| 25 | + else |
| 26 | + echo "File: $full_filename has $CONVERTED_EXTENSION TOO SMALL. Removing." |
| 27 | + mv -n $output_filename ${output_filename}.to-delete |
| 28 | + fi |
| 29 | + fi |
| 30 | + if ! [ -f $output_filename ] && [ $seconds_age -gt $MAX_AGE ] ; then |
| 31 | + echo "Age $seconds_age is greater than MAX_AGE, must convert: $full_filename" |
| 32 | + /usr/local/bin/ffmpeg -f s16le -ar 48000 -ac 2 -i $full_filename -c:a libfdk_aac -b:a 128k $output_filename < /dev/null |
| 33 | + fi |
| 34 | +done |
0 commit comments