#!/bin/bash # By Linc 10/1/2004 # Find the original script at http://linc.homeunix.org:8080/scripts/bashpodder # 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! # Added various functionality 03/2005 B. O'Steen # The file continuing is a little bit beta.... # ben at maysubdivide dot org # for the crontab cd $(dirname $0) # Possible directorys to store the podcasts. Will use # the first valid directory. # (For those who sometimes store their 'casts straight # to their player, but not always.) datadirs="/media/removeable/podcasts /mnt/usb/podcasts /music/podcasts" datadir="placeholder" # All mp3's are downloaded one at a time to $tmpdir and then moved. # They are moved as soon as they have been downloaded however. # This cuts down on the amount of writing to a portable player, # as they don't seem to be fond of repeated additions to files... # especially flash players. # This is IMO that is. My iRiver does burn less battery power when connected up in this way. tmpdir="/tmp" dateum=$(date +%F) #Appended -c flag to wget. Turn this to 1 to not attempt a download if a file with the same name is found. overwritefiles=0 #defaults: Don't stream, update log and try to continue files that have been logged as downloaded or exist in the target directory. # NB Sorry that I have used counter intuitive truths.... (I was thinking about return codes at the time, 'exit 0') # 0 - True # 1 - False streamxmms=1 updatelog=0 ignorelog=1 retainnames=0 #Verbose? verbose=1 for args in $@ do if test -d $args then datadirs=$args else case $args in # Create m3u list and pass it to xmms. Do not log the files "-stream" | "-Stream" | "-STREAM" | "-s" | "-S" ) streamxmms=0 updatelog=1 ;; # Update log file. Useful with xmms streaming if you want to not # download the same file you just heard. "-log" | "-Log" | "-LOG" | "-l" | "-L" ) updatelog=0 ;; #Update log file and create a stream m3u for xmms "-logStream" | "-logstream" | "-streamlog" | "-streamLog" | "-STREAMLOG" | "-sl" | "-SL" | "-ls" | "-LS" ) streamxmms=0 updatelog=0 ;; # A bit of an outdated flag feature.... might remove this soon. "-continuelog" | "-CONTINUELOG" | "-continue" | "-CONTINUE" | "-c" | "-C" ) # Was caught short running this program last time, so update log first with # And then carry on if test -e temp.log then cat ~/podcast.log >> $tmpdir/temp.log sort $tmpdir/temp.log | uniq > ~/podcast.log fi ;; # ignore the log file and look at all valid urls in the rss feeds "-ignore" | "-IGNORE" | "-ignorelog" | "-IGNORELOG" ) ignorelog=0 ;; # keep the urls in the filenames of the files downloaded. Useful if your bp.conf goes bang "-k" | "-K" | "-keepurls" ) retainnames=1 ;; #Verbose? "-v" | "-V" | "-verbose" ) verbose=0 ;; # Show help dialog "-h" | "-H" | "--h" | "--H" | "-help" | "-HELP" | "--help" | "--HELP" ) echo "Podding tool. Can download and stream rss pocasts" echo "" echo "Usage:" echo "" echo "-stream (-s)" echo " Create m3u list and pass it to xmms." echo " (Doesnt log which files.)" echo "-keepurls (-k)" echo " Compact the url and use this as the filename instead." echo " Useful for keeping tabs on which 'cast came from where" echo " without having to listen to it or checking its id3 tag" echo "-logstream (-ls)" echo " Create m3u list and pass it to xmms." echo " Does log which files." echo "-log (-l)" echo " Update log at end of operation." echo "-continuelog (-c)" echo " Continue with temp log if bashpodder" echo " was halted midway" echo "-ignorelog" echo " Ignores the log and downloads all files" echo " that do not exist in target directory" echo "-verbose (-v)" echo " Echo which feeds are being checked and" echo " downloaded" echo "-help (-h)" echo " Shows this dialog" echo "---------" echo "/place/my/feeds/here" echo " Pass a directory to have the feeds downloaded" echo " there. Useful with -ignorelog to create a" echo " snapshot of the feeds" exit 0 ;; esac fi done # Check for datadir if not streaming: if [ $streamxmms -eq 1 ] then for rsslocation in $datadirs; do if test -d $rsslocation then datadir=$rsslocation if test ! -d $datadir/$dateum then mkdir $datadir/$dateum fi if [ $verbose -eq 0 ] then echo "Feed placed in $datadir" fi break 2 fi done if [[ $datadir = "placeholder" ]] then echo "No valid location available. Edit the datadirs" echo "variable in the script to suit your system" echo "datadirs is currently $datadirs" echo "Alternatively, you can pass a valid directory on the command line" echo "" echo " [user@localhost]$ rsspodder /mnt/usb/podcasts" echo "" echo "for example." exit 65 fi fi # Delete any temp file: rm -f $tmpdir/temp.log rm -f $tmpdir/tempm3u.m3u # Go through the podcasts in bp.conf, ignoring those with a '#' at the beginning grep -v "^#" ~/bp.conf > $tmpdir/filtered.feeds while read podcast do if [ $verbose -eq 0 ] then echo "Checking $podcast" fi file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p') for url in $file do # Consult log? ignore=0 if [ $ignorelog -eq 1 ] then if grep "$url" ~/podcast.log > /dev/null then ignore=1 fi fi if [ $ignore -eq 0 ] then #Does the file exist already and if so, should it be overwritten? downloadthisurl=1 filenametocheck="" if [ $retainnames -eq 1 ] then sanitised=`echo ${url/%".mp3"/} | tr -d / | tr -d \: | tr -d .` filenametocheck=$sanitised.mp3 else t=${url%/} filenametocheck=${t##*/} fi verboseAddition="" if test -e $datadir/$dateum/$filenametocheck then if [ $overwritefiles -eq 0 ] then downloadthisurl=0 verboseAddition=" - file found. Trying to continue." else downloadthisurl=1 fi else downloadthisurl=0 fi finalfilename="" if [ $downloadthisurl -eq 0 ] then if [ $streamxmms -eq 1 ] then if [ $verbose -eq 0 ] then echo $verboseAddition wget -c "$url" -P $tmpdir else wget -q -c "$url" -P $tmpdir fi if [ $retainnames -eq 1 ] then t=${url%/} savedfilename=${t##*/} sanitised=`echo ${url/%".mp3"/} | tr -d / | tr -d \: | tr -d .` finalfilename=$sanitised.mp3 mv $tmpdir/$savedfilename $datadir/$dateum/$finalfilename else t=${url%/} finalfilename=${t##*/} mv $tmpdir/$finalfilename $datadir/$dateum/$finalfilename fi else echo "$url" >> $tmpdir/tempm3u.m3u fi fi # update log? if [ $updatelog -eq 0 ] then echo $url >> $tmpdir/temp.log fi fi done done < $tmpdir/filtered.feeds # Update the logfile? if [ $updatelog -eq 0 ] then cat ~/podcast.log >> $tmpdir/temp.log sort $tmpdir/temp.log | uniq > ~/podcast.log fi if [ $streamxmms -eq 0 ] then #send it to xmms $tmpdir/tempm3u.m3u & fi #Clean up temporary files rm -f $tmpdir/filtered.feeds rm -f $tmpdir/temp.mp3 exit 0