#!/bin/bash # Original version by Linc 12/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! # # Changelog for revisions by Chess Griffin # # # v0.1 2005-12-07: initial set of revisions # v0.2 2006-12-01: second set of revisions incorporating # command line flags (based on some of # Brian Hefferan's changes) # # Default values can be set here. Command-line flags override these. verbose= # default: nothing is quiet; 1 is verbose wget_quiet='-q' # default: -q is quiet, can remove the -q to get output update_all= # default: nothing is normal download; 1 is update all first_only= # default: nothing is all files; 1 is first only fetchlist='bp.conf' # default is bp.conf; can change name to other file # No changes should be necessary below this line function usage { echo " Chess Griffin's modified BashPodder v0.2 2006-12-01 Usage: $0 [OPTIONS] Options are: -c, --config Use a different config file other than bp.conf -f, --first_only Grabs only the first new enclosed file found in each feed. The --update_all flag won't work with this option. If you want to download the first file and also permanently ignore the other files, run bashpodder with this option, and then run it again with --update_all. -h, --help Display this help message -u, --update_all Write all episode names to the log file without downloading the actual files. This is useful if you want to subscribe to some podcasts but don't want to download all the back episodes. Once this switch has been run and the episodes names have been updated in the podcast.log file, you can edit the podcast.log file afterwards to delete any episode you still wish to download the next time bashpodder is run. -v, --verbose Display verbose messages. bp.conf is the standard configuration file. It should contain a list of podcast feeds and local directories where each podcast's episodes will be saved. There should be a space between the feed and the local directory. For example, one line in the bp.conf file may look like this: http://wwww.lugradio.org/episodes.rss /home/user/podcasts/LUGRadio The first part of the line contains the URL of the podcast feed and the second part of the line is the local directory where the episodes of that podcast will be saved. Note that you can use the '-c' switch to pass a different configuration file when executing the script. One can also rename the default configuration file in the default settings located near the top of the script. Please note that one also needs the parse_enclosure.xsl file found at the BashPodder page: http://linc.homeunix.org:8080/scripts/bashpodder/. " } # Make script crontab friendly: cd $(dirname $0) # here are the command line switches while [ "$1" != "" ];do case $1 in -c|--config ) config=1 fetchlist=$2 ;; -f|--first_only ) first_only=1 ;; -h|--help ) usage exit ;; -u|--update_all ) update_all=1 ;; -v|--verbose ) verbose=1 ;; esac shift done # Make sure a config file is passed when -c switch is used if [ -z "$fetchlist" ]; then echo "You used the -c switch but did not include a configuration file. Run $0 -h for usage. Exiting."; exit 1; fi # Make sure the bp.conf file or the file passed with -c switch exists if test ! -f "$fetchlist"; then echo "The file $fetchlist does not exist. Run $0 -h for usage. Exiting."; exit 1; fi # print date if [ -n "$verbose" ]; then echo "Starting bashpodder on"; date; fi # Use an incoming folder to hold feeds prior to editing the file name # from James Stone if [ -n "$verbose" ]; then echo "Creating temp folders...";fi incoming="incoming" rm -rf $incoming mkdir $incoming # Delete any temp file: rm -f temp.log # If this is the first time running, create the podcast.log # from Scott Maxwell if ! [ -e podcast.log ] then if [ -n "$verbose" ]; then echo "Creating podcast.log file...";fi touch podcast.log fi # Read the bp.conf file and wget any url not already in the # podcast.log file: while read podcast datadir do seenfirst= # Skip lines beginning with '#' as comment lines - from Rick Slater # Also skip blank lines if echo $podcast | grep -E '^#|^$' > /dev/null then continue fi # Check to make sure datadir is listed on each line; if not, quit if test ! $datadir then echo "No feed directory specified in $fetchlist for the $podcast feed. Please edit $fetchlist and name a directory for this feed. Exiting." exit 1; fi # Check for and create datadir if necessary: # (Uses Tony Whitmore's addition to bp.conf where # name of directory comes after feed, e.g., # http://www.lugradio.org/episodes.rss LUGRadio) if test ! -d $datadir && test "$update_all" != "1"; then if [ -n "$verbose" ]; then echo "Creating $datadir directory to store feeds..."; fi mkdir -p $datadir fi 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 if [ -n "$first_only" ] && [ -n "$seenfirst" ]; then break;fi #the realurl fix for dynamically generated feeds (from Huw #Lynes and James Stone) realurl=`curl -s -I -L -w %{url_effective} --url $url | tail -n 1` #short url (i.e. filename!) from James Stone urlss=`echo $realurl|awk -F / '{print $NF}'` urls=`echo $urlss|awk -F ? '{print $1}'` echo $urls >> temp.log if [ -n "$update_all" ]; then if [ -n "$verbose" ]; then echo "Catching up $realurl...";fi elif ! grep "$urls" podcast.log > /dev/null then # added Christian Daven's wget switches if [ -n "$verbose" ]; then echo "Fetching $realurl...";fi wget $wget_quiet -c -T 2 -P $incoming "$realurl" #fix for ?podcast end to recent lugradio feeds #from James Stone mv $incoming/$urls* $datadir/$urls fi seenfirst=1 done # Create an m3u playlist: if [ -z "$update_all" ]; then if [ -n "$verbose" ]; then echo "Creating $datadir m3u playlist..."; fi ls $datadir | grep -v m3u > $datadir/podcast.m3u fi done < $fetchlist if test ! -f temp.log && [ -n "$verbose" ]; then echo "Nothing to download."; fi # Move dynamically created log file to permanent log file: if [ -n "$verbose" ]; then echo "Cleaning up...";fi cat podcast.log >> temp.log sort temp.log | uniq > podcast.log rm temp.log if [ -n "$verbose" ]; then echo "Done."; fi;