Youtube python: get thumbnail

Is there an easy way to get the default thumbnail from the youtube gdata.youtube.YouTubeVideoEntry recording object?

I tried entry.media.thumbnail, but that gives me four thumbnail objects. Can I always believe that there are four of them? Can I find out which default thumbnail will be displayed on the youtube search page? And how do I get this? Or do I need to change one of the others?

When I know video_id, I use:

http://i4.ytimg.com/vi/ {{video_id}} / default.jpg

so it would be useful to get video_id.

Do I need to deal with one of the URLs to get into video_id? It seems strange that they do not provide this information directly.

+3
source share
2 answers

gdata.youtube.YouTubeVideoEntry:

import gdata.youtube.service

service = gdata.youtube.service.YouTubeService()
feed_url = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed?v=2'
feed = service.GetYouTubeVideoFeed(feed_url)
entry = feed.entry[0] # pick most viewed video as sample entry

thumbnail = entry.media.thumbnail[0].url
    # will be an URL like: 'http://i.ytimg.com/vi/%(video_id)s/default.jpg'
    # when querying YouTube API version 2 ('?v=2' at the end of feed URL)

, 4 ( ). .

URL- entry.id.text , , , 'http://i4.ytimg.com/vi/%(video_id)s/default.jpg', URL- . URL- .

: "default.jpg" , 2 API YouTube ( "? v = 2" URL ). , .

+3

URL:

thumnail_url = "http://img.youtube.com/vi/%s/0.jpg" % video_id

: https://djangosnippets.org/snippets/2234/

+3

Source: https://habr.com/ru/post/1783483/


All Articles