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/nicovideo.lua

55 lines
1.6 KiB
Lua

do
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)T"
local year, month, day = dateString:match(pattern)
if month == "00" then
return year
elseif day == "00" then
return month..'.'..year
else
return day..'.'..month..'.'..year
end
end
local function get_vid_info(id)
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fext.nicovideo.jp%2Fapi%2Fgetthumbinfo%2Fsm'..id..'%22&format=json'
local res,code = https.request(url)
local data = json:decode(res).query.results.nicovideo_thumb_response.thumb
if code ~= 200 then return "HTTP-Fehler" end
if not data then return "HTTP-Fehler" end
local title = data.title
local date = makeOurDate(data.first_retrieve)
local user = data.user_nickname
local views = comma_value(data.view_counter)
local dura = data.length
local favs = comma_value(data.mylist_counter)
local comm = comma_value(data.comment_num)
local pic = data.thumbnail_url
local text = title..'\nHochgeladen am '..date..' von '..user..', '..views..'x angesehen, Länge: '..dura..', '..favs..'x favoritisiert, '..comm..' Kommentare'
return text, pic
end
local function run(msg, matches)
local id = matches[1]
local text, pic = get_vid_info(id)
local receiver = get_receiver(msg)
local file = download_to_file(pic)
send_photo(receiver, file, ok_cb, false)
return text
end
return {
description = "Sendet Infos zu einem nicovideo-Video",
usage = "Link zu nicovideo.jp Video",
patterns = {
"nicovideo.jp/watch/sm(%d+)$",
"nico.ms/sm(%d+)$"
},
run = run
}
end