#!/bin/bash # By Linc 10/1/2004 # Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder # Last revision 12/14/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! #debug #set -x # Make script crontab friendly: cd $(dirname $0) #set up directory names here so we can change them without #having to re-write the whole script # datadir is the directory you want podcasts saved to: datadir=$(date +%Y-%m-%d) # incoming is the directory incoming poscasts are saved to before completion incoming="incoming" #In Selfish mode dont relauch bittorrent to seed #set to 0 to be a selfish shellfish selfish=1 #logfiles podcastlog="podcast.log" temppodcastlog="temp.log" torrentlog="torrent.log" #configuration file config="bp.conf" #temporary list of torrent files torrentlist="torrentlist" # Check for and create datadir if necessary: if test ! -d $datadir then mkdir $datadir fi # Check for and create incoming directory if test ! -d $incoming then mkdir $incoming fi # Delete any temp file: rm -f $temppodcastlog rm -f $torrentlog # Read the bp.conf file and wget any url not already in the podcast.log file: while read podcast do file=$(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" $podcastlog > /dev/null then #lets get the real url in the case of dynamically generated feeds like lugradio realurl=`curl -s -I -L -w %{url_effective} --url $url | tail -n 1` #we'll need filename to allow us to move the poscast into datadir filename=`echo $realurl | awk -F / '{print $NF}'` #file is a torrent so hand off to btpodder.py if [ `echo $filename | grep ".torrent"` ] then audiofilename=`echo $filename | sed 's/\.torrent//'` #btpodder does the hard work of getting the file and then exiting screen -D -m ./btpodder.py --url $realurl --saveas $incoming/$audiofilename #if we've succeeded add file to podcast log and move to datadir if [ $? == 0 ] then mv $incoming/$audiofilename $datadir echo $url >> $podcastlog #create log for relaunching torrents echo -n $realurl >> $torrentlog echo " "$datadir/$audiofilename >> $torrentlog fi #not a torrent so use wget else wget -q -c -P $incoming $realurl #if we succeeded in the download add the file to the log if [ $? == 0 ] then mv $incoming/$filename $datadir echo $url >> $podcastlog fi fi fi done done < $config # Move dynamically created log file to permanent log file: cat $podcastlog > $temppodcastlog sort $temppodcastlog | uniq > $podcastlog rm $temppodcastlog # Create an m3u playlist: #slightly more comlicatd to deal with #geeknewscentral who put their stuff in directories ( cd $datadir find . -name \*.mp3 > podcast.m3u find . -name \*.ogg >> podcast.m3u ) #If we are not in selfish mode relaunch the torrents to seed if [ $selfish != 0 ] then #we only need to do the following if we actually encountered #some torrents if [ -e $torrentlog ] then #use contents of torrentlog as positional parameters set `cat $torrentlog` while [ $# != 0 ] do url=$1 file=$2 screen -d -m btdownloadheadless.py --url $url --saveas $file shift shift done fi fi