主题 : Linux下载YouTube影片的Shell Script
级别: 乐园武士2级

UID: 126166
精华: 3
发帖: 552
威望: 635 点
论坛币: -3 两
贡献值: 1 点
在线时间: 227(时)
注册时间: 2006-08-09
最后登录: 2007-08-18
楼主  发表于: 2006-08-24 13:21

Linux下载YouTube影片的Shell Script

当我看到这个Shell Script的时候,简直佩服作者的Shell Scripting功夫
放在这里给有需要的人

用法:将下面的代码复制然后储存为youtube.sh


CODE:[Copy to clipboard]#!/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"
我在下面加了两行,使它下载后自动把flv转成mpg:


CODE:[Copy to clipboard]exec ffmpeg -i "$VID.flv" -ab 56 -ar 22050 -b 500 -s 320x240 "$VID.mpg"
exec rm "$VID.flv"
Total 0.025059(s) query 3, Time now is:02-09 06:37, Gzip enabled 渝ICP备09055655号
Powered by PHPWind v7.3.2 Certificate Game Code © 2003-09 PHPWind.com