从YouTube视频中获取播放列表ID

huangapple go评论63阅读模式
英文:

Get playlist ID from youtube video

问题

有没有办法通过API查找YouTube视频的播放列表ID,例如通过videoID?我查看了/playlistItems端点,但我不确定在哪里可以找到播放列表项ID?我已经尝试在各处查找这个信息,但我不知所措。

英文:

Is there any way to find playlist ID of youtube video using API, like through videoID? I looked into /playlistItems endpoint but I'm not sure where I can find the playlist item ID? I've tried to look this over everywhere but I'm at lost.

答案1

得分: 1

以下是已翻译的内容:

  1. 获取视频ID
  2. 如果您想要检查同一频道上的播放列表,请从视频中获取频道ID(参见https://developers.google.com/youtube/v3/docs/videos#resource)
  3. 获取您想要检查的播放列表(https://developers.google.com/youtube/v3/docs/playlists/list)-可以是您自己的播放列表或其他指定频道的播放列表
  4. 循环遍历并获取每个播放列表上的项目(正如您找到的https://developers.google.com/youtube/v3/docs/playlistItems/list)
  5. 寻找具有与您正在检查的视频ID相同的播放列表项(https://developers.google.com/youtube/v3/docs/playlistItems#resource)

这是一个有些繁琐且当然有限的方法 - 也许其他人会与我们分享更好的方法。

英文:

I looked a bit, and the only method I can find would be limited to your own playlists and playlists on the video's channel (or other channels that you specify):

  1. Get the video ID
  2. If you want to check playlists on the same channel, get the channel ID from the video (see https://developers.google.com/youtube/v3/docs/videos#resource)
  3. Get the playlists you want to check (https://developers.google.com/youtube/v3/docs/playlists/list) - either your own playlists or playlists on
  4. Loop through and get the items on each playlist (https://developers.google.com/youtube/v3/docs/playlistItems/list as you found)
  5. Look for the playlist item that has the same video ID as the one you're examining (https://developers.google.com/youtube/v3/docs/playlistItems#resource)

It's a bit ugly, and limited of course - maybe someone else will share a better method with us.

答案2

得分: 1

  1. 因为您有 video_id,也可以获取视频的标题
  2. 使用视频标题,在 search:list 端点中搜索与查询/条件匹配的播放列表 - 即视频的标题。
  3. 循环搜索请求的结果,并使用我在我的回答中展示的代码来检查 video_id 是否在播放列表中。

示例:

> video_id: eJjbnFZ6yA8
>
> 标题: FULL MATCH - The Rock vs. Mankind – > WWE Championship Match: Raw, Jan. 4, 1999

搜索匹配搜索词:“FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999”的播放列表。

URL:

https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=50&q=FULL%20MATCH%20-%20The%20Rock%20vs.%20Mankind%20%E2%80%93%20WWE%20Championship%20Match%3A%20Raw%2C%20Jan.%204%2C%201999&type=playlist&key=[YOUR_API_KEY]

在此尝试

从搜索结果中获取播放列表 - 例如,我从搜索结果中取得了第一个结果,然后检查 video_id eJjbnFZ6yA8 是否在播放列表 PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W 中。

URL:

https://youtube.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet&playlistId=PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W&videoId=eJjbnFZ6yA8&key=[YOUR_API_KEY]

在此尝试 检查结果。

请记住,search:list 端点消耗 100 配额点,因此,配额可能会相当快地耗尽 - 取决于搜索的强度。

英文:

An alternative could be:

  1. Since you have the video_id, get the title of the video as well.
  2. With the title of the video, use the search:list endpoint for search playlists that matches with the query/criteria - that is, the title of the video.
  3. Loop the results from the search request and use the code I show in my answer for check if the video_id is on the playlist.

Example:

> video_id: eJjbnFZ6yA8
>
> title: FULL MATCH - The Rock vs. Mankind –
> WWE Championship Match: Raw, Jan. 4, 1999

Make search to get playlists that matches the search term: "FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999"

URL:

https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=50&q=FULL%20MATCH%20-%20The%20Rock%20vs.%20Mankind%20%E2%80%93%20WWE%20Championship%20Match%3A%20Raw%2C%20Jan.%204%2C%201999&type=playlist&key=[YOUR_API_KEY]

Try-it here

From the results of the search, get the playlist - for this example I took the first result I got from the search, then, I check if the video_id eJjbnFZ6yA8 is on the playlist PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W

URL:

https://youtube.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet&playlistId=PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W&videoId=eJjbnFZ6yA8&key=[YOUR_API_KEY]

Try-it here for check the results.

Keep in mind that the search:list endpoint consumes 100 quota points, so, the quota might be drain rather quickly - depending of the intensity of the search.

huangapple
  • 本文由 发表于 2023年2月8日 22:36:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387337.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定