#!/bin/bash if [ "$1" = "--help" ]; then echo " # By Linc 10/1/2004 # Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder # Revision 1.2 09/14/2006 - 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! OPTIONS --help Show help text -n Add new podcast interactively -u [url...] Add new podcast automatically (New Podcasts will only download the most recent episode, to select other podcasts, delete that line from the 'podcast.log' file included in your BashPodder directory) " exit 0 fi # ************************************************************************ # Number of episodes to download from a new feed downnum=3 # datadir is the directory you want podcasts saved to: datadir=/home/$USER/podcasts # Pass the first argument to the 'arg' variable. arg="$1" # Check if a new podcast will be added # bp.temp is used to hold the feed url before it can be added bp.conf # so that any new podcasts are not accidentally added to podcast.log # without downloading the podcast if [ "$arg" = "-n" ]; then echo "Please enter the url of the new podcast feed:" read feedurl echo $feedurl > bp.temp elif [ "$arg" = "-u" ]; then echo $2 > bp.temp arg="-n" else cat bp.conf > bp.temp fi # Make script crontab friendly: cd $(dirname $0) # create datadir if necessary: mkdir -p $datadir # Delete any temp file: rm -f temp.log # Read the bp.conf file and wget any url not already in the podcast.log file: getpodcast () { while read podcast do 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 echo $url >> temp.log if ! grep "$url" podcast.log > /dev/null && [ "$arg" != "-n" ] then wget -t 10 -U BashPodder -c -q -O $datadir/$(echo "$url" | awk -F'/' {'print $NF'} | awk -F'=' {'print $NF'} | awk -F'?' {'print $1'}) "$url" fi done done < bp.temp # Move dynamically created log file to permanent log file: cat podcast.log >> temp.log cat temp.log > temp2.log if [ "$arg" = "-n" ]; then cat bp.conf >> bp.temp sort bp.temp | uniq > bp.conf sed -e "1,${downnum}d" temp.log | sort | uniq > podcast.log else sort temp.log | uniq > podcast.log fi rm temp.log temp2.log bp.temp } # This calls the previous function. If it is invoked with an option to # add a new podcast, the feed is downloaded, then re-run to download # the newest podcast in the feed along with any others which may be # available getpodcast if [ "$arg" = "-n" ]; then cat bp.conf > bp.temp arg="" getpodcast fi # Create an m3u playlist: ls $datadir | grep -v m3u > $datadir/podcast.m3u