Shell script to downsample podcasts
Last modified on July 24, 2026 • 2 min read • 251 wordsI have a very basic mp3 player with only 128 MB memory.
I have a very basic mp3 player with only 128 MB memory. I mostly listen to podcasts which are automatically downloaded by Amarok into the folder ~/.kde/share/apps/amarok/podcasts/data. In order to fit many of them to the limited memory and to have them available from anywhere, I have been writing a script that automatically downsamples them as they arrive and puts them online to my web server. The script is executed hourly by the crontab. The two relevant files look like this:
server:/etc/cron.hourly> more podcast_convert.sh
#!/bin/bash
/home/marzena/bin/podcast_convert.sh /home/marzena/.kde/share/apps/amarok/podcasts/data/*.mp3server:~/bin> more podcast_convert.sh
#!/bin/bash
if [ $1 = "/home/marzena/.kde/share/apps/amarok/podcasts/data/*.mp3" ]
then
echo "$1: No files to process!"
exit 1
else
while [ $# -ge 1 ]; do
infn=$1
echo "Infile = "$infn
strippedinfn=`basename $1`
strippedinfn=${strippedinfn//:/}
echo "Stripped Infile = "$strippedinfn
outfn="/srv/www/htdocs/vhosts/jeltsch.org/podcasts/${strippedinfn%%.mp3}_LQ.mp3"
echo "Outfile = "$outfn
if test ! -f $outfn
then
echo "Downsampling $outfn."
lame --mp3input -V 3 --strictly-enforce-ISO --resample 12 $infn $outfn
else
echo "The file $outfn has been already downsampled. Skipping…"
fi
# rm $infn
shift 1
done
fiA modern version would look like this:
#!/bin/bash
if [ "$1" = "/home/marzena/.kde/share/apps/amarok/podcasts/data/*.mp3" ]; then
echo "$1: No files to process!"
exit 1
else
while [ $# -ge 1 ]; do
infn="$1"
echo "Infile = $infn"
strippedinfn=$(basename "$1")
strippedinfn=${strippedinfn//:/}
echo "Stripped Infile = $strippedinfn"
outfn="/srv/www/htdocs/vhosts/jeltsch.org/podcasts/${strippedinfn%%.mp3}_LQ.mp3"
echo "Outfile = $outfn"
if [ ! -f "$outfn" ]; then
echo "Downsampling $outfn."
lame --mp3input -V 3 --strictly-enforce-ISO --resample 12 "$infn" "$outfn"
else
echo "The file $outfn has been already downsampled. Skipping…"
fi
# rm "$infn"
shift
done
fi