funkwlmpv/cache_helper.sh

33 lines
921 B
Bash
Raw Normal View History

#!/bin/bash
if [ ! -n "$1" ]; then
echo 'Usage: cache_helper.sh path/to/cache'
exit 1
fi
total_before=0
total_after=0
for i in "$1"/*/*; do
2023-03-01 00:14:23 +02:00
if [ $(ffprobe -hide_banner -print_format json -select_streams a:0 -show_streams "$i" | jq -r '.streams[0].bit_rate') -gt 128000 ]; then
size_before=$(stat --format=%s "$i")
total_before=$(( $total_before + $size_before ))
ffmpeg -hide_banner -loglevel error -i "$i" -vn "$i".ogg
if [ $? -eq 0 ]; then
size_after=$(stat --format=%s "$i".ogg)
total_after=$(( $total_after + $size_after ))
2023-03-01 00:14:23 +02:00
size_reduced=$(( $size_before - $size_after ))
echo "Reduced: $(echo $size_reduced | numfmt --to=iec)"
mv "$i".ogg "$i"
else
echo "$i convert failed"
fi
else
2023-03-01 00:14:23 +02:00
echo "$i already OK"
fi
done
echo "Total before: $(echo $total_before | numfmt --to=iec)"
echo "Total after: $(echo $total_after | numfmt --to=iec)"
echo "Note: only included processed tracks"