
也许有人看优酷电视剧或电影喜欢粤语版的,我贡献个自动转粤语的脚本:
~/.scripts/PlayFLV:
[bash]#!/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")
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
fmt=high
player="mplayer -playlist"
for parameter in "$@"; do
case "$parameter" in
normal|high|super|real)
fmt="$parameter"
;;
http*)
wurl="$parameter"
;;
mplayer)
player="mplayer -playlist"
;;
gnome-mplayer|gmplayer)
player="gnome-mplayer"
;;
vlc)
player="vlc"
;;
smplayer)
player="smplayer"
;;
yueyu|canton|cantonese)
cantonese=yes
;;
*)
other="$other $parameter"
;;
esac
done
parser="
http://www.flvcd.com/parse.php?flag=&kw ... CA%BCGO%21"
get_cantonese() {
canton=`sed -n '/>粤语版</ p' /tmp/dump`
if [ -n "$canton" ]; then
rm /tmp/dump
cantonurl=`echo $canton |sed 's/^.*http/http/; s/html.*$/html/'`
parser="
http://www.flvcd.com/parse.php?kw=$cant ... CA%BCGO%21"
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
fi
}
get_m3u() {
start_line=`sed -n '/m3u/=' /tmp/dump`
end_line=`sed -n '/M3U/=' /tmp/dump`
cut_line=$(($end_line-2))
sed -e "$cut_line,$ d" /tmp/dump > /tmp/playlist
sed -i "1,$start_line d" /tmp/playlist
sed -i 's/^.*http/http/g' /tmp/playlist
}
get_url() {
grep "<U>" /tmp/dump > /tmp/playlist
sed -i 's/<U>//g' /tmp/playlist
if [[ -n $(grep "<P>" /tmp/dump |sed -n '/搜狐/p') ]]; then
sed -i 's/^.*&new=/http:\/\/newflv.sohu.ccgslb.net/g' /tmp/playlist
fi
}
get_title() {
grep "<N>" /tmp/dump >/tmp/title
sed -i 's/<N>//g' /tmp/title
file="`sed 's/-0001//' /tmp/title |head -1`"
}
get_playlist() {
for ((i=1; i<=$u_length; ++i))
do
ttl="${file}-${i}/${u_length}"
sed -i "$((2*i-1)) i #EXTINF:PART $i in $u_length, $ttl" /tmp/playlist
done
mv /tmp/playlist /tmp/playlist.m3u
sed -i "1i#EXTM3U" /tmp/playlist.m3u
}
play() {
if [ -s /tmp/playlist.m3u ]; then
notify-send "playing $file"
$player /tmp/playlist.m3u $other
elif [ -s /tmp/playlist ]; then
$player /tmp/playlist $other
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 [[ $cantonese = "yes" ]]; then
get_cantonese
fi
if [[ "`grep m3u /tmp/dump`" != "" ]] ; then
get_m3u
else
get_url
fi
get_title
u_length=`cat /tmp/playlist |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.m3u or /tmp/playlist"
fi[/bash]
用法:~/.scripts/PlayFLV super smplayer yueyu 网址 -fullscreen ##用smplayer以超清模式全屏播放粤语版(如果有)视频。
支持smplayer、vlc、gnome-mplayer、mplayer,用vlc有标题,其它的没有标题,只有网址;但vlc暂停很久后会断开连接。
再贡献个播放优酷专辑的脚本:
~/.scripts/PlayAlbum
[bash]
#!/bin/bash
##这个脚本可以用来连续播放优酷的专辑,配合“mplayer自动连播脚本”一起使用,输入网址可以是专辑网址,也可以是专辑里的其中一个视频网址,如果是专辑网址,则从第一集开始播放,如果是某个视频网址,则从这个视频开始播放。
##电视剧是按集数顺序播放,综艺节目之类的可能是按日期从新往旧的播放(因为优酷是这样安排的),用户上传的专辑如果不止一页,会自动全部播放,不需要逐页执行。
##该脚本运行时会调用终端来打开,请将lxterminal改成您自己的终端(如gnome-terminal)
##
mkscript() {
cat << EOF
#!/bin/bash
##mplayer自动连播脚本的位置,脚本下载地址:
http://forum.ubuntu.org.cn/viewtopic.php?f=73&t=344921
playscript="\$HOME""/.scripts/PlayFLV"
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
format=high
if [ ! -e "\$playscript" ];then
notify-send "播放脚本不存在,请检查playscript的路径是否正确"
exit 0
fi
##处理输入的参数
for parameter in "\$@"; do
case "\$parameter" in
normal|high|super|real)
format="\$parameter"
;;
http*)
current="\$parameter"
;;
*)
other="\$other \$parameter"
;;
esac
done
##判断输入的网址的页面类型
is_album() {
if [[ \`echo \$listpage |sed -n '/show_page/p'\` ]]; then
pagetype="sp"
elif [[ \`echo \$listpage |sed -n '/playlist_show/p'\` ]]; then
pagetype="ps"
elif [[ \`echo \$listpage |sed -n '/v_show/p'\` ]]; then
pagetype=""
elif [[ \`echo \$listpage |sed -n '/user_playlist/p'\` ]]; then
pagetype="up"
else
notify-send "脚本不支持此页面或链接"
exit 0
fi
}
##下载视频所属的专辑页面,并返回专辑页面地址
get_listpage() {
sp=\`cat /tmp/currentpage |sed -n 's/^.*http/http/; s/html.*\$/html/; /show_page/p' |head -1\`
ps=\`cat /tmp/currentpage |sed -n 's/^.*http/http/; s/html.*\$/html/; /playlist_show/p' |head -1\`
up=\`cat /tmp/currentpage |sed -n 's/^.*http/http/; s/html.*\$/html/; /user_playlist/p' |head -1\`
if [ -n "\$sp" ]; then
wget \$sp -q -U "\$UA" -O /tmp/currentpage
listpage="\$sp"
elif [ -n "\$up" ]; then
wget \$up -q -U "\$UA" -O /tmp/currentpage
listpage="\$up"
elif [ -n "\$ps" ]; then
wget \$ps -q -U "\$UA" -O /tmp/currentpage
listpage="\$ps"
else
notify-send "无法获取专辑页面地址,可能该视频没有被收入任何专辑"
exit 0
fi
}
##根据专辑页面类型来生成视频网址列表
get_urllist() {
[ -e /tmp/urllist ] && rm /tmp/urllist
if [[ \$pagetype = "sp" ]]; then
sed -ne 's/^.*http/http/; /zy_bd/,/clear/ s/html.*\$/html/p' /tmp/currentpage > /tmp/urllist
elif [[ \$pagetype = "up" ]]; then
next=Y
while [ -n "\$next" ]; do
grep "PlaylistID" /tmp/currentpage |sed 's/html.*\$/html/; s/^.*http/http/' >> /tmp/urllist
post=\`sed -n '/"current"/=' /tmp/currentpage|head -1\`
post=\`expr \$post + 1\`
next=\`sed -n "\$post p" /tmp/currentpage |sed -n 's/^.*user/user/; s/html.*\$/html/p'\`
if [ -n "\$next" ]; then
wget
http://u.youku.com/\$next -q -U "\$UA" -O /tmp/currentpage
fi
done
elif [[ \$pagetype = "ps" ]]; then
next=Y
while [ -n "\$next" ];do
grep "v_link" /tmp/currentpage |sed 's/^.*http/http/; s/html.*\$/html/' >> /tmp/urllist
post=\`sed -n '/"current"/=' /tmp/currentpage|head -1\`
post=\`expr \$post + 1\`
next=\`sed -n "\$post p" /tmp/currentpage |sed -n 's/^.*http/http/; s/html.*\$/html/p'\`
if [ -n "\$next" ]; then
wget \$next -q -U "\$UA" -O /tmp/currentpage
fi
done
else
notify-send "无法获取视频网址列表 "
exit 0
fi
uniq /tmp/urllist > /tmp/urllist.temp
mv /tmp/urllist.temp /tmp/urllist
}
##计算输入的网址在专辑中的序号
get_num() {
id=\`echo "\$current" |sed 's/^.*\///; s/\.html.*\$//'\`
N=\`sed -ne "/\$id/=" /tmp/urllist\`
if [[ -z "\$N" ]];then
N=1
fi
}
##从当前页(或第1集)开始播放
play() {
n=\$(sed -n '\$=' /tmp/urllist)
j=\$N
for (( i=1; i<=n; i++ )); do
if (( i>=j )); then
videopage=\$(sed -n "\$i p" /tmp/urllist)
sh \$playscript \$videopage \$format \$other
fi
done
}
wget \$current -q -U "\$UA" -O /tmp/currentpage
listpage=\$current
is_album
if [[ -n \$pagetype ]]; then
get_urllist
N=1
play
else
get_listpage
is_album
get_urllist
get_num
play
fi
EOF
}
##将脚本写入临时文件里,以便用终端调用
[ -e /tmp/playalbum.sh ] && rm /tmp/playalbum.sh
mkscript > /tmp/playalbum.sh
chmod +x /tmp/playalbum.sh
##调用终端,方便终止脚本
(lxterminal -t "正在播放优酷专辑...不看时请关闭本窗口" --geometry=40x1 -e "/tmp/playalbum.sh $*") &
exit
[/bash]
用法:~/.scripts/PlayAlbum smplayer super 网址 -close-at-end -fullscreen ##用smplayer以超清模式全屏播放优酷专辑,播完一集自动播下一集。
7月30日优化了脚本,参数位置可以任意变换,自动识别画质、网址,可选择是否播放粤语;
可以在参数中选择播放器(默认mplayer,可以用gmplayer,smplay,vlc,其它的自己加上),可添加播放器控制参数;
播放专辑时,推荐添加全屏选项和自动退出选项
8月10日更新:将原来播放专辑的两个脚本合并成一个。其实用了一个很猥琐的方法。
8月16日顺应潮流,添加了搜狐视频支持。其实只需要在get_url函数的最后加上代码: 全选
if [[ -n $(grep "<P>" /tmp/dump |sed -n '/搜狐/p') ]]; then
sed -i 's/^.*&new=/http:\/\/newflv.sohu.ccgslb.net/g' /tmp/url
fi
就可以让脚本支持搜狐视频了,不用另外写一大堆代码的。[/color] [/size]