doulai2025 2016-10-08 00:02
浏览 303
已采纳

如何获取包含特定单词的YouTube视频的视频片段

Ok, so based on this video; https://www.youtube.com/watch?v=7tjfeEAdY0I

I'm curious if it's possible to create a PHP script that will automatically grab all video's on a certain youtube channel (in this example; https://www.youtube.com/user/whitehouse/videos), grab all videos, check out the transcripts for a certain line or word, then save the vids with the correct timestamp, to make it possible to merge all these video's into one.

I know there's an API available to get all youtube video url's of a specific user, and you can get the transcripts per video, but scanning through all of them will be quite resource-heavy. I'm curious if you guys have any ideas on how to create such a script.

  • 写回答

1条回答 默认 最新

  • dqo58772 2016-10-10 17:53
    关注

    It is possible to capture all information related to videos of a particular YouTube channel using the YouTube V3 API.
    The documentation of YouTube API can be found here
    The related API functionality can be found here

    The procedure to retrieve the transcript of a video from the json response from the API call will not be resource intensive and can be achieved in line of code as json parsing is a standard procedure and is supported on most of the languages including PHP.

    Using the PHP wrapper, this can be achieved in a few lines of code.

    Procedure:
    Firstly, a request to listChannels under channels is send to receive all content details regarding a particular YouTube channel denoted by a channel ID. The related code snippet is:

    $channelsResponse = $service->channels->listChannels('contentDetails', array('forUsername' => $channelId));
    

    The second step is to parse through each video item which is done conveniently using a for loop like:

    foreach ($channelsResponse['items'] as $channel)  {}
    

    The third step is to get the upload list id from the current item and send another request to the API with the parameter 'snippet'.

    At this point, you will have all the content related data in json format and you need to parse and get the desired information.


    The entire code snippet is :

    $channelsResponse = $service->channels->listChannels('contentDetails', array('forUsername' => $channelId));
    
    $data = [];
    
    foreach ($channelsResponse['items'] as $channel) 
    {
    
      $uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];
    
      $playlistItemsResponse = $service->playlistItems->listPlaylistItems(
    'snippet', array(
                        'playlistId' => $uploadsListId,
                        'maxResults' => 50
                    )
       );
    
      foreach ($playlistItemsResponse['items'] as $playlistItem) 
      {
            $data[] = $playlistItem['snippet'];
      }
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab