解釋YOUTUBE FLV 地址
http://kej.tw/flvretriever/
|
|
|
|
|
|
| flvdown.sh for downloading flv video from YouTube. |
|
|
在網上看到可以通過 www.youtube.com/get_video.php 下載 youtube 的 flv 動畫, 於是嘗試寫了個指令碼實現:
#!/bin/bash
#
# @Function:
# download flv from www.youtube.com
#
# @HOW-TO:
# E.G.
# flvdown.sh http://www.youtube.com/watch?v=1eOu-jVuuxo
#
# @Author:
# HenryFour
# @Date:
# 2008-01-08
#
how_to() {
echo "Usage:"
echo " flvdown.sh youtube_video"
echo "E.G. flvdown.sh http://www.youtube.com/watch?v=1eOu-jVuuxo"
echo ""
}
downflv_exit() {
EXIT_CODE=$1
tmp_file_name=$2
if [ -f "$tmp_file_name" ]; then
rm -f "$tmp_file_name"
fi
exit $EXIT_CODE
}
WGET="/usr/bin/wget -c "
downflv_main() {
flvaddr=$1
#check whether it is youtube web address
if !(echo $flvaddr | /bin/egrep -q 'www[1-7]?.youtube.com/watch"?v=');
then
echo "addr invalid: flvdown.sh can just download youtube vidow."
exit 1
fi
#get the video page down
webfilename="${flvaddr#*watch?v=}.$(/bin/date '+%F-%s').tube4"
if ! $WGET -O "$webfilename" "$flvaddr"; then
echo "Failed to download page: $flvaddr"
downflv_exit 1 "$webfilename"
fi
#get video info from the webfile
video_title=$(/bin/grep '<title>.*</title>' "$webfilename" | sed 's/^"s*<title>"s*"([^"s]"+.*[^"s]"+")"s*<"/title>"s*$/"1/')
video_id=$(/bin/grep 'fullscreen' "$webfilename" | sed 's/.*fullscreen?video_id="(.*");$/"1/')
video_id=${video_id%"'}
video_file_name="$video_title".flv
if [ -f "video_file_name" ]; then
video_file_name="$video_title"-$(/bin/date '+%F-%s').flv
fi
video_down_addr="http://www.youtube.com/get_video.php?video_id=$video_id"
#download flv video
if ! $WGET -O "$video_file_name" "$video_down_addr"; then
echo 'Failed to download flv video'
downflv_exit 1 "$webfilename"
fi
echo "download flv vedio: $video_file_name"
downflv_exit 0 "$webfilename"
}
if [ $# -ne 1 ]; then
how_to
exit 1
else
downflv_main $1
fi
|
|
|
|
其他一種
當我看到這個Shell Script的時候,我在想 YouTube 的下載方式又多了一種
而寫這一個 Shell Script 的作者對 Script 及 YouTube 也很熟悉
我看了他的 Shell Script 原碼後,是利用 Linux 的 wget 下載 YouTube 的影片
其原始 Shell Script 碼如下:
#!/bin/sh
# $Id: youtube.sh 496 2006-06-05 23:37:35Z berto $
if [ "$#" != "1" ]; then
echo "YouTube Video Downloader"
echo "Written by Alberto Garcia <agarcia-at-igalia-com>"
echo "Homepage: http://people.igalia.com/berto/"
echo
echo "Usage:"
echo " youtube.sh http://www.youtube.com/watch?v=<video_ID>"
echo " or"
echo " youtube.sh <video_ID>"
echo
exit 64
fi
VID=$(echo "$1"|sed "s/.*v="([^&]*").*/"1/")
URL1="http://www.youtube.com/watch?v=$VID"
echo -n "Getting $URL1 ..."
PARAM="$(wget -q -O - "$URL1"|grep watch_fullscreen|cut -d '&' -f 3)"
echo " done."
URL2="http://www.youtube.com/get_video?video_id=$VID&$PARAM"
echo -n "Getting $URL2 ..."
URL3="$(wget -S "$URL2" 2>&1|sed -n /Location:/s/.*http:/http:/p)"
echo " done."
echo "Video address is $URL3"
exec wget -O "$VID.flv" "$URL3"
將上面的原始碼複製然後儲存為 youtube.sh
或由此下載