Crawley
Crawley

Reputation: 640

Could I get a Youtube thumbnail onto a Tkinter application

I'm currently designing an application that the user enters in a URL and the application downloads it via a module such as pytube (if you know better ones please reccommend). This is my current brief code to find the thumbnail URL from a Youtube 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)

The variable new is the URL for the thumbnail, is there anyway to download this or add this to my application, or is there a module that can do this for me?

Upvotes: 0

Views: 706

Answers (2)

Crawley
Crawley

Reputation: 640

After import requests I did this

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

Upvotes: 0

Mike
Mike

Reputation: 23

I would suggest taking a look at the Youtube API and the Requests library. Requests makes it simple to pull data from API's and Youtube's is well documented. I cannot tell you how to integrate the image directly with TKinter, but once you have the thumbnail from the query it should be trivial.

Upvotes: 1

Related Questions