#!/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! # Amended by Nik Butler 2005 10 12 # Dropped creation of date in favour of downloading podcasts by title. # using wgets -N timestamp and -c Continue feature to grab the files. # wget knows what the filename is and if we have seen it or not # of course the above screws up if the file names change ! # also we accept 1 argument ... the count of the shows to download from the feed. # this stops the files going MAD trying to grab everything from the feed. # ive split the xsl files up to spot the title in the feed. # # 2005 11 20 - Split bp.conf into everyday and weekly downloads # # 2005 12 10 - test the result of file to see if its long enough to be a http:// line. # it does get it more than neccesay ... must fix this ! # with lincs help ive added a method for reading feeburner/itunes style css functions # Make script crontab friendly: cd $(dirname $0) rm current_shows temp_shows # Make a List of Shows we currently Have available. du -a | grep -i mp3 | awk '{FS=" "; print $2}' >temp_shows TODAY=`date +%A`.bp.conf if [ -e $TODAY ] then FILES="$TODAY bp.conf" else FILES="bp.conf " fi # This will read bp.conf every day and a file named WEEKDAY.bp.conf cat $FILES | while read podcast do echo "$podcast" # So First we grab the title of the shows we are grabbing. title=$(wget -q $podcast -O - | xsltproc parse_enclosure_title.xsl - 2>/dev/null) # drop spaces and annoying characters from the name. # i could do this all on one line but im lazy ! title=${title//\ /_} title=${title//\'/} title=${title//\\/} title=${title//\//} # then create the directory. if ! test -d "$title" then mkdir $title fi # grab the links to the files download from the Rss Feed. ## test the return length i guess it needs to be longer than http:// file=$(wget -q $podcast -O - | xsltproc parse_enclosure_url.xsl - 2>/dev/null ) if [ ${#file} -lt 8 ] then file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p') fi if [ ${#file} -lt 8 ] then file=$(wget -q $podcast -O - | xsltproc parse_retarded_feed.xsl - 2>/dev/null ) fi # count the files we are downloading. fileCount=0 for url in $file do echo $url # We need to make sure that the Output file looks like filename.mp3 since # this makes life easier for other applications looking for them. # note a lot of feeds are getting wierd redirect strings and renames .. so watch out for wierd # urls turning up from time to time . outfile=$(echo $url | awk 'BEGIN { FS = "/" } ; { print $(NF) }') outfile=${outfile//\?[a-z]*/} if [ -n "$1" ] then if [ $fileCount -eq $1 ] then break fi fi wget -c -N -P $title -O ./${title}/${outfile} "$url" fileCount=$(($fileCount+1)) done done du -a | grep -i mp3 | awk '{FS=" "; print $2}' >>temp_shows datenow=$(date +%Y-%m-%d) sort temp_shows | uniq -u >> PodCasts-$datenow # Now Ive added this bit to set the Podcast Albums to the word 'Podcast' and the Genre to Speech. # making this easier for me to locate them on my ipod while read mp3file do id3v2 -A Podcast -g 101 $mp3file done < PodCasts-$datenow