我可以在 Tkinter 应用程序上获取 Youtube 缩略图吗

Could I get a Youtube thumbnail onto a Tkinter application

我目前正在设计一个应用程序,用户在 URL 中输入该应用程序,该应用程序通过 pytube 等模块下载它(如果您知道更好的模块,请推荐)。这是我目前从 Youtube URL.

中查找缩略图 URL 的简短代码
template = 'https://img.youtube.com/vi/{}/0.jpg'
link1 = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'

a,b = link1.split('=')

new = template.format(b)

print(new)

变量 new 是缩略图的 URL,是否可以下载或将其添加到我的应用程序中,或者是否有可以为我执行此操作的模块?

我建议您查看 Youtube API 和 Requests 库。 Requests 使得从 API's 和 Youtube's 中提取数据变得很简单。我无法告诉您如何将图像直接与 TKinter 集成,但是一旦您从查询中获得缩略图,它应该是微不足道的。

import requests之后我做了这个

data = requests.get(new).content
with open('file01.jpg','wb') as file:
    file.write(data)