perl - 为什么这个使用 wget 保存 youtube 视频的 perl 脚本不能正常工作?

标签 perl bash ubuntu wget

第一个参数应该是视频的 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

最佳答案

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

关于perl - 为什么这个使用 wget 保存 youtube 视频的 perl 脚本不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12417997/

相关文章:

ubuntu - 如何在窗口 7 的 Octave 中使用 Vlfeat?

windows - 在 Windows 中编辑代码但在 Ubuntu 中运行 Rails?

linux - Perl 中的条件拆分

perl - 需要 html::tagFilter 的帮助

bash - 如何获取当前目录中的每个文件夹并将其迭代到脚本中

bash - bash 中的循环迭代

regex - 更改特定字母后的所有出现位置

perl - 根据字符串出现的次数拆分一行

linux - 如何运行 bash 脚本?

linux - 如何停止/禁用/保持 linux 中软件包的自动更新?