#!/bin/bash

# variablen
feedurl=/data/podcasts/feed.xml
mp3url=http://wasserbett.ath.cx/podcasts/
podcastfolder=/data/podcasts

# Beginn der feed.xml
cat > $feedurl << EOF
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Podcast Sammlung</title>
<description>Interessante Podcasts</description>
<link>$mp3url</link>
<language>de</language>
EOF

# MP3 files finden und einsortieren
filelist=`ls -lt $podcastfolder/*.mp3 | awk '{print $9}'`
for FilewithfullPath in $filelist
do
 file=$(basename $FilewithfullPath)
 mp3val $FilewithfullPath -f
 if [ -f $FilewithfullPath.bak ]; then
  rm $FilewithfullPath.bak
 fi
 filesize=`ls -l $FilewithfullPath | awk '{print $5}'`
 filewithoutExtension=${file/.mp3/}
cat >> $feedurl << EOF
<item>
<title>${filewithoutExtension//./ }</title>
<description></description>
<enclosure url="$mp3url$file" length="$filesize" type="audio/mpeg"/>
</item>
EOF
done

cat >> $feedurl << EOF
</channel>
</rss>
EOF
exit 0
