0

第一个参数应该是视频的 url。谁能向我指出为什么这不起作用?

我启动了 ubuntu 12.04 的这些 ec2 实例之一,它已经安装了 perl 和 wget http://cloud-images.ubuntu.com/precise/current/

该脚本源自这里: https ://calomel.org/youtube_wget.html

#!/usr/bin/perl

use strict;
use warnings;

## 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 and translate to the proper URL
my ($download) = $html =~ /url_encoded_fmt_stream_map([\s\S]+?)fallback_host/ig;
$download =~ s/\\u0026/\&/g;
$download =~ s/^\=url%3D//g;
$download =~ s/%25/%/g;
$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/%253A/\:/g;

## print the file name of the video
print "\n     Download:   $prefix$title.webm\n\n";

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

编辑 在我运行 perl 脚本后,视频没有下载(它的大小为 0 字节)

$ ./youtube_get_videos.pl http://www.youtube.com/watch?v=ejkm5uGoxs4

     Download:   radscorpion_youtube.webm

$ ls -lh
-rw-rw-r-- 1 ubuntu ubuntu    0 Sep 14 04:40 radscorpion_youtube.webm
4

2 回答 2

1

&我怀疑它是您system命令中的“唐老鸭”,与号。您不是在等待程序完成。我不知道这可能需要多长时间,但不会是瞬间的。您(可能)从中获得的错误代码 0system将由 shell 返回(&将调用 shell),而不是wget.

于 2012-09-14T09:29:49.387 回答
1

让我为你 CPAN :WWW::YouTube::Download。安装此模块后,只需使用捆绑的youtube-download实用程序:

stas@Stanislaws-MacBook-Pro:~$ youtube-download -o "{title}.{suffix}" http://www.youtube.com/watch?v=ejkm5uGoxs4 
--> Working on ejkm5uGoxs4
Downloading `RADSCORPION!.mp4`
26320989/26320989 (100.00%)
Download successful!
stas@Stanislaws-MacBook-Pro:~$ file RADSCORPION\!.mp4 
RADSCORPION!.mp4: ISO Media, MPEG v4 system, version 2
stas@Stanislaws-MacBook-Pro:~$

奇迹般有效 :)

于 2013-01-11T18:36:03.300 回答