This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/search_youtube.lua

31 lines
761 B
Lua
Raw Normal View History

2015-04-19 22:03:06 +02:00
function searchYoutubeVideo(text)
local data = httpRequest('http://gdata.youtube.com/feeds/api/videos?max-results=1&alt=json&q=' .. URL.escape(text))
2015-03-16 20:28:13 +01:00
if not data then
print("HTTP Error")
return nil
elseif not data.feed.entry then
2015-04-19 22:03:06 +02:00
return "YouTube Video nicht gefunden!"
2015-03-16 20:28:13 +01:00
end
return data.feed.entry[1].link[1].href
end
2015-04-19 22:03:06 +02:00
function httpRequest(url)
local res,code = http.request(url)
if code ~= 200 then return nil end
return json:decode(res)
end
function run(msg, matches)
local text = msg.text:sub(string.len(matches[1]) + 1,-1)
return searchYoutubeVideo(text)
2015-03-16 20:28:13 +01:00
end
return {
2015-04-19 22:03:06 +02:00
description = "Sucht ein Video auf YouTube und sendet es.",
2015-04-14 20:21:23 +02:00
usage = "/youtube [Begriff]",
2015-03-16 20:28:13 +01:00
patterns = {
2015-04-19 22:03:06 +02:00
"^/youtube",
"^/yt"
},
run = run
}