#!/bin/bash # By Linc 10/1/2004 # Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder # Last revision 06/21/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! # # Modified by James Stone on 30th June 2005: # (jmstone at dsl dot pipex dot com) # Now uses filenames only in the log. This might not be a good idea if # different feeds use the same filenames, but it gets around the problem # associated with mirrored files: where if the full url changes, the file # is downloaded again. # 5th July 2005: Further fixes to deal with Lugradio's new ?tags at the # end of the filenames. # Make script crontab friendly: cd $(dirname $0) # datadir is the directory you want podcasts saved to: incoming="incoming" datadir=$(date +%Y-%m-%d) # Check for and create datadir if necessary: if test ! -d $datadir then mkdir $datadir fi rm -rf $incoming mkdir $incoming # 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 file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p') for url in $file do #the realurl fix for dynamically generated feeds (thanks huw lynes) realurl=`curl -s -I -L -w %{url_effective} --url $url | tail -n 1` #short url (i.e. filename!) urlss=`echo $realurl|awk -F / '{print $NF}'` urls=`echo $urlss|awk -F ? '{print $1}'` #echo $urlss|awk -F ? '{print $1}' if ! grep "$urls" podcast.log > /dev/null then wget -q -P $incoming "$realurl" #fix for ?podcast end to recent lugradio feeds mv $incoming/$urls* $datadir/$urls echo $urls >> 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 #only create a directory if there are any podcasts! thanks leon pennington! if [[ -z $(ls $datadir) ]]; then rmdir $datadir else # Create an m3u playlist: ls $datadir | grep -v m3u > $datadir/podcast.m3u fi