#!/bin/bash # By Linc 10/1/2004 # Merijn Vogel 2005/05/16 added: # bittorrent downloading # postprocessing for mp3 files (to either make them smaller or make them compatible with my player) # gave it a verbose option # this script now depends on: screen, lame and bittorrent # 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! function usage() { echo "usage: $0 [-h -v -q -l]" echo " -h prints this" echo " -l enables lame postprocessing (to shrink files)" echo " -q makes me quiet" echo " -v makes me verbose" echo " -n ## max number of items per feed (do not forget the space between -n and the number)" } function utter() { if [ "$verbose" = "1" ] ; then echo $* fi } verbose=0 quiet=0 uselame=0 # one may want to set these from the commandline? lameopts="--resample 44100 --abr 96 -b32 -B96" # MV: commandline arguments parsing while [ "$1" ] ; do if [ "$1" = "-v" ] ; then quiet=0 verbose=1 elif [ "$1" = "-h" ] ; then usage exit elif [ "$1" = "-q" ] ; then quiet=1 verbose=0 elif [ "$1" = "-l" ] ; then uselame=1; elif [ "$1" = "-n" ] ; then numitems=$2 if [ ! "$numitems" ] ; then numitems=20 ;fi fi shift done if [ "$quiet" = "1" ] ; then wgetquiet="-q" lamequiet="--quiet" fi # Make script crontab friendly: cd $(dirname $0) # datadir is the directory you want podcasts saved to: datadir=$(date +%Y-%m-%d) # MV: datadirpost is the directory where re-encoded podcasts go to: datadirpost=${datadir}.finished # Check for and create datadir if necessary: if test ! -d $datadir then mkdir $datadir fi if test ! -d $datadirpost then mkdir $datadirpost fi # Delete any temp file: rm -f temp.log # Read the bp.conf file and wget any url not already in the podcast.log file: while read podcast do utter "getting podcast feed: $podcast" # MV: only get the first $numitems at maximum file=$(wget -c $wgetquiet $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p' ) urlcount=0; for url in $file ; do echo $url >> temp.log urlcount=$(( $urlcount + 1 )) if ! grep "$url" podcast.log > /dev/null ; then if [ $urlcount -le $numitems ] ; then utter "[$urlcount / $numitems]" $url wget $wgetquiet -c -P $datadir "$url" if [ "$uselame" = "1" ] ; then pushd $datadir find . -name '*.mp3' | while read mp3 ; do lame $lamequiet $lameopts "$mp3" -o "../$datadirpost/$mp3" done popd fi fi fi done done < bp.conf # MV: Bittorrent downloading using the commandline bittorrent client from debian # some extra explanation: # The bittorrentclient cannot work outside a tty; even the headless variant cannot. # Therefore the downloads are started in new screen sessions which start out in a detached # state. These torrents are running forever; sharing the file. One must manually shutdown the # btdownloadcurses processes by attaching to the screens and quitting the application. # Also, take not that the .torrent files are not removed; if you start this script more than once a day, # you may run into problems as two bittorrents will run for the same file. # I have not figured out how to automate the killing of these torrents, or how to get them grouped in one screen session. pushd $datadir count=0 find . -name '*.torrent' | while read torrent ; do count=$(($count + 1)) utter "starting bittorrent download number $count in a new screen session" screen -d -m btdownloadcurses --max_upload_rate 8 "$torrent" & done if [ $count -gt 0 ] ; then utter "started $count torrents.. postprocessing of resulting files need to be done manually, because I cannot detect the finishing of those downloads. Re-encoding may happen the next time this script starts." fi popd # Move dynamically created log file to permanent log file: cat podcast.log >> temp.log sort temp.log | uniq > podcast.log rm temp.log # Create an m3u playlist: ls $datadirpost | grep -v m3u > $datadirpost/podcast.m3u