【问题标题】:How can I get Youtube MostViewed URL我如何获得 Youtube 观看次数最多的 URL
【发布时间】:2016-09-25 09:13:33
【问题描述】:

如果用户输入视频的名称,它将链接到该名称的观看次数最多的 Youtube 视频。例如,如果用户搜索“Sam Smith”,它将重定向到 Sam Smith 观看次数最多的视频。我该怎么做?

【问题讨论】:

    标签: html youtube


    【解决方案1】:

    你熟悉命令行吗?

    如果是这样,这个 perl 程序会为您提供给定用户观看次数最多的视频的 url。这假设 YouTube 不会很快更改其 HTML 格式。

    #!/usr/bin/perl
    
    print "Enter user name: ";
    chomp ($user = <STDIN>);
    
    my $url = "https://www.youtube.com/user/".$user."/videos?sort=p"; # sort=p means sort by popularity
    
    # open the web page
    open F, "wget -q -O- $url|" or die "Could not wget $url";
    
    my $mostViewedUrl = 'ERROR';
    
    foreach $line (<F>){
        # Since the urls are sorted by popularity,
        # we want the first url only.
        if($line =~ /.*<h3 class="yt-lockup-title ">/){
            $mostViewedUrl = $line;
            last;
        }
    }
    
    $mostViewedUrl =~ s/.*href="([^"]+).*/$1/;
    $mostViewedUrl = 'youtube.com'.$mostViewedUrl;
    print "Most viewed link: $mostViewedUrl";
    

    【讨论】:

      【解决方案2】:

      Youtube 为开发人员提供了大量的 API,可以从其数据库中提取数据,而不会给用户带来安全问题。您可以查看here 以获取 youtube 提供的 API。 为此,您只需要以开发人员身份登录并在其中创建一个项目,您可以学习 here

      这样一种方法是,您可以确定频道视频的最大观看次数,然后您可以找到该视频。 Here 是可能有用的链接。

      【讨论】:

      • 仅链接的答案不好。链接目标可能会移动,答案变得毫无意义。答案应尽可能独立。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-04
      • 2012-10-01
      • 1970-01-01
      • 2019-04-14
      • 2011-03-01
      • 2011-11-21
      • 1970-01-01
      相关资源
      最近更新 更多