优酷视频mplayer自动连播脚本
- widon1104
- 帖子: 846
- 注册时间: 2008-07-17 10:55
Re: 优酷视频mplayer自动连播脚本
脚本不能用了,谁来修复一下啊
- rapistor
- 帖子: 1983
- 注册时间: 2009-01-19 15:09
- rapistor
- 帖子: 1983
- 注册时间: 2009-01-19 15:09
- chenjietao
- 帖子: 130
- 注册时间: 2010-09-21 1:50
Re: 优酷视频mplayer自动连播脚本
现在flvcd的页面源代码有改动,以前的脚本要改一下才能用。我来给个参考。
首先是获取视频地址(即get_url),搜狐解析不了,暂时无法解决,其它网站获取视频地址的代码为:
其次,如今已经没有分标题,只有视频的总标题。所以/tmp/title和参数t_length也没用。
获取标题的代码:
对应的制作m3u列表的一些代码也需要做些调整。
最后,一些网址如优酷是没有360P、480P之分的,只有高清、超清之分,所以我觉得1楼的一些代码不妥。
而且有些人用的KDE桌面,若安装zenity就显得蛋疼了,我给个kdialog的相似代码吧:
[bash]
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="normal 流畅 off" # normal画质是所有视频都有的
[ $_high -ne 0 ] && _fmt1="high 高清 on"
[ $_super -ne 0 ] && _fmt2="super 超清 off"
[ $_super2 -ne 0 ] && _fmt3="super2 720P off"
[ $_real -ne 0 ] && _fmt4="real 原画 off"
if [[ -n "${_fmt1}" || -n "${_fmt2}" || -n "${_fmt3}" || -n "${_fmt4}" ]]; then
# kdialog --radiolist <test> [tag item status] 返回tag值
qual=$(kdialog --radiolist "选择要使用的视频格式" ${_fmt0} ${_fmt1} ${_fmt2} ${_fmt3} ${_fmt4} )
fmt="$qual"
else
fmt=normal
fi[/bash]
首先是获取视频地址(即get_url),搜狐解析不了,暂时无法解决,其它网站获取视频地址的代码为:
代码: 全选
sed -ne 's/^.*href="//;/onclick/ s/" target.*$//p' /tmp/dump >/tmp/url
获取标题的代码:
代码: 全选
title="$(sed -ne 's/" + ".*$//; /document\.title/ s/^.*"//p' /tmp/dump)"
最后,一些网址如优酷是没有360P、480P之分的,只有高清、超清之分,所以我觉得1楼的一些代码不妥。
而且有些人用的KDE桌面,若安装zenity就显得蛋疼了,我给个kdialog的相似代码吧:
[bash]
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="normal 流畅 off" # normal画质是所有视频都有的
[ $_high -ne 0 ] && _fmt1="high 高清 on"
[ $_super -ne 0 ] && _fmt2="super 超清 off"
[ $_super2 -ne 0 ] && _fmt3="super2 720P off"
[ $_real -ne 0 ] && _fmt4="real 原画 off"
if [[ -n "${_fmt1}" || -n "${_fmt2}" || -n "${_fmt3}" || -n "${_fmt4}" ]]; then
# kdialog --radiolist <test> [tag item status] 返回tag值
qual=$(kdialog --radiolist "选择要使用的视频格式" ${_fmt0} ${_fmt1} ${_fmt2} ${_fmt3} ${_fmt4} )
fmt="$qual"
else
fmt=normal
fi[/bash]
- chenjietao
- 帖子: 130
- 注册时间: 2010-09-21 1:50
Re: 优酷视频mplayer自动连播脚本
贴一个根据1楼改的代码,支持kdialog,使用vlc播放(并支持土豆视频)。
[bash]#!/bin/bash
# Thanks to http://www.flvcd.com
# usage: vsplay [play|dump] [url] [fmt]
# 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.
PresetGTK() {
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="FALSE 流畅"
[ $_high -ne 0 ] && _fmt1="TRUE 高清"
[ $_super -ne 0 ] && _fmt2="FALSE 超清"
[ $_super2 -ne 0 ] && _fmt3="FALSE 720P"
[ $_real -ne 0 ] && _fmt4="FALSE 原画"
if [[ -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" = "流畅" ] && fmt=normal
[ "$qual" = "高清" ] && fmt=high
[ "$qual" = "超清" ] && fmt=super
[ "$qual" = "720P" ] && fmt=super2
[ "$qual" = "原画" ] && fmt=real
get_page
fi
}
PresetQT() {
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="normal 流畅"
[ $_high -ne 0 ] && _fmt1="high 高清"
[ $_super -ne 0 ] && _fmt2="super 超清"
[ $_super2 -ne 0 ] && _fmt3="super2 720P"
[ $_real -ne 0 ] && _fmt4="real 原画"
if [[ -n "${_fmt1}" || -n "${_fmt2}" || -n "${_fmt3}" || -n "${_fmt4}" ]]; then
qual=$(kdialog --menu "选择要使用的视频格式" ${_fmt0} ${_fmt1} ${_fmt2} ${_fmt3} ${_fmt4} )
fmt="$qual"
get_page
fi
}
# download the page and convert to utf-8
get_page() {
parser="http://www.flvcd.com/parse.php?flag=&fo ... CA%BCGO%21"
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
}
# get the video's urls and its title name
get_url() {
sed -ne 's/^.*href="//;/onclick/ s/" target.*$//p;/class="link"/ s/" target.*$//p' /tmp/dump >/tmp/url
title="$(sed -ne 's/" + ".*$//; /document\.title/ s/^.*"//p' /tmp/dump)"
u_length=$(cat /tmp/url |wc -l)
if [ $u_length -eq 0 ]; then
notify-send "stream url is null, exit"
exit 0
fi
}
# make an m3u playlist
make_playlist() {
mkdir -p /tmp/playlists
for ((i=1; i<=$u_length; ++i))
do
sed -i "$((2*i-1)) i #EXTINF:PART $i in $u_length, ${title}-$i" /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
if [ -x /usr/bin/vlc ]; then
vlc "/tmp/playlists/${title}.m3u" 2>/dev/null
else
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title}.m3u" -title "${title}"
fi
elif [ -s /tmp/url ]; then
mv /tmp/url "/tmp/playlists/${title-dump}.url" # in case title is null.
if [ -x /usr/bin/vlc ]; then
vlc "/tmp/playlists/${title-dump}.url" 2>/dev/null
else
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title-dump}.url" -title "${title}"
fi
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 =================
# ==============================================
if [ -x /usr/bin/vlc ]; then
vlcver=$(vlc --version |sed -n '/VLC/ s/^.* \([0-9.]\+\) .*$/\1/p')
UA="VLC/$vlcver LibVLC/$vlcver"
else
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
fi
for parameter in "$@"; do
case "$parameter" in
normal|high|super|super2|real)
fmt="$parameter"
;;
play|dump)
action="$parameter"
;;
http*)
wurl="$(echo $parameter |sed 's/\//%2F/g; s/:/%3A/g')"
;;
usage|*)
notify-send "Usage:" "vsplay [play|dump|usage] [url] [normal|high|super|super2|real]" && exit 0
;;
esac
done
if [ -z "$action" ] ; then
notify-send "Obsolute action designated." "Usage: vsplay [action] [url] [fmt]" && exit 1
fi
get_page
if [ -z "$fmt" ]; then
if [ -x /usr/bin/kdialog ]; then
PresetQT
elif [ -x /usr/bin/zenity ]; then
PresetGTK
fi
fi
get_url
if [ "$action" = "play" ]; then
make_playlist
if ! play ; then
notify-send "can not play, check the url's in /tmp/playlists"
exit 1
fi
elif [ "$action" = "dump" ]; then
if ! dump ; then
notify-send "dump failed, check the url's in /tmp/url"
exit 1
fi
fi
[/bash]
[bash]#!/bin/bash
# Thanks to http://www.flvcd.com
# usage: vsplay [play|dump] [url] [fmt]
# 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.
PresetGTK() {
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="FALSE 流畅"
[ $_high -ne 0 ] && _fmt1="TRUE 高清"
[ $_super -ne 0 ] && _fmt2="FALSE 超清"
[ $_super2 -ne 0 ] && _fmt3="FALSE 720P"
[ $_real -ne 0 ] && _fmt4="FALSE 原画"
if [[ -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" = "流畅" ] && fmt=normal
[ "$qual" = "高清" ] && fmt=high
[ "$qual" = "超清" ] && fmt=super
[ "$qual" = "720P" ] && fmt=super2
[ "$qual" = "原画" ] && fmt=real
get_page
fi
}
PresetQT() {
_high=$(grep "\bformat=high\b" /tmp/dump |wc -l)
_super=$(grep "\bformat=super\b" /tmp/dump |wc -l)
_super2=$(grep "\bformat=super2\b" /tmp/dump |wc -l)
_real=$(grep "\bformat=real\b" /tmp/dump |wc -l)
_fmt0="normal 流畅"
[ $_high -ne 0 ] && _fmt1="high 高清"
[ $_super -ne 0 ] && _fmt2="super 超清"
[ $_super2 -ne 0 ] && _fmt3="super2 720P"
[ $_real -ne 0 ] && _fmt4="real 原画"
if [[ -n "${_fmt1}" || -n "${_fmt2}" || -n "${_fmt3}" || -n "${_fmt4}" ]]; then
qual=$(kdialog --menu "选择要使用的视频格式" ${_fmt0} ${_fmt1} ${_fmt2} ${_fmt3} ${_fmt4} )
fmt="$qual"
get_page
fi
}
# download the page and convert to utf-8
get_page() {
parser="http://www.flvcd.com/parse.php?flag=&fo ... CA%BCGO%21"
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
}
# get the video's urls and its title name
get_url() {
sed -ne 's/^.*href="//;/onclick/ s/" target.*$//p;/class="link"/ s/" target.*$//p' /tmp/dump >/tmp/url
title="$(sed -ne 's/" + ".*$//; /document\.title/ s/^.*"//p' /tmp/dump)"
u_length=$(cat /tmp/url |wc -l)
if [ $u_length -eq 0 ]; then
notify-send "stream url is null, exit"
exit 0
fi
}
# make an m3u playlist
make_playlist() {
mkdir -p /tmp/playlists
for ((i=1; i<=$u_length; ++i))
do
sed -i "$((2*i-1)) i #EXTINF:PART $i in $u_length, ${title}-$i" /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
if [ -x /usr/bin/vlc ]; then
vlc "/tmp/playlists/${title}.m3u" 2>/dev/null
else
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title}.m3u" -title "${title}"
fi
elif [ -s /tmp/url ]; then
mv /tmp/url "/tmp/playlists/${title-dump}.url" # in case title is null.
if [ -x /usr/bin/vlc ]; then
vlc "/tmp/playlists/${title-dump}.url" 2>/dev/null
else
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title-dump}.url" -title "${title}"
fi
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 =================
# ==============================================
if [ -x /usr/bin/vlc ]; then
vlcver=$(vlc --version |sed -n '/VLC/ s/^.* \([0-9.]\+\) .*$/\1/p')
UA="VLC/$vlcver LibVLC/$vlcver"
else
UA="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
fi
for parameter in "$@"; do
case "$parameter" in
normal|high|super|super2|real)
fmt="$parameter"
;;
play|dump)
action="$parameter"
;;
http*)
wurl="$(echo $parameter |sed 's/\//%2F/g; s/:/%3A/g')"
;;
usage|*)
notify-send "Usage:" "vsplay [play|dump|usage] [url] [normal|high|super|super2|real]" && exit 0
;;
esac
done
if [ -z "$action" ] ; then
notify-send "Obsolute action designated." "Usage: vsplay [action] [url] [fmt]" && exit 1
fi
get_page
if [ -z "$fmt" ]; then
if [ -x /usr/bin/kdialog ]; then
PresetQT
elif [ -x /usr/bin/zenity ]; then
PresetGTK
fi
fi
get_url
if [ "$action" = "play" ]; then
make_playlist
if ! play ; then
notify-send "can not play, check the url's in /tmp/playlists"
exit 1
fi
elif [ "$action" = "dump" ]; then
if ! dump ; then
notify-send "dump failed, check the url's in /tmp/url"
exit 1
fi
fi
[/bash]
-
- 帖子: 3
- 注册时间: 2012-06-04 18:08
Re: 优酷视频mplayer自动连播脚本
我来挖挖坟,原来的脚本title失效了,可以改get title为
sed -ne 's/" + ".*$//; /document\.title/ s/^.*"//p' /tmp/dump >/tmp/title
sed -ne 's/" + ".*$//; /document\.title/ s/^.*"//p' /tmp/dump >/tmp/title