我们需要YouTube的频道名称的视频列表(使用API)。

我们可以通过下面的API获得一个频道列表(只有频道名):

https://gdata.youtube.com/feeds/api/channels?v=2&q=tendulkar

下面是频道的直接链接

https://www.youtube.com/channel/UCqAEtEr0A0Eo2IVcuWBfB9g

Or

WWW.YouTube.com/channel/HC-8jgBP-4rlI

现在,我们需要>> UCqAEtEr0A0Eo2IVcuWBfB9g或HC-8jgBP-4rlI频道的视频。

我们尝试

https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&User=UC7Xayrf2k0NZiz3S04WuDNQ https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&q=UC7Xayrf2k0NZiz3S04WuDNQ

但是,这并没有帮助。

我们需要把所有视频发到频道上。上传到一个频道的视频可以来自多个用户,因此我不认为提供用户参数会有帮助…


当前回答

简短的回答:

这里有一个叫做scrapetube的库,可以帮你解决这个问题。

PIP安装刮刀管

import scrapetube

videos = scrapetube.get_channel("UC9-y-6csu5WGm29I7JiwpnA")

for video in videos:
    print(video['videoId'])

长一点的回答:

上面提到的模块是由我创建的,因为没有任何其他解决方案。以下是我的尝试:

硒。它很有效,但有三个大缺点:它需要安装网络浏览器和驱动程序。2. 对CPU和内存的需求很大。3.不能处理大频道。 使用youtube-dl。是这样的:

import youtube_dl
    youtube_dl_options = {
        'skip_download': True,
        'ignoreerrors': True
    }
    with youtube_dl.YoutubeDL(youtube_dl_options) as ydl:
        videos = ydl.extract_info(f'https://www.youtube.com/channel/{channel_id}/videos')

这也适用于小的频道,但对于更大的频道,我会被youtube屏蔽,因为在这么短的时间内发出这么多的请求(因为youtube-dl下载了更多的信息,每个视频在频道)。

所以我做了图书馆scrapetube使用web API来获得所有的视频。

其他回答

下面是返回频道下所有视频id的代码

<?php 
    $baseUrl = 'https://www.googleapis.com/youtube/v3/';
    // https://developers.google.com/youtube/v3/getting-started
    $apiKey = 'API_KEY';
    // If you don't know the channel ID see below
    $channelId = 'CHANNEL_ID';

    $params = [
        'id'=> $channelId,
        'part'=> 'contentDetails',
        'key'=> $apiKey
    ];
    $url = $baseUrl . 'channels?' . http_build_query($params);
    $json = json_decode(file_get_contents($url), true);

    $playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];

    $params = [
        'part'=> 'snippet',
        'playlistId' => $playlist,
        'maxResults'=> '50',
        'key'=> $apiKey
    ];
    $url = $baseUrl . 'playlistItems?' . http_build_query($params);
    $json = json_decode(file_get_contents($url), true);

    $videos = [];
    foreach($json['items'] as $video)
        $videos[] = $video['snippet']['resourceId']['videoId'];

    while(isset($json['nextPageToken'])){
        $nextUrl = $url . '&pageToken=' . $json['nextPageToken'];
        $json = json_decode(file_get_contents($nextUrl), true);
        foreach($json['items'] as $video)
            $videos[] = $video['snippet']['resourceId']['videoId'];
    }
    print_r($videos);

注意:你可以在 登录https://www.youtube.com/account_advanced。

试着像下面这样做。它可能对你有帮助。

https://gdata.youtube.com/feeds/api/videos?author=cnn&v=2&orderby=updated&alt=jsonc&q=news

在这里作者,你可以指定你的频道名称和“q”,因为你可以给你的搜索关键字。

使用已弃用的API版本2,用于上传的URL(通道UCqAEtEr0A0Eo2IVcuWBfB9g)是:

https://gdata.youtube.com/feeds/users/UCqAEtEr0A0Eo2IVcuWBfB9g/uploads

有一个API版本3。

Python中的示例解决方案。从这个视频中得到帮助:视频 与许多其他答案一样,上传id首先从通道id中检索。

import urllib.request
import json

key = "YOUR_YOUTUBE_API_v3_BROWSER_KEY"

#List of channels : mention if you are pasting channel id or username - "id" or "forUsername"
ytids = [["bbcnews","forUsername"],["UCjq4pjKj9X4W9i7UnYShpVg","id"]]

newstitles = []
for ytid,ytparam in ytids:
    urld = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails&"+ytparam+"="+ytid+"&key="+key
    with urllib.request.urlopen(urld) as url:
        datad = json.loads(url.read())
    uploadsdet = datad['items']
    #get upload id from channel id
    uploadid = uploadsdet[0]['contentDetails']['relatedPlaylists']['uploads']

    #retrieve list
    urld = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId="+uploadid+"&key="+key
    with urllib.request.urlopen(urld) as url:
        datad = json.loads(url.read())

    for data in datad['items']:
        ntitle =  data['snippet']['title']
        nlink = data['contentDetails']['videoId']
        newstitles.append([nlink,ntitle])

for link,title in newstitles:
    print(link, title)

只需三步:

订阅:list -> https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&maxResults=50&mine=true&access_token= {oauth_token} 通道:list -> https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id= {channel_id}关键= {YOUR_API_KEY} PlaylistItems: list -> https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId= {playlist_id}关键= {YOUR_API_KEY}