优酷视频mplayer自动连播脚本

上网、浏览、聊天、下载等
回复
funicorn
帖子: 1318
注册时间: 2005-09-13 4:56
系统: Ubuntu Jammy Jellyfi

优酷视频mplayer自动连播脚本

#1

帖子 funicorn » 2011-09-12 9:47

这个脚本使用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]
附件
openwith.png
context-menu.png
mplayer-tudou.png
上次由 funicorn 在 2012-09-29 14:50,总共编辑 39 次。
头像
acer4740
帖子: 1405
注册时间: 2010-09-13 19:04
来自: 0xFF00EE

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

#2

帖子 acer4740 » 2011-09-12 9:58

支持,我也是刚发现这个网站
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

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

#3

帖子 eexpress » 2011-09-12 16:16

自动下载的,都发过,都没啥人用。
● 鸣学
头像
nmsfan
帖子: 18958
注册时间: 2009-10-16 22:46
来自: finland

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

#4

帖子 nmsfan » 2011-09-12 16:17

我更喜欢flashblock…………当然,结果就反过来了
>>>>推Ubuntu 桌面培训~~<<<<
>>>>想加入/了解gimp汉化吗,点我吧~<<<<
——————————————————————
不推荐wubi,也不推荐你给别人推荐wubi…………
随心而为的感觉真好……
强推mayhem!!
强推ensiferum
wykzly
帖子: 224
注册时间: 2010-05-20 13:45

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

#5

帖子 wykzly » 2011-09-12 17:37

不错 就是mplayer标题乱码!
头像
枫叶饭团
帖子: 14683
注册时间: 2010-06-16 1:05
系统: Mac OS X
来自: Tencent
联系:

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

#6

帖子 枫叶饭团 » 2011-09-12 17:46

这个还不错,就是麻烦了点。。。
flay
帖子: 211
注册时间: 2010-01-25 9:27

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

#7

帖子 flay » 2011-09-12 17:53

恩 这个不错 flash太垃圾
wykzly
帖子: 224
注册时间: 2010-05-20 13:45

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

#8

帖子 wykzly » 2011-09-13 10:14

:em11 好脚本。。
funicorn
帖子: 1318
注册时间: 2005-09-13 4:56
系统: Ubuntu Jammy Jellyfi

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

#9

帖子 funicorn » 2011-09-13 10:15

wykzly 写了:不错 就是mplayer标题乱码!
我的mplayer怎么不乱吗呢
screenshot.png
头像
momova
帖子: 3381
注册时间: 2007-07-11 21:43
系统: archlinux
来自: 东江边

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

#10

帖子 momova » 2011-09-13 16:35

我菜单没这个选项,扩展已经安装了,脚本也弄了
我来了,我看见了,我征服了!
求勾搭,不管饭。
头像
momova
帖子: 3381
注册时间: 2007-07-11 21:43
系统: archlinux
来自: 东江边

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

#11

帖子 momova » 2011-09-13 16:42

哦,自己弄错了。谢谢,搞定,的确是不错,比那什么玩意要好多了。
我来了,我看见了,我征服了!
求勾搭,不管饭。
头像
bigsun
帖子: 301
注册时间: 2009-01-11 16:05

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

#12

帖子 bigsun » 2011-09-13 17:13

结合flashgot也能使用,我将脚本存成了flvcd.sh
附件
windowshot-2011-09-13.png
头像
昊昊昊
帖子: 182
注册时间: 2011-08-22 21:22

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

#13

帖子 昊昊昊 » 2011-09-13 17:21

mark ! :em11
▓   單 調   ▓
头像
Ubuntu与Linux
帖子: 1211
注册时间: 2010-06-09 19:57

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

#14

帖子 Ubuntu与Linux » 2011-09-13 17:47

wykzly 写了:不错 就是mplayer标题乱码!
我这里也是乱码。
PS.英文的gnome3
头像
hakie
帖子: 270
注册时间: 2008-04-30 12:14

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

#15

帖子 hakie » 2011-09-13 17:59

学习学习!
Archlinux+FVWM

虽然没技术折腾,但一直在默默折腾。
回复