#!/bin/bash # By Linc 10/1/2004 # Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder # Last revision 11/17/2004 - 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! # Make script crontab friendly: cd $(dirname $0) # datadir is the directory you want podcasts saved to: datadir=podcasts # $(date +%Y-%m-%d) # Check for and create datadir if necessary: if test ! -d $datadir then mkdir $datadir fi # Lock this section # if another bashpodder is going, drop out if ! dotlockfile -r 0 -p .bashpodder.lock then exit 0 fi # touch the bashpodder.log file, so it won't complain that it doesn't exist # when it first runs. touch bashpodder.log # if it doesn't exist, its a recipe for disaster! check! if ! [ -w bashpodder.log ] then echo "Could not write to bashpodder.log! Exiting..." exit 1 fi # clear the todo list echo -n > all_rss.log # if it doesn't exist, its a recipe for disaster! check! if ! [ -w all_rss.log ] then echo "Could not write to all_rss.log! Exiting..." exit 1 fi # Read the bp.conf file and wget any url not already in the bashpodder.log file: wget --quiet --input-file=bp.conf --output-document=all_rss.log file=$(cat all_rss.log | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p') # Now process the 'todo' list for url in $file do if ! grep "$url" bashpodder.log > /dev/null then if wget --quiet --tries=1 --limit-rate=25k --mirror --directory-prefix=$datadir $url then # 'commit' the transaction to the bashpodder.log echo $url >> bashpodder.log fi fi # Recreate an m3u playlist: ls -tr $datadir | grep -v m3u > $datadir/podcast.m3u done # Remove the dotlock file, allow other bashpodders to do the above # ie wget etc dotlockfile -u .bashpodder.lock # Finally, if the btlaunchmany isn't running, run it now. # This will mean this particular script instance will never end, # but the script can be safely re-run (eg via crontab) # try to lock the dotlock once. if not, then torrents must be going. if dotlockfile -r 0 -p .bashpodder-torrent.lock then btlaunchmany --max-download-rate 25 . > /dev/null # remove dotlockfile (not actually important, the pid check will # handle leftover dotlocks, but nice to be clean) dotlockfile -u .bashpodder-torrent.lock fi