优酷视频mplayer自动连播脚本
-
- 帖子: 1318
- 注册时间: 2005-09-13 4:56
- 系统: Ubuntu Jammy Jellyfi
优酷视频mplayer自动连播脚本
这个脚本使用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。 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]
与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。 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]
上次由 funicorn 在 2012-09-29 14:50,总共编辑 39 次。
- acer4740
- 帖子: 1405
- 注册时间: 2010-09-13 19:04
- 来自: 0xFF00EE
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
- nmsfan
- 帖子: 18958
- 注册时间: 2009-10-16 22:46
- 来自: finland
Re: 优酷视频mplayer自动连播脚本
我更喜欢flashblock…………当然,结果就反过来了
>>>>推Ubuntu 桌面培训~~<<<<
>>>>想加入/了解gimp汉化吗,点我吧~<<<<
——————————————————————
不推荐wubi,也不推荐你给别人推荐wubi…………
随心而为的感觉真好……
强推mayhem!!
强推ensiferum
>>>>想加入/了解gimp汉化吗,点我吧~<<<<
——————————————————————
不推荐wubi,也不推荐你给别人推荐wubi…………
随心而为的感觉真好……
强推mayhem!!
强推ensiferum
-
- 帖子: 224
- 注册时间: 2010-05-20 13:45
Re: 优酷视频mplayer自动连播脚本
不错 就是mplayer标题乱码!
- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: 优酷视频mplayer自动连播脚本
这个还不错,就是麻烦了点。。。
-
- 帖子: 211
- 注册时间: 2010-01-25 9:27
Re: 优酷视频mplayer自动连播脚本
恩 这个不错 flash太垃圾
-
- 帖子: 224
- 注册时间: 2010-05-20 13:45
Re: 优酷视频mplayer自动连播脚本

-
- 帖子: 1318
- 注册时间: 2005-09-13 4:56
- 系统: Ubuntu Jammy Jellyfi
Re: 优酷视频mplayer自动连播脚本
我的mplayer怎么不乱吗呢wykzly 写了:不错 就是mplayer标题乱码!
- momova
- 帖子: 3381
- 注册时间: 2007-07-11 21:43
- 系统: archlinux
- 来自: 东江边
- momova
- 帖子: 3381
- 注册时间: 2007-07-11 21:43
- 系统: archlinux
- 来自: 东江边
- bigsun
- 帖子: 301
- 注册时间: 2009-01-11 16:05
- 昊昊昊
- 帖子: 182
- 注册时间: 2011-08-22 21:22
- Ubuntu与Linux
- 帖子: 1211
- 注册时间: 2010-06-09 19:57
- hakie
- 帖子: 270
- 注册时间: 2008-04-30 12:14