Explanation of YouTube FLV address
Http://kej.tw/flvretriever/
|
|
|
|
|
|
Flvdown. Sh for downloading FLV video from YouTube. |
|
|
You can see on the Internet that the FLV animation of YouTube can be downloaded through www.youtube.com/get_video.php, so you try to write a script to implement it:#!/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 |
|
|
|
Other
When I saw this shell script, I was thinking about another method of downloading YouTube.
The author of this shell script is also familiar with script and YouTube.
After reading his original shell script, I used the Linux wget to download a YouTube video.
The original shell script syntax is as follows:
#! /Bin/sh
# $ ID: Youtube. Sh 496 23: 37: 35z Berto $
If ["$ #"! = "1"]; then
Echo "YouTube video downloader"
Echo "written by Albert to 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:/P )"
Echo "done ."
Echo "video address is $ url3"
Exec wget-o "$ vid. FLV" "$ url3"
Save the original website as YouTube. Sh.
Or