-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyoutube.lua
More file actions
40 lines (34 loc) · 1021 Bytes
/
youtube.lua
File metadata and controls
40 lines (34 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
do
local BASE_URL = 'http://gdata.youtube.com/feeds/api/'
function get_yt_data (yt_code)
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
function run(msg, matches)
local yt_code = matches[1]
local data = get_yt_data(yt_code)
local receiver = get_receiver(msg)
send_youtube_data(data, receiver)
end
return {
description = "Sends YouTube info and image.",
usage = "",
patterns = {
"youtu.be/([A-Za-z0-9-]+)",
"youtube.com/watch%?v=([A-Za-z0-9-]+)",
},
run = run
}
end