我先分享一个ubuntu12.04 自动下载网页视频+合并的脚本
用法很简单,只要 download url就可以了,脚本写了,最好放在自己的一个单独的文件夹下,比如在~下建立一个mysh目录,并把mysh加到PATH中,在~/.bashrc中添加就可以了(PATH=$PATH:~/mysh)
代码: 全选
#!/bin/bash
if [ $# -ne 1 ] #检测参数数量
then
echo "Usage: $0 URL"
exit 1
fi
temf=`tempfile`
url="http://www.flvcd.com/parse.php?flag=&format=&kw="`echo $1 |sed -e 's/\//%2F/g' -e 's/:/%3A/g'`"&sbt=%BF%AA%CA%BCGO%21" #转换输入url到最后访问时需要用到的url
wget -U "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" "$url" -O "$temf" #取得访问页面的html代码
cat "$temf" |iconv -f gb18030 -t utf-8 | grep -q '高清版解析'
if [ $? -eq 0 ]
then
url=`echo $url |sed 's/flag=/flag=one/' |sed 's/format=/format=high/'`
wget -U "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" "$url" -O "$temf"
fi
cat "$temf" |iconv -f gb18030 -t utf-8 |grep -q '超清版解析'
if [ $? -eq 0 ]
then
url=`echo $url |sed 's/format=high/format=super/'`
wget -U "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" "$url" -O "$temf"
fi
title=`cat $temf | iconv -f gb18030 -t utf-8 |grep '(请用右键"目标另存为"或硕鼠来快速下载.)' | awk '{print $1}'`
links=`cat $temf | iconv -f gb18030 -t utf-8 | sed -n '/<input type="hidden" name="inf" value="/p' |grep -o 'http:.*' |tr \| ' ' |sed 's/".*//'`
echo $title
echo $links
i=0
for line in $links #把所有链接下载下来,存在/tmp目录下,下次开机自动删除
do
templist[$i]=`tempfile`
wget -c -U "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" `echo $line |sed 's/\r//'` -O ${templist[$i]}
((i++))
done
j=0
cmd="mencoder -oac mp3lame -ovc copy -idx"
while [ $j -ne $i ] #拼接所有下载的视频片段
do
cmd=$cmd" ${templist[$j]}"
((j++))
done
$cmd -o "$title.mp4"