#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 12/14/2004 - Many Contributers!
# If you use this and have made improvements or have comments
# drop me an email at linc dot fessenden at gmail dot com
# I'd appreciate it!
flag=$1
# Make script crontab friendly:${homedir}/ podcast.log
cd $(dirname $0)
homedir=${HOME}
LOGFILE=${homedir}/testpodcast.log
TEMPLOG=${homedir}/testtemp.log
CONFILE=${homedir}/bp.conf
PLAYLIST=`date +%A`

# datadir is the directory you want podcasts saved to:
DATADIR=/backup/mp3/Pod_Casts/Junk

# Check for and create datadir if necessary:
if test ! -d $DATADIR
       then
       mkdir $DATADIR
fi

# Delete any temp file:
rm -f ${TEMPLOG}

# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
       do
       file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p')
       for url in $file
               do
               echo $url >> ${TEMPLOG}
               if ! grep "$url" ${LOGFILE} > /dev/null
                       then
                       echo "$url"
###  uncomment the following to build  ignore list

                        echo  wget -q -P ${DATADIR} "$url"

               fi
               done
       done < ${CONFILE}
# Move dynamically created log file to permanent log file:
cat ${LOGFILE} >> ${TEMPLOG}
sort ${TEMPLOG} | uniq > ${LOGFILE}
#rm ${TEMPLOG}
# Create an m3u playlist:
ls ${DATADIR} | grep -v m3u > ${DATADIR}/${PLAYLIST}

