Have you ever found interesting videos on YouTube, and wanted to download and save them on your hard drive (for offline access or archiving purpose)? There is a handy open-source Linux tool that does exactly that: download YouTube videos.
A tool called youtube-dl is a command-line program written in Python that downloads videos from various online video sharing sites, including YouTube, DailyMotion, Vimeo, etc. Since the tool is written in Python, it can run on any platform that has Python interpreter (in particular, Python version 2.6, 2.7, or 3.3+). A binary for Windows platform is also available.
Here is a guide on how to download and save YouTube videos by using youtube-dl.
Instead of using a package manager, you can also download youtube-dl Python code directly from its website, and use it.
Once you have installed youtube-dl, it is straightforward to download a YouTube video. You just need to pass a YouTube video link to youtube-dl. It will go ahead and fetch the video and store it as mp4/flv format.
$ youtube-dl http://www.youtube.com/watch?v=ykp8fxHWcVo
ykp8fxHWcVo: Downloading video webpage
ykp8fxHWcVo: Downloading video info webpage
ykp8fxHWcVo: Extracting video information
[download] Destination: ykp8fxHWcVo.mp4
[download] 3.5% of 56.72M at 367.13k/s ETA 02:32^C
Resume Interrupted Downloads of YouTube Videos
The youtube-dl tool supports resuming interrupted downloads. If youtube-dl is killed (for example by Ctrl-C or due to loss of Internet connectivity) in the middle of download, you can simply re-run it with the same YouTube video url. It will automatically resume the unfinished download, as long as a partial download is present in the current directory.
Download YouTube Videos in Multiple Formats
Most of YouTube videos nowadays are available in multiple resolutions and formats in order to support various devices and Internet connections. The youtube-dl tool actually allows you to choose a specific resolution and format when downloading YouTube videos.
Since different YouTube videos may have different resolutions ready, you first need to check available video formats of a given YouTube video. For that, run youtube-dl with “-F” option. It will show you a list of available formats.
$ youtube-dl -F http://www.youtube.com/watch?v=BlXaGWbFVKY
BlXaGWbFVKY: Downloading video webpage
BlXaGWbFVKY: Downloading video info webpage
BlXaGWbFVKY: Extracting video information
37 : mp4 [1080x1920]
46 : webm [1080x1920]
22 : mp4 [720x1280]
45 : webm [720x1280]
35 : flv [480x854]
44 : webm [480x854]
34 : flv [360x640]
18 : mp4 [360x640]
43 : webm [360x640]
5 : flv [240x400]
17 : mp4 [144x176]
Now among the available video formats, choose one that you like:
You can put commonly used options (e.g., –extract-audio –audio-format mp3) in youtube-dl‘s configuration file, which is located at either /etc/youtube-dl.conf (system-wide) or ~/.config/youtube-dl.conf (per-user), in which case those options become “default” arguments that you do not have to specify explicitly from the command line.
As an alternative to /opt/lampp/bin/php, to run a php script from the command line, you just need to install php5-cli: sudo apt-get install php5-cli And run your script with: php myscript.php To open an interactive php shell, just type in a terminal: 如果想在terminal里面直接写php，可以用： php -a 本文：linux: 命令行运行php Run PHP from the command line