分页: 1 / 9

优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 9:47
funicorn
这个脚本使用http://www.flvcd.com的视频地址解析,直接在mplayer中播放flash视频,避开linux下丑恶的adobe flash player。本脚本原则上对包括优酷在内的flvcd支持的大部分网站适用,欢迎测试。

与firefox配合使用方法:将代码保存为可执行文件vsplay,安装flashgot扩展,首选项添加下载器,"vsplay",参数里写入 '[action] [fmt]',action可以是play|dump|test|usage中的 ... 840]perl脚本。)[/size]

2012.09.05,增加清晰度选择。可以在运行脚本时手动指定一个清晰度,也可以让脚本去找源里所有的版本,然后再选定需要的版本。如果已经手动指定了清晰度,脚本就不再提示选择了。在选择对话框中,如果选择“当前值”,那么会按照flvcd默认的地址播放,似乎默认的都是normal,也就是260P,不确定是否如此。

使用方法跟之前有所区别,见代码头部的说明。

2012.09.09 最终版。代码在下面的附件中。修改了参数设定,修正了几处小错误。使用firefox扩展dragit,可以直接拖动链接并使用vsp播放,避免使用flashgot。此版为最终版,以后不再更新。有时间的话,可能考虑使用perl重写此代码,那样将不必依赖flvcd。
vsp.gz
vsp
(4.29 KiB) 已下载 290 次
2012.09.20 flvcd开始支持ppstream和讯雷看看了,这真是个好消息

注:这个脚本原则上只供Ubuntu中文论坛上的网友测试使用,请尽量避免过度使用。习惯下载的朋友请不要使用多线程工具,如果视频网站发飙,封杀是很容易的。

[bash]
#!/bin/bash
# Thanks to http://www.flvcd.com

# usage: vsplay [play|dump|test] [url] [fmt]
# One can [test] this script with certain url to make it work better

# example: vsplay play http://v.youku.com/v_show/id_XMzAwMjI3MDI0.html

# fmt could be: 'normal', 'high', 'super', 'super2' or 'real'(without the quotation mark),
# denoting 260p, 360p, 480p, 720p and the original image respectively, yet depending on the stream source.
# Leaving it blank leads to the default video quality provided by flvcd.

Preset(){

_P26=$(sed -n '/260P版解析/p' "/tmp/dump" |sed 's/<a href="*//g' |sed 's/"><font color="red"><B>260P版解析<\/B><\/font><\/a>//g' |sed 's/^[ ]*//g')
_P36=$(sed -n '/360P版解析/p' "/tmp/dump" |sed 's/<a href="*//g' |sed 's/"><font color="red"><B>360P版解析<\/B><\/font><\/a>//g' |sed 's/^[ ]*//g')
_P48=$(sed -n '/480P版解析/p' "/tmp/dump" |sed 's/<a href="*//g' |sed 's/"><font color="red"><B>480P版解析<\/B><\/font><\/a>//g' |sed 's/^[ ]*//g')
_P72=$(sed -n '/720P版解析/p' "/tmp/dump" |sed 's/<a href="*//g' |sed 's/"><font color="red"><B>720P版解析<\/B><\/font><\/a>//g' |sed 's/^[ ]*//g')
_P00=$(sed -n '/原画版解析/p' "/tmp/dump" |sed 's/<a href="*//g' |sed 's/"><font color="red"><B>原画版解析<\/B><\/font><\/a>//g' |sed 's/^[ ]*//g')

[ -n "${_P26}" ] && _fmt0="FALSE 260P"
[ -n "${_P36}" ] && _fmt1="TRUE 360P"
[ -n "${_P48}" ] && _fmt2="FALSE 480P"
[ -n "${_P72}" ] && _fmt3="FALSE 720P"
[ -n "${_P00}" ] && _fmt4="FALSE 原画"

}

get_url() {
sed -ne 's/^<U>//p' /tmp/dump >/tmp/url

if echo "$wurl" |grep "tv.sohu.com" >/dev/null ; then
sed -i 's/^.*&new=/http:\/\/newflv.sohu.ccgslb.net/g' /tmp/url
fi
}

get_title() {
sed -ne 's/^<N>//p' /tmp/dump >/tmp/title
}

make_playlist() {

mkdir -p /tmp/playlists
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
sed -i "1i#EXTM3U" /tmp/url
mv /tmp/url "/tmp/playlists/${title}.m3u"
}


# script to play the stream
play() {
notify-send "playing ${title}"
if [ -s "/tmp/playlists/${title}.m3u" ]; then
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title}.m3u" -title "${title}"
elif [ -s /tmp/url ]; then
mv /tmp/url "/tmp/playlists/${title-dump}.url" # in case title is null.
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title-dump}.url" -title "${title}"
fi
}

