【问题标题】:Download YouTube videos with wget使用 wget 下载 YouTube 视频
【发布时间】:2012-12-31 09:16:45
【问题描述】:

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

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

如果可以,如果可以,怎么做?

谢谢。

【问题讨论】:

    标签: linux youtube wget


    【解决方案1】:

    我会推荐 youtube-dl 作为来自 YouTube 和其他视频网站的控制台下载器。

    【讨论】:

    • 聚会有点晚了,但刚刚发现这可以通过 Homebrew 安装。很简单,谢谢!
    • $ sudo pip install youtube-dl
    【解决方案2】:
    #!/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 脚本。我不确定它来自哪里……它很好用。

    【讨论】:

    • 之所以发表评论,是因为我今天在三个不同的视频中尝试了这个脚本,但对于所有这些视频,它都生成了一个空文件。问题很可能是 YouTube 的一些变化。我还没有完成故障排除,但我想补充一点。
    • 也给我空文件
    • YouTube 大约每 3 个月进行一次更改以破坏此类脚本。该脚本可能会更新以适用于当代网站。
    【解决方案3】:

    如果您在 Windows 上需要这个,YouTuber 是一个 Windows 控制台下载器。同样的链接也提供了源代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多