51VOA音频下载

51voa.sh
#!/bin/bash
 
WEBSITE=http://www.51voa.com/VOA_Standard_English/
SAVEPATH=$HOME/Music/voa
 
COUNT=7
wget -q "$WEBSITE" -O /tmp/index.html
 
cuthtml(){
 
	LEFT=`grep "\"leftMainContainer\""  -n $1 | cut -d: -f1`
	RIGHT=`grep "\"content\"" -n $1 | cut -d: -f1`
	if [ ! -z $LEFT ];then
		let "LEN = RIGHT - LEFT "
		echo "cuthtml:left"$LEFT,right=$RIGHT,len=$LEN
		ex $1 <<1xxxx1
			:$LEFT
			:d $LEN
			:wq
1xxxx1
	fi	
}
 
 
for MYPATH in `grep "/VOA[_a-zA-Z]*/[a-zA-Z.0-9-]*html" /tmp/index.html -o`
do
	let "COUNT -= 1"
 
	if [ $COUNT -lt 0 ]
	then
		break
	fi
 
	DIR=`echo $MYPATH | grep "VOA[_a-zA-Z]*" -o`
	DIR=$SAVEPATH/$DIR
	if [ ! -d  $DIR ];then
		mkdir -p $DIR
	fi
	NAME=`echo $MYPATH  | sed "s/\/.*\///"`
	if [ ! -e $DIR/$NAME ];then
		wget -q $WEBSITE$MYPATH -O $DIR/$NAME
		echo wget:$NAME
	fi
	NEXT=`grep /[0-9]*/.*mp3 $DIR/$NAME -o | grep -v "<"`
	PRE="http://www.51voa.com/path.asp?url="
	TOTAL=$PRE$NEXT
	if [ ! -e $SAVEPATH$MYPATH.mp3 ];then
		wget -q "$TOTAL" -O $SAVEPATH$MYPATH.mp3
		echo wget:$TOTAL
	fi
	cuthtml $DIR/$NAME
done