# script to download the stream
dump(){

mkdir -p "$HOME/Videos/${title-dump}"

for ((i=1; i<=$u_length; i++))
do
uri=$(sed -n "$i p" /tmp/url)
if pgrep notify-osd |grep '[0-9]'>/dev/null
then
killall notify-osd
fi
notify-send "dumping ${title-dump}-$i of $u_length"
wget -c -U "$UA" -O "$HOME/Videos/${title-dump}/${title-dump}-$i" "$uri"
done

if [ $u_length -eq 1 ]; then
mv "$HOME/Videos/${title-dump}/${title-dump}-1" "$HOME/Videos/${title-dump}/${title-dump}"
fi

}


# ==============================================
# =========== work starts here =================
# ==============================================
case "$1" in
usage)
notify-send "Usage:" "vsplay [play|dump|test|usage] [url] [normal|high|super|real]" && exit 0
;;
esac

if [[ "$1" != "play" && "$1" != "dump" && "$1" != "test" ]] ; then
notify-send "Obsolute action designated." "Usage: vsplay [action] [url] [fmt]" && exit 1
fi

wurl=$(urlencode "$2") # target url
fmt=$3 # video format
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" # fake user-agent
parser="http://www.flvcd.com/parse.php?flag=&fo ... CA%BCGO%21" # flvcd default


if ! wget $parser -q -U "$UA" -O /tmp/dump; then
notify-send "cannot parser, exit"
exit 0
else iconv -f gbk -t utf-8 /tmp/dump -o /tmp/dump
fi

if [ -z "$3"] ; then

Preset

if [[ -n "${_fmt0}" || -n "${_fmt1}" || -n "${_fmt2}" || -n "${_fmt3}" || -n "${_fmt4}" ]]; then

qual=$(zenity --text="选择要使用的视频格式" --title="" --list --cancel-label 当前值 --ok-label 选定值 --hide-header --radiolist --column "" --column "" ${_fmt0} ${_fmt1} ${_fmt2} ${_fmt3} ${_fmt4})

[ "$qual" = "260P" ] && fmt=normal
[ "$qual" = "360P" ] && fmt=high
[ "$qual" = "480P" ] && fmt=super
[ "$qual" = "720P" ] && fmt=super2
[ "$qual" = "原画" ] && fmt=real

fi
fi

if [ -n "$qual" ]; then
newparser="http://www.flvcd.com/parse.php?flag=&fo ... CA%BCGO%21"
wget $newparser -q -U "$UA" -O /tmp/dump
iconv -f gbk -t utf-8 /tmp/dump -o /tmp/dump
fi


get_url

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 [ $t_length -eq 1 ] ; then
title=$(cat /tmp/title)
elif [$t_length -gt 1]; then
title=$(sed -n '1s/-[0-9]\+$//'p /tmp/title)
fi


case "$1" in

play)

if [ $u_length -eq $t_length ]; then
make_playlist
else
notify-send "u_length and t_length not match, no playlist generated."
fi

if ! play ; then
echo "can not play, check the url's in /tmp/playlists"
exit 1
fi
;;

dump)

if ! dump ; then
echo "dump failed, check the url's in /tmp/url"
exit 1
fi
;;

test)

notify-send "OK" "$u_length url items, $t_length title items."
;;

esac

[/bash]

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 9:58
acer4740
支持,我也是刚发现这个网站

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 16:16
eexpress
自动下载的,都发过,都没啥人用。

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 16:17
nmsfan
我更喜欢flashblock…………当然,结果就反过来了

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 17:37
wykzly
不错 就是mplayer标题乱码!

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 17:46
枫叶饭团
这个还不错,就是麻烦了点。。。

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-12 17:53
flay
恩 这个不错 flash太垃圾

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 10:14
wykzly
:em11 好脚本。。

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 10:15
funicorn
wykzly 写了:不错 就是mplayer标题乱码!
我的mplayer怎么不乱吗呢
screenshot.png

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 16:35
momova
我菜单没这个选项,扩展已经安装了,脚本也弄了

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 16:42
momova
哦,自己弄错了。谢谢,搞定,的确是不错,比那什么玩意要好多了。

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 17:13
bigsun
结合flashgot也能使用,我将脚本存成了flvcd.sh

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 17:21
昊昊昊
mark ! :em11

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 17:47
Ubuntu与Linux
wykzly 写了:不错 就是mplayer标题乱码!
我这里也是乱码。
PS.英文的gnome3

Re: 优酷视频mplayer自动连播脚本

发表于 : 2011-09-13 17:59
hakie
学习学习!