#!/bin/bash # Original version by Linc Fessenden 12/1/2004 # Find the latest script at: # http://lincgeek.org/bashpodder # # # # 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) # v0.3 2007-06-02: Add podshow.com fix, add m3u switch, and # tweak the echo statements # v0.4 2007-06-19: Add ability to remove spaces from filenames # v0.5 2008-01-06: Add in MSNBC feed fix from Brian Reichert # Default values can be set here. Command-line flags override these. first_only= # default: nothing is all files; 1 is first only m3u= # default: no m3u playlist is created; 1 will create m3u update_all= # default: nothing is normal download; 1 is update all verbose=1 # default: nothing is quiet; 1 is verbose fetchlist='bp.conf' # default is bp.conf; can change name to other file wget_quiet='' # default: -q is quiet, can remove the -q to get output # No changes should be necessary below this line function usage { echo " Chess Griffin's modified BashPodder v0.5 2008-01-06 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 will not 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 -m, --m3u Create m3u playlists -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 do not 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://feeds.feedburner.com/linuxreality /home/user/podcasts/LinuxReality 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://lincgeek.org/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 ;; -m|--m3u ) m3u=1 ;; -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 the 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 if [ -n "$verbose" ]; then echo "Checking "$podcast; 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` # Figure out the short url (i.e. filename!) from James Stone urlss=`echo $realurl|awk -F / '{print $NF}'` urls=`echo $urlss|awk -F ? '{print $1}'` # Replace URL encoded spaces in filenames with regular space nospace=`echo $urls|sed -e 's/%20/ /g'` # Remove all spaces from filenames nospace2=`echo $nospace|sed -e 's/ //g'` # Fix Podshow.com numbers that keep changing urlsfix=`echo $nospace2|sed s/_pshow_[0-9]*//` # Fix MSNBC podcast names for audio feeds from Brian Reichart if echo $realurl | grep -q 'msnbc.*pd_.*mp3$'; then urlsfix=`echo $urlss | sed -e 's/.*\(pd_.*mp3$\)/\1/'` fi if echo $realurl | grep -q 'msnbc.*pdm_.*mp3$'; then urlsfix=`echo $urlss | sed -e 's/.*\(pdm_.*mp3$\)/\1/'` fi if echo $realurl | grep -q 'msnbc.*vh-.*mp3$'; then urlsfix=`echo $urlss | sed -e 's/.*\(vh-.*mp3$\)/\1/'` fi # Fix MSNBC podcast names for video feeds if echo $realurl | grep -q 'msnbc.*pdv_.*m4v$'; then urlsfix=`echo $urlss | sed -e 's/.*\(pdv_.*m4v$\)/\1/'` fi echo $urlsfix >> temp.log if [ -n "$update_all" ]; then if [ -n "$verbose" ]; then echo "Catching up $realurl...";fi elif ! grep "$urlsfix" podcast.log > /dev/null then # Added Christian Daven's wget switches if [ -n "$verbose" ]; then echo "Fetching $realurl...";fi # File names longer than 255 characters break wget, this should # fix that. if echo $realurl | grep -q 'msnbc'; then wget $wget_quiet -c -T 2 -O $incoming/$urlsfix "$realurl" mv $incoming/$urlsfix $datadir else wget $wget_quiet -c -T 2 -P $incoming "$realurl" # Fix for ?podcast end to recent lugradio feeds # rom James Stone mv $incoming/"$nospace"* $datadir/$urlsfix fi fi seenfirst=1 done # Create an m3u playlist: if [ -z "$update_all" ]; then if [ -n "$m3u" ]; then if [ -n "$verbose" ]; then echo "Creating $datadir m3u playlist..."; fi ls $datadir | grep -v m3u > $datadir/podcast.m3u fi 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;