如何从 id 中抓取 youtube 视频的缩略图? [英] How to scrape the thumbnail of a youtube video from id?

查看:31
本文介绍了如何从 id 中抓取 youtube 视频的缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 python 非常陌生,我想知道如何只打印 maxres 缩略图,而不是字面上关于视频的所有内容.抱歉,如果答案有点明显,我对 Python 和一般编程有点陌生.

I am very new to python, I'm wondering how I would just get the maxres thumbnail to print, instead of literally everything about the video. Sorry if the answer is a bit obvious, I am a bit new to python and programming in general.

from apiclient.discovery import build

DEVELOPER_KEY = 'xxxxxx'
youtube = build('youtube', 'v3', developerKey=DEVELOPER_KEY)

ids = '6Gw-RyTRMns'
results = youtube.videos().list(id=ids, part='snippet').execute()
for result in results.get('items', []):
    print(results)    

我还想知道是否有办法从给定视频的描述中获取图片的 URL 并将其保存到文件夹中.

I'm also wondering if there is a way to grab a URL to a picture from a description of a given video and have it saved to a folder.

推荐答案

多亏了 YouTube,这一切变得容易了.他们使用如下链接来检索不同分辨率的缩略图.假设您只需要 URL,只需将字符串格式化如下:

This has been made easy thanks to YouTube. They use links like the one below to retreive thumbnails at different resolutions. Assuming all you need is the URL, just format a string like this:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

您可以在这里找到类似的问题:如何从 YouTube API 获取 YouTube 视频缩略图?

You can find a similar question here: How do I get a YouTube video thumbnail from the YouTube API?

您可以在此处找到有关 Api 的更多信息:https://developers.google.com/youtube/v3/

You can find more information on the Api here: https://developers.google.com/youtube/v3/

要遍历频道,您可以在这里找到另一个类似的问题:python:获取频道的所有 youtube 视频网址

To iterate over a channel you can find another similar question here: python: get all youtube video urls of a channel

要下载图像,您可以使用类似的方法.

To download the images you could use something like this.

import urllib
urllib.urlretrieve("http://img.youtube.com/vi/ytvideo/0.jpg")

这篇关于如何从 id 中抓取 youtube 视频的缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