2011年2月16日水曜日

macでyoutubeの動画をコマンドラインからダウンロード

youtubeの動画を落とすときにコマンドラインから楽に落としたい。

探してみると、Pythonで書かれたYouTubeビデオダウンロードプログラムを見つけました。
-youtube-dl
Python 2.4以降が必要みたいです。

「Download it」っていうボタンから、Pythonのプログラムをダウンロード。
ファイルがそのままテキストになってるので、自分は落としてきて、名前を「youtube-dl.py」とかにしました。
で、一応、chmodでパーミションを755にして実行権限を与えます。

あとはコマンドラインから、
$ ./youtube-dl.py http://www.youtube.com/watch?v=********* -l
とyoutubeのビデオURLを渡すだけ。-lオプションを付けてるのは、つけないとデフォルトのflvファイル名が英数字の羅列になっちゃうので。-lを付ければ名前もちゃんとつけてくれます(日本語OK)。

一応オプション。
$ ./youtube-dl.py -h
Usage: youtube-dl.py [options] url...

Options:
  -h, --help            print this help text and exit
  -v, --version         print program version and exit
  -U, --update          update this program to latest stable version
  -i, --ignore-errors   continue on download errors
  -r LIMIT, --rate-limit=LIMIT
                        download rate limit (e.g. 50k or 44.6m)
  -R RETRIES, --retries=RETRIES
                        number of retries (default is 10)
  --playlist-start=NUMBER
                        playlist video to start at (default is 1)
  --playlist-end=NUMBER
                        playlist video to end at (default is last)
  --dump-user-agent     display the current browser identification

  Authentication Options:
    -u USERNAME, --username=USERNAME
                        account username
    -p PASSWORD, --password=PASSWORD
                        account password
    -n, --netrc         use .netrc authentication data

  Video Format Options:
    -f FORMAT, --format=FORMAT
                        video format code
    --all-formats       download all available video formats
    --max-quality=FORMAT
                        highest quality format to download

  Verbosity / Simulation Options:
    -q, --quiet         activates quiet mode
    -s, --simulate      do not download video
    -g, --get-url       simulate, quiet but print URL
    -e, --get-title     simulate, quiet but print title
    --get-thumbnail     simulate, quiet but print thumbnail URL
    --get-description   simulate, quiet but print video description
    --get-filename      simulate, quiet but print output filename
    --no-progress       do not print progress bar
    --console-title     display progress in console titlebar

  Filesystem Options:
    -t, --title         use title in file name
    -l, --literal       use literal title in file name
    -A, --auto-number   number downloaded files starting from 00000
    -o TEMPLATE, --output=TEMPLATE
                        output filename template
    -a FILE, --batch-file=FILE
                        file containing URLs to download ('-' for stdin)
    -w, --no-overwrites
                        do not overwrite files
    -c, --continue      resume partially downloaded files
    --cookies=FILE      file to dump cookie jar to
    --no-part           do not use .part files
    --no-mtime          do not use the Last-modified header to set the file
                        modification time