You are here: Home » Reply » Reply To: Playlists and Podcasts

Reply To: Playlists and Podcasts

#13257
sonichouse
Participant

I couldn’t get gregarius to work on my slug with cherokee, so I hacked this bashpodder script.

I then set up cron to check every 4 hours.

bash-3.2# cat /etc/crontab
SHELL=/bin/sh
PATH=/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/
#

Default is Empty

#
0 0-23/8 * * * root /usr/sbin/CheckDiskFull &>/dev/null
0 0 * * * root /usr/sbin/WatchDog &>/dev/null
1 * * * * root /usr/sbin/hwclock -s &>/dev/null
15 */4 * * * root /share/hdd/data/public/mp3/bashpodder.sh -p

All my podcasts get dumped into a directory, playlist is generated, and I delete old podcasts.


#!/opt/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 10/23/2004 - The Lee Colleton/Wari Wahab/Dann Washko version.
# 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!

#VARS
PATH=/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
log=podcast.log
conf=bp.conf
playlist=podcast.m3u
numitems=3
maxdays=35
FIREFLY=192.168.100.77
FIREFLYPORT=3689

#usage function to print usage.
usage()
{
builtin echo -e >&2
"usage: $0 [-p] [-l] [-h] n -p make playlist n -l keep log trimmed n -h print this help"
exit 1;
}

#getopts for playlist and log trimming. (JCE)
while getopts plh opt
do
case "${opt}" in
p) pl=set;; # playlist switch
l) lt=set;; # log trim
h) hlp=set;; # show help exit
?) usage # unknown flag
exit 1;;
esac
done
shift $(($OPTIND - 1))

#check for help flag.
if [ "${hlp}" == "set" ]; then
usage
fi

# Quickie change to make the script more cron friendly
# Contributed by Wari Wahab
workdir=`dirname ${0}`
cd ${workdir}

# datadir is the directory you want the audio files to be put into
# I used a date string which will create a new directory every day
# Changed to iso date format as suggested by Lee Colleton!
# Updated to work on OSX by Dann Washko
# datadir=`date +%Y-%m-%d`

# SPF - set datadir to a fixed directory
datadir=podcasts

# test for existance of data directory and create if not there
if [ ! -d ${datadir} ]
then
mkdir ${datadir}
fi

# SPF - If this is the first time, touch podcast.log to shut up the grep below.
if ! [ -e ${log} ]
then
touch ${log}
fi


# Read the conf file for rss feeds you wish to grab audio from
# Used the sed line from Rodrigo Stulzer to better take care of
# non-standard rss. (JCE)

IFS_T=${IFS}
IFS='
'
I=0
while read url
do
urlcount=0;

for url in $(wget -q ${url} -O - | sed 's/<enclosure/n<enclosure/g' | grep "<enclosure " | tr ' " | sed -n 's/.*url="([^"]*)".*/1/p')
do
# limit podcasts to numitems downloaded
urlcount=$(( $urlcount + 1 ))
if ! grep "${url}" ${log} > /dev/null
then
if [ $urlcount -le $numitems ] ; then
wget -q -P ${datadir} ${url}
echo ${url} >> ${log}
((I += 1))
fi
fi

#save all urls for uptodate log file
#if -l flag is thrown
if [ "${lt}" == "set" ]; then
NEWLOG[${I}]=${url}
fi
done

done < ${conf}
IFS=${IFS_T}

#Write a new log file containing only urls in current rss feeds.
#if -l flag is thrown.
if [ "${lt}" == "set" ]; then
rm ${log}
for urllog in "${NEWLOG[@]}"; do
echo ${urllog} >> ${log}
done
fi


# SPF - Remove old files
removals=`find ${datadir} -maxdepth 1 -type f -mtime +${maxdays}|wc -l`
if [ $removals -ge 1 ]; then
echo "Removing ${removals} files"
find ${datadir} -maxdepth 1 -type f -mtime +${maxdays} -exec rm {} ;
fi


# That's it!
# Oh yeah, you probably want an m3u playlist (at least I do)
# added a switch for making the play list (JCE)
if [ "${pl}" == "set" ] ; then
ls ${datadir} | grep -v m3u > ${datadir}/${playlist}
fi

# SPF - Update Firefly by forcing a scan if files downloaded/deleted
if [ $(($I + $removals)) -ge 1 ]; then
wget --delete-after -q "http://mt-daapd:[email protected]${FIREFLY}:${FIREFLYPORT}/config-update.html?action=rescan"
fi

My bp.conf file is

http://downloads.bbc.co.uk/podcasts/fivelive/drkarl/rss.xml
http://downloads.bbc.co.uk/podcasts/worldservice/scia/rss.xml
http://downloads.bbc.co.uk/podcasts/radio4/fricomedy/rss.xml
http://downloads.bbc.co.uk/podcasts/radio2/ross/rss.xml
http://www.dailysourcecode.com/feed.xml

You just need to ensure bash and wget are installed. YMMV

Steve