View on GitHub

ytcmd

Execute shell commands on YouTube videos

Download this project as a .zip file Download this project as a tar.gz file

ytcmd is a tool to execute shell commands on YouTube videos. It is written in Python 3.3, and is available under the MIT license.

$ ytcmd SvaG0xDdP8g
Title:  The Space Shuttle (Narrated by William Shatner)
Length: 1:20:44
ID:     SvaG0xDdP8g

  45  720p webm 
  22  720p mp4  
  35  480p flv  
  43  360p webm 
  34  360p flv  
* 18  360p mp4  
   5  240p flv  
  36  240p 3gp  
  17  144p 3gp

Get the video URL (for the format marked with *):

$ ytcmd -u SvaG0xDdP8g
http://r6---sn-po8puxa-c0ql.c.youtube.com/ ...

Play with mplayer:

$ ytcmd --exec 'mplayer "$url"' SvaG0xDdP8g

Same, but fake the User-Agent, display the title in the titlebar, and allow seeking to a given time:

$ yt.play() { ytcmd -e 'exec mplayer -user-agent "$ua" -title "$title" ${ss:+-ss "$ss"} "$url"' "$@"; }
$ ss=15:00 yt.play SvaG0xDdP8g

Play in HD, but only WebM or MPEG-4 formats:

$ yt.play SvaG0xDdP8g 1080:720p/webm,mp4

See more examples at the GitHub page.

Installation

  1. git clone git://github.com/ariand/ytcmd.git
  2. Run python setup.py install, or just copy the ytcmd script into a directory on your PATH.