使用wget下载YouTube视频

时间:2013-01-16 22:11:30

标签: linux youtube wget

我通常使用keepvid.com或Firefox下载助手插件来下载YouTube视频。是否可以使用Linux中提供的wget命令下载它们?

另外,我有一台VPS服务器。我想在我的VPS服务器(cPanel)上下载视频。

如果可能,如果可能,如何?

感谢。

3 个答案:

答案 0 :(得分:22)

我建议将youtube-dl作为YouTube和其他视频网站的控制台下载程序。

答案 1 :(得分:18)

#!/usr/bin/perl

use strict;
use warnings;
## Two arguments
##    $1 YouTube URL from the browser
##    $2 Prefix to the file name of the video (optional)
#

## Collect the URL from the command line argument
my $url = $ARGV[0] or die "\nError: You need to specify a YouTube URL\n\n";

## Declare the user defined file name prefix
my $prefix = defined($ARGV[1]) ? $ARGV[1] : "";

## Download the HTML code from the YouTube page
my $html = `wget -Ncq -e "convert-links=off" --keep-session-cookies --save-cookies /dev/null --no-check-certificate "$url" -O-`  or die  "\nThere was a problem downloading the HTML file.\n\n";

## Collect the title of the page to use as the file name
my ($title) = $html =~ m/<title>(.+)<\/title>/si;
$title =~ s/[^\w\d]+/_/g;
$title =~ s/_youtube//ig;
$title =~ s/^_//ig;
$title = lc ($title);

## Collect the URL of the video
my ($download) = $html =~ /"url_encoded_fmt_stream_map"([\s\S]+?)\,/ig;

## Clean up the URL by translating Unicode and removing unwanted strings
$download =~ s/\:\ \"//;
$download =~ s/%3A/:/g;
$download =~ s/%2F/\//g;
$download =~ s/%3F/\?/g;
$download =~ s/%3D/\=/g;
$download =~ s/%252C/%2C/g;
$download =~ s/%26/\&/g;
$download =~ s/sig=/signature=/g;
$download =~ s/\\u0026/\&/g;
$download =~ s/(type=[^&]+)//g;
$download =~ s/(fallback_host=[^&]+)//g;
$download =~ s/(quality=[^&]+)//g;

## Collect the URL and signature since the HTML page randomizes the order
my ($signature) = $download =~ /(signature=[^&]+)/;
my ($youtubeurl) = $download =~ /(http.+)/;
$youtubeurl =~ s/&signature.+$//;

## Combine the URL and signature in order to use in Wget
$download = "$youtubeurl\&$signature";

## A bit more cleanup
$download =~ s/&+/&/g;
$download =~ s/&itag=\d+&signature=/&signature=/g;

## Print the file name of the video collected from the web page title for us to see on the CLI
print "\n Download: $prefix$title.webm\n\n";

## Download the file using Wget and background the Wget process
system("wget -Ncq -e \"convert-links=off\" --load-cookies /dev/null --tries=50 --timeout=45 --no-check-certificate \"$download\" -O $prefix$title.webm &");

#### EOF #####

这是我已经使用了一段时间的Perl脚本。我不知道它来自哪里......它很棒。

答案 2 :(得分:0)

如果您需要这个用于Windows,YouTuber是Windows控制台下载程序。相同的链接也提供源代码。

  

免责声明:我制作了这个程序,它链接到我的github。