Jan 5
大家都知道,网页上的视频都分段存储的,要想下载,就必须分析网页地址,多麻烦啊!
现在好了,我在网上查到一个工具downflv,可以下载完整的下载网页中的视频,呵呵,和大家分享一下代码:
#!/bin/bash
################################################################
# $ID: playflv Tue, 28 Apr 2009 16:34:13 +0800 mhfan $ #
# #
# Copyright (c) 2009 HHTech Co., Ltd. #
# All rights reserved. #
# #
# Last modified: Sun, 31 May 2009 14:53:16 +0800 by mhfan #
################################################################
if [ ! $# -eq 2 ] ; then
echo "Usage: $0 flvurl flvfname"
exit -1
fi
USER_AGENT="Mozilla/4.0"
download () {
DLPROG="wget -U $USER_AGENT"
if [ -n "$2" ] ; then
DLPROG="$DLPROG -O $2"
else
DLPROG="$DLPROG --timeout=15 --quiet -O -"
fi
$DLPROG $1
}
parseurl () {
URL_PARSER="http://www.flvcd.com/parse.php?flag=&format=&kw="
#echo "URL Parser: $URL_PARSER";
#echo "Parsing: $1";
download "$URL_PARSER$1" | grep "^<U>" | cut -d\> -f2
}
downflv () {
local FULLNAME BASE EXT IDX SAVEFILE
FULLNAME=$2
BASE=${FULLNAME%.*}
EXT=${FULLNAME##*.}
IDX=0
parseurl $1 | \
{ \
while read DLURL; do
IDX=$(($IDX + 1))
SAVEFILE=${BASE}-$(printf "%03d" ${IDX}).${EXT}
echo "Downloading : $DLURL";
echo "Save as file: $SAVEFILE"
download $DLURL $SAVEFILE
if [ ! $? -eq 0 ] ; then
echo "Download failed!"
break
fi
done
if [ $IDX -eq "0" ]; then
echo "Sorry, Couldn't found any video in this page";
fi
}
}
#parseurl $1
downflv $1 $2
################### End Of File: downflv ###################
# vim:sts=4:ts=8:
################################################################
# $ID: playflv Tue, 28 Apr 2009 16:34:13 +0800 mhfan $ #
# #
# Copyright (c) 2009 HHTech Co., Ltd. #
# All rights reserved. #
# #
# Last modified: Sun, 31 May 2009 14:53:16 +0800 by mhfan #
################################################################
if [ ! $# -eq 2 ] ; then
echo "Usage: $0 flvurl flvfname"
exit -1
fi
USER_AGENT="Mozilla/4.0"
download () {
DLPROG="wget -U $USER_AGENT"
if [ -n "$2" ] ; then
DLPROG="$DLPROG -O $2"
else
DLPROG="$DLPROG --timeout=15 --quiet -O -"
fi
$DLPROG $1
}
parseurl () {
URL_PARSER="http://www.flvcd.com/parse.php?flag=&format=&kw="
#echo "URL Parser: $URL_PARSER";
#echo "Parsing: $1";
download "$URL_PARSER$1" | grep "^<U>" | cut -d\> -f2
}
downflv () {
local FULLNAME BASE EXT IDX SAVEFILE
FULLNAME=$2
BASE=${FULLNAME%.*}
EXT=${FULLNAME##*.}
IDX=0
parseurl $1 | \
{ \
while read DLURL; do
IDX=$(($IDX + 1))
SAVEFILE=${BASE}-$(printf "%03d" ${IDX}).${EXT}
echo "Downloading : $DLURL";
echo "Save as file: $SAVEFILE"
download $DLURL $SAVEFILE
if [ ! $? -eq 0 ] ; then
echo "Download failed!"
break
fi
done
if [ $IDX -eq "0" ]; then
echo "Sorry, Couldn't found any video in this page";
fi
}
}
#parseurl $1
downflv $1 $2
################### End Of File: downflv ###################
# vim:sts=4:ts=8:
保存为downflv
在终端运行:
# ./downflv [URL] [filename]
例如:
# ./downflv http://v.youku.com/v_show/id_XMTQzMjQ2NTAw.html 嘻哈4重奏第二季07.flv
就OK了!!