#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 07/01/2005 - 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!

# Make script crontab friendly:
cd $(dirname $0)

# Delete any temp file:
rm -f temp.log

# Read the bp.conf file and wget any url not already in the podcast.log file:
while read line
	do
	podcast=`echo $line | awk '{print \$1}'`
	# datadir is the directory you want podcasts saved to:
	datadir=`echo $line | awk '{if (""==\$2) $2="etc"; print \$2}'`
	file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -nc -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p')
	for url in $file
		do
		if ! grep "$url" podcast.log > /dev/null
			then
			if test ! -d $datadir
		            then
		            mkdir $datadir
			fi
			wget -nc -q -P $datadir "$url" && echo $url >> temp.log
		fi
		done
	done < bp.conf
# Move dynamically created log file to permanent log file:
cat podcast.log >> temp.log
sort temp.log | uniq > podcast.log
rm temp.log
# Create an m3u playlist:
#ls $datadir | grep -v m3u > $datadir/podcast.m3u

