Darkland | net

Script To Download Democracy Now MPEG

Published on 05 February, 2016 by Amanda

#!/bin/bash
#######################################################
# Types of output:
# stdin - 0 - Standard Input (usually keyboard or file)
# stdout - 1 - Standard Output (usually screen)
# stderr - 2 - Standard Error (usually screen)
# stdout and stderr - & Standard Output and Standard Error
# ex.: command 2> /dev/null redirects error
# messages to special device /dev/null
#
# 20160205 Added logic to account for
# missing torrent file at democracynow.org
# and to try every 10 minutes for an hour
# if it does not. Hides wget error message
# and only prints exit status if file does
#
# 20160602 added oldvids variable, and rm command to
# 
# 20161029 added command line variable to allow downloading
# torrent for show from the day before. For example, adding
# line will download Thursday's show on Friday. This will
# only work for "day before" shows and not for downloading
#
#######################################################
day=$1
daystamp=$(date +%Y-%m%d)
#message="/tmp/demnow-dl_message.txt"
MIN=2
oldvids=$HOME/Videos/dn$(date +%Y)*
rcount=1
stamp=0
tdl="http://ewheel.democracynow.org/dn$daystamp.mp4.torrent"
tfile="$HOME/torrents/dn$daystamp.mp4.torrent"
timestamp=$(date +%X)

#rm -v $oldvids 2> /dev/null
rm -v $HOME/torrents/*torrent 2> /dev/null

cd $HOME/torrents

if [  $1  ] ;then
	daystamp=0
	echo $daystamp
	stamp=$(TZ=PST+24 date +%Y-%m%d)
	echo $stamp
	tdl="http://ewheel.democracynow.org/dn$stamp.mp4.torrent"
	tfile="$HOME/torrents/dn$stamp.mp4.torrent"
fi

until wget $tdl 2> /dev/null; do
	printf "Torrent file not found. Will try again in two minutes.\n\n"
	if [ $rcount -lt 6 ]; then
		
		printf "Attempt: $rcount\n"
		printf " \n"
		rcount=`expr $rcount + 1`
	else
		exit
	fi
done

if ps aux | grep 'transmission-gtk' | grep -v grep 1> /dev/null ; then
		cd $HOME && transmission-gtk $tfile  
		exit
	else
		cd $HOME && transmission-cli -w $HOME/Videos/ $tfile
		rm $tfile 2> /dev/null
fi

exit
Back