Re: 优酷视频mplayer自动连播脚本
发表于 : 2011-10-05 22:28
原来mplayer给我弄挂了……,悲剧。我使用第一次,成功,然后按ctrl-c终端后就始终挂掉了,显示第四句出错,修改也没用,倒是生成了playlist.title,地址也正确,为什么就不能看啊。
原来mplayer给我弄挂了……,悲剧。我使用第一次,成功,然后按ctrl-c终端后就始终挂掉了,显示第四句出错,修改也没用,倒是生成了playlist.title,地址也正确,为什么就不能看啊。
代码: 全选
#!/bin/bash
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
wurl=$1
fmt=super
parser="http://www.flvcd.com/parse.php?flag=&format=$fmt&kw=$wurl&sbt=%BF%AA%CA%BCGO%21"
wget $parser -q -U "$UA" -O /tmp/dump
iconv -f gbk -t utf-8 /tmp/dump -o /tmp/dump
get_m3u() {
line=`cat /tmp/dump |wc -l`
m3u_start=`grep "m3u" /tmp/dump -n`
start_line=${m3u_start%%:*}
m3u_end=`grep "M3U" /tmp/dump -n`
end_line=${m3u_end%%:*}
cut_line=$(($line-$end_line+2))
tac /tmp/dump |sed -e "1,$cut_line d" |tac >/tmp/url
sed -i "1,$start_line d" /tmp/url
sed -i '/1/s/<input type="hidden" name="inf" value="//g' /tmp/url
}
get_url() {
grep "<U>" /tmp/dump > /tmp/url
sed -i 's/<U>//g' /tmp/url
}
get_title() {
grep "<N>" /tmp/dump >/tmp/title
sed -i 's/<N>//g' /tmp/title
file="`sed -n '1p' /tmp/title` "
file=$(echo $file|sed 's/.....$//')
}
get_playlist() {
for ((i=1; i<=$u_length; ++i))
do
ttl=`sed -n "$i p" /tmp/title`
sed -i "$((2*i-1)) i #EXTINF:PART $i in $u_length, $ttl" /tmp/url
done
mv /tmp/url /tmp/play.m3u
sed -i "1i#EXTM3U" /tmp/play.m3u
}
download() {
mkdir -p ~/Downloads/$file
if [ -s /tmp/play.m3u ]; then
cat /tmp/play.m3u|sed '/http/!d' > /tmp/playlist.title
rm /tmp/play.m3u
t=$(cat /tmp/playlist.title)
j=1
for i in $t
#notify-send "playing $file"
do
wget -U "$UA" $i -O ~/Downloads/$file/$file$j.flv
j=$((j+1))
done
elif [ -s /tmp/url ]; then
cat /tmp/url|sed '/http/!d' >/tmp/playlist
rm /tmp/url
t=$(cat /tmp/playlist)
j=1
for i in $t
#notify-send "playing $file"
do
wget -U "$UA" $i -O ~/Downloads/$file/$file$j.flv
j=$((j+1))
done
fi
}
if [ "`grep m3u /tmp/dump`" != "" ] ; then
get_m3u
else
get_url
fi
get_title
u_length=`cat /tmp/url |wc -l`
t_length=`cat /tmp/title |wc -l`
get_playlist
rm /tmp/title /tmp/dump
download
这个是flvcd.com网站解析视频真实地址错误导致的,没办法改。。杯具的5650 写了:挺好用的,但是不能播放土豆的视频,奇怪
代码: 全选
#!/bin/bash
#thanks http://www.flvcd.com
#example: vsplay http://v.youku.com/v_show/id_XMzAwMjI3MDI0.html
# fmt could be: 'normal', 'high', 'super' or 'real'(without the quotation mark), generally denoting 260p, 360p, 480p and the original image respectively, yet depending on the video source defaults though. Leaving it blank leads to the default video quality provided.
#wurl=$(urlencode "$1")
wurl=$1
fmt=super
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
parser="http://www.flvcd.com/parse.php?flag=&format=$fmt&kw=$wurl&sbt=%BF%AA%CA%BCGO%21"
get_m3u() {
line=`cat /tmp/dump |wc -l`
m3u_start=`grep "m3u" /tmp/dump -n`
start_line=${m3u_start%%:*}
m3u_end=`grep "M3U" /tmp/dump -n`
end_line=${m3u_end%%:*}
cut_line=$(($end_line-2))
sed "$cut_line,$ d" /tmp/dump >/tmp/url
sed -i "1,$start_line d" /tmp/url
sed -i '/1/s/<input type="hidden" name="inf" value="//g' /tmp/url
}
get_url() {
grep "<U>" /tmp/dump > /tmp/url
sed -i 's/<U>//g' /tmp/url
}
get_title() {
grep "<N>" /tmp/dump >/tmp/title
sed -i 's/<N>//g' /tmp/title
file="`sed -n '1p' /tmp/title`"
}
get_playlist() {
for ((i=1; i<=$u_length; ++i))
do
ttl=`sed -n "$i p" /tmp/title`
sed -i "$((2*i-1)) i #EXTINF:PART $i in $u_length, $ttl" /tmp/url
done
mv /tmp/url /tmp/play.m3u
sed -i "1i#EXTM3U" /tmp/play.m3u
}
play() {
if [ -s /tmp/play.m3u ]; then
notify-send "playing $file"
vlc /tmp/play.m3u
elif [ -s /tmp/url ]; then
vlc -playlist /tmp/play
fi
}
if ! wget $parser -q -U "$UA" -O /tmp/dump; then
notify-send "cannot get parser, exit"
exit 0
fi
iconv -f gbk -t utf-8 /tmp/dump -o /tmp/dump
if [ "`grep m3u /tmp/dump`" != "" ] ; then
get_m3u
else
get_url
fi
get_title
u_length=`cat /tmp/url |wc -l`
t_length=`cat /tmp/title |wc -l`
if [ $u_length -eq 0 ]; then
notify-send "stream url is null, exit"
exit 0
fi
if [ $u_length -eq $t_length ]; then
get_playlist
else
notify-send "u_length and t_length not match, generated with no titles. "
fi
rm /tmp/title /tmp/dump
if ! play ; then
echo "can not play, check the url's in /tmp/playlist or /tmp/playlist.title"
fi