【问题标题】:Could I get a Youtube thumbnail onto a Tkinter application我可以在 Tkinter 应用程序上获取 Youtube 缩略图吗
【发布时间】:2018-03-28 12:42:12
【问题描述】:

我目前正在设计一个用户在 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,是否可以下载或将其添加到我的应用程序中,或者是否有可以为我执行此操作的模块?

【问题讨论】:

  • 可以使用urllib下载图片,使用pillow将图片嵌入tkinter

标签: python python-3.x youtube pytube


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    import requests之后我做了这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 2011-06-03
      • 2011-10-09
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 2012-04-25
      相关资源
      最近更新 更多