#!/bin/bash
#                        /usr/local/bin/di
#  http://crystalfaeries.net/posix//bin/di
# celeste:crystalfaery 2016-05-01 20:30:10+00:00
# Digitally Imported Stream Ripper
# Optional argument is the DI stream MountPoint, else we:
# bring up the list of streams, from which user selects one,
# with copy/paste of mountpoint back into this terminal-interactive script:

# Configuration:
usernumber=255					# which subscriber are we?
relayport=8007					# relay port for monitoring the rip
cd /home/downloads/streams			# where we store stream-rips
logfile=.streamripper.txt			# where we log

# Prompt User for stream (mountpoint) to rip if not provided as agument on CLI:
if [ "$1" == "" ]
then
	iceweasel http://pub7.di.fm	&		# show the stream list
	echo -n "Mount Point?: ";read mountpoint	# request the mountpoint
	if [ "$mountpoint" == "" ]
	then
		mountpoint="di_ambient_aac"		# default mountpoint
	fi
else
	mountpoint="$1"				# mountpoint was provided as argument on CLI, use it
fi
stream=$(echo $mountpoint | sed 's/^\///g;s/\/$//g')	# trim leading+trailing slashes from user's copy-paste from webpage
/usr/bin/streamripper http://pub7.di.fm/$stream?$usernumber -r $relayport -R 0 --quiet -u "AudioAddict-di/3.2.0.3240 Android/5.1" |& tee -a $logfile &
sleep 6						# wait for stream connect
mplayer -loop 0 http://127.0.0.1:$relayport	# monitor stream-rip (OMG... commercials! EEK!)
exit $?						# exit the launch script

# our conventional way to terminate backgrounded / daemonized streamrippers,
# and tidy the streamrip directory, is a manual invocation of
#                       /usr/local/bin/rip_tidy
#  http://crystalfaeries.net/posix/bin/rip_tidy


syntax highlighted by Code2HTML, v. 0.9.1