#!/bin/bash

# Modified by John Jensen 2005.01.23, to split into "check" and "fetch".
# The idea being to run "check.bash", pause, examine the "new_mp3"
# file and delete anything I don't really want before I invoke the
# "fetch.bash" file to go out and get them.  The "fetch script"
# also has changes to support Evil Genius style torrent mp3s.

# 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!

# Make script crontab friendly:

cd $(dirname $0)

# datadir is the directory you want podcasts saved to:

datadir=$(date +%Y-%m-%d)

# Check for and create datadir if necessary:

if test ! -d $datadir
        then
        mkdir $datadir
fi

# Delete any temp file:

rm -f temp.log

# Read the new_mp3 file to get urls to fetch

while read url
do
  if echo $url | grep torrent >/dev/null
  then
	name=`basename $url`
	btdownloadgui --saveas $datadir/$name --url $url &
  else
	wget -nc -P $datadir "$url"
  fi
done < new_mp3

# Create an m3u playlist:

# ls $datadir | grep -v m3u > $datadir/podcast.m3u

