2015-11-12 17:42:03 +01:00
|
|
|
do
|
|
|
|
|
2016-01-30 21:03:21 +01:00
|
|
|
local function send_gfycat_video(name, receiver)
|
2015-11-12 17:42:03 +01:00
|
|
|
local BASE_URL = "https://gfycat.com"
|
|
|
|
local url = BASE_URL..'/cajax/get/'..name
|
|
|
|
local res,code = https.request(url)
|
|
|
|
if code ~= 200 then return "HTTP-FEHLER" end
|
|
|
|
local data = json:decode(res).gfyItem
|
2016-01-30 21:03:21 +01:00
|
|
|
local file = download_to_file(data.webmUrl)
|
2015-11-12 17:42:03 +01:00
|
|
|
local cb_extra = {file_path=file}
|
|
|
|
if file == nil then
|
2016-01-30 21:03:21 +01:00
|
|
|
send_msg(receiver, 'Fehler beim Herunterladen von '..name, ok_cb, false)
|
2015-11-12 17:42:03 +01:00
|
|
|
else
|
2016-01-30 21:03:21 +01:00
|
|
|
send_video(receiver, file, rmtmp_cb, cb_extra)
|
2015-11-12 17:42:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function send_gfycat_thumb(name, receiver)
|
|
|
|
local BASE_URL = "https://thumbs.gfycat.com"
|
|
|
|
local url = BASE_URL..'/'..name..'-poster.jpg'
|
|
|
|
local file = download_to_file(url)
|
|
|
|
local cb_extra = {file_path=file}
|
|
|
|
if file == nil then
|
2016-01-30 21:03:21 +01:00
|
|
|
print('Fehler beim Herunterladen des Thumbnails von '..name)
|
2015-11-12 17:42:03 +01:00
|
|
|
else
|
|
|
|
send_photo(receiver, file, rmtmp_cb, cb_extra)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
2016-01-30 21:03:21 +01:00
|
|
|
local name = matches[1]
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
send_gfycat_video(name, receiver)
|
|
|
|
if matches[2] ~= 'NSFW' then
|
|
|
|
send_gfycat_thumb(name, receiver)
|
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
description = "Postet Gfycat-Video",
|
2016-01-30 21:03:21 +01:00
|
|
|
usage = "URL zu gfycat-Video (hänge 'NSFW' an, wenn es NSFW ist)",
|
2015-11-12 17:42:03 +01:00
|
|
|
patterns = {
|
2016-01-30 21:03:21 +01:00
|
|
|
"gfycat.com/([A-Za-z0-9-_-]+) (NSFW)",
|
|
|
|
"gfycat.com/([A-Za-z0-9-_-]+)"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
|
|
|
run = run
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|