#!/bin/bash # By Linc 10/1/2004 # Find the latest script at http://lincgeek.org/bashpodder # Revision 1.21 12/04/2008 - 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) # datadir is the directory you want podcasts saved to: datadir=$(date +%Y-%m-%d) # create datadir if necessary: mkdir -p $datadir mkdir -p xmlcache # 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 podcast do # xmlfile=xmlcache/$(echo "$podcast" | awk -F'://' {'print $NF'} | tr '/' '_') # echo "$xmlfile" # wget -S -t 10 -U BashPodder -N -c -O $xmlfile $podcast # file=$(xsltproc parse_enclosure.xsl $xmlfile 2> /dev/null || wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p') file=$(xsltproc parse_enclosure.xsl $podcast 2> /dev/null || wget -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 original_url=$url # first redirect url to make it pretty for (( tries=0; tries < 10; tries+=1 )) { newurl=$(curl -s --head "$url" | awk '/^Location:/ {print $2}' | tr -d '\r') if [ "$newurl" != "" ] && [ "$newurl" != "$url" ] then url=$newurl else break fi } wget -t 10 -U BashPodder -q -O $datadir/$(echo "$url" | awk -F'/' {'print $NF'} | awk -F'?' {'print $1'}) "$url" if [ $? == 0 ]; then echo $original_url >> temp.log else echo "Could not download $url" fi 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 -rt $datadir/*.{ogg,mp3} > $datadir/podcast.m3u