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/pluginsold/plex_xml.lua

92 lines
2.3 KiB
Lua

-- 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 xml = require("xml")
local BASE_URL = 'http://yagyuu.local:32400'
local function delete_tags(str)
str = string.gsub( str, '<br />', '')
str = string.gsub( str, '%[i%]', '')
str = string.gsub( str, '%[/i%]', '')
str = string.gsub( str, '&mdash;', '')
return str
end
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)"
local year, month, day = dateString:match(pattern)
return day..'.'..month..'.'..year
end
local function get_info(tags)
local url = BASE_URL..'/search?query='..tags
local res,code = http.request(url)
if code ~= 200 then return "HTTP-Fehler" end
local result = xml.load(res)
return result
end
local function send_data(result, receiver)
--[[ local title = xml.find(result, 'Video', 'title')[1]
if xml.find(result, 'Video', 'parentIndex')[1] then
season = 'S'..xml.find(result, 'Video', 'parentIndex')[1]
else
season = ''
end
if xml.find(result, 'Video', 'index')[1] then
episode = 'E'..xml.find(result, 'Video', 'index')[1]
else
episode = ''
end
if xml.find(result, 'Video', 'originallyAvailableAt')[1] ~= "0000-00-00" then
date = 'Ausstrahlung: '..makeOurDate(xml.find(result, 'Video', 'originallyAvailableAt')[1])
else
date = ''
end
if xml.find(result, 'Video', 'summary')[1] then
desc = '\n'..unescape(delete_tags(string.sub(xml.find(result, 'Video', 'summary')[1], 1, 200)))..'...'
else
desc = ''
end
local text = title..' ('..season..episode..')\n'..date..'\n\n'..desc]]
if xml.find(result, 'thumb') then
local image_url = BASE_URL..xml.find(result, 'thumb')[1]
local cb_extra = {
receiver=receiver,
url=image_url
}
send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
else
send_msg(receiver, text, ok_cb, false)
end
end
local function run(msg, matches)
local tags = URL.escape(matches[1])
local receiver = get_receiver(msg)
local info = get_info(tags)
if info == "HTTP-Fehler" then
return "Nichts gefunden!"
else
send_data(info, receiver)
end
end
return {
description = "",
usage = "",
patterns = {"^/plex (.*)$"
},
run = run
}
end