-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
-- DO NOT USE WITHOUT PERMISSION

do

local BASE_URL = 'https://api.dailymotion.com'

function get_dm_data (dm_code)
  local url = BASE_URL..'/video/'..dm_code
  local res,code  = https.request(url)
  if code ~= 200 then return "HTTP-FEHLER" end
  local data = json:decode(res)
  return data
end

function send_dailymotion_data(data, receiver)
  local title = data.title
  local channel = data.channel
  local text = title..'\nHochgeladen in die Kategorie "'..channel..'"'
  send_msg(receiver, text, ok_cb, false)
end

function run(msg, matches)
  local dm_code = matches[1]
  local data = get_dm_data(dm_code)
  local receiver = get_receiver(msg)
  send_dailymotion_data(data, receiver)
end

return {
  description = "Sendet Dailymotion-Info.", 
  usage = "URL zu Dailymotion-Video",
  patterns = {"dailymotion.com/video/([A-Za-z0-9-_-]+)"},
  run = run 
}

end