This commit is contained in:
yago 2015-02-15 20:27:21 +01:00
parent 874d2b3bf9
commit 975d57c827

View File

@ -1,16 +1,34 @@
do
function send_youtube_thumbnail(msg, yt_code) local BASE_URL = 'http://gdata.youtube.com/feeds/api/'
yt_thumbnail = "http://img.youtube.com/vi/".. yt_code .."/hqdefault.jpg"
file = download_to_file(yt_thumbnail) function get_yt_data (yt_code)
send_photo(get_receiver(msg), file, ok_cb, false) local url = BASE_URL..'/videos/'..yt_code..'?v=2&alt=jsonc'
local res,code = http.request(url)
if code ~= 200 then return "HTTP ERROR" end
local data = json:decode(res).data
return data
end
function send_youtube_data(data, receiver)
local title = data.title
local description = data.description
local uploader = data.uploader
local text = title..' ('..uploader..')\n'..description
local image_url = data.thumbnail.hqDefault
local cb_extra = {receiver=receiver, url=image_url}
send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
end end
function run(msg, matches) function run(msg, matches)
send_youtube_thumbnail(msg, matches[1]) local yt_code = matches[1]
local data = get_yt_data(yt_code)
local receiver = get_receiver(msg)
send_youtube_data(data, receiver)
end end
return { return {
description = "sends YouTube image", description = "Sends YouTube info and image.",
usage = "", usage = "",
patterns = { patterns = {
"youtu.be/([A-Za-z0-9-]+)", "youtu.be/([A-Za-z0-9-]+)",
@ -18,3 +36,5 @@ return {
}, },
run = run run = run
} }
end