When I copy a YouTube link, like this one, for example (http://www.youtube.com/watch?v=_Ka2kpzTAL8), and paste it into a Facebook status update, Facebook somehow grabs a still of the video. I'd like to build a feature that does the same thing, but I don't really know how to find the image.
Can anyone point me in the right direction? I'm open to PHP, Python, Ruby or Perl.
Alright, found it !
Take this link: http://i4.ytimg.com/vi/something/hqdefault.jpg
and replace something with the video's ID on Youtube. For a smaller image, just remove the hq
part of the URL.
I can also confirm this implementation is the way two go. I have used it a Ruby screen scraper ( search application ) @ http://stripsearch.me
# search10b Youtube crawl9
@search10a1 = search_array[1]
if search_array[1].present?
@results_9b = []
params_9b = search_array[1].split.map(&:downcase).join('+')
search_url_yt_9b = url_9b << params_9b
doc_9b = Nokogiri::HTML(open(search_url_yt_9b).read, nil, 'utf-8')
entries_9b = doc_9b.css('.yt-ui-ellipsis-2.spf-link')
if entries_9b.size != 0
entries_9b.each do |entry_9b|
title = entry_9b['title']
li = "https://www.youtube.com"
nk = entry_9b['href']
link = li << nk
img_src = entry_9b['href']
uid = img_src.split('=').last
precede_url = "http://i4.ytimg.com/vi/"
append_url = "/hqdefault.jpg"
img_url = precede_url << uid << append_url
precede_tag = "<img src="
append_tag = ">"
img = precede_tag << img_url << append_tag
@results_9b.push(title, link, img)
end
else
@error_9b = "no results found here for " + params_9b
end
end
<meta property="og:image" content="http://i4.ytimg.com/vi/_Ka2kpzTAL8/hqdefault.jpg">
. Now I just have to figure out how to get a hold of that - Jason Swett 2012-04-04 18:34