贴个带下载的吧,免得老有人问。注意使用方法有所变化:
vsplay [play|dump|test] [url] [format]
比如
然后打开~/Videos/看看
[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' or 'real'(without the quotation mark),
# denoting 260p, 360p, 4 80p and the original image respectively, yet depending on the stream source.
# Leaving it blank leads to the default video quality provided by flvcd.
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
get_url() {
sed -ne 's/^<U>//p' /tmp/dump >/tmp/url
}
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() {
if [ -s "/tmp/playlists/${title}.m3u" ]; then
notify-send "playing ${title}"
mplayer -user-agent "$UA" -playlist "/tmp/playlists/${title}.m3u" -title "${title}"
elif [ -s /tmp/url ]; then
notify-send "playing ${title}"
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"
mplayer -user-agent "$UA" -dumpstream -dumpfile "$HOME/Videos/${title-dump}/${title-dump}-$i" "$uri"
done
}
# ==============================================
# =========== work starts here =================
# ==============================================
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
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 -gt 0 ] ; then
title=$(sed -n '1p' /tmp/title |awk -F '[-]' '{print $1}')
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]