2016-02-25 15:25:50 +01:00
|
|
|
do
|
|
|
|
|
|
|
|
local makeOurDate = function(dateString)
|
|
|
|
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
|
|
|
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_plex(query)
|
|
|
|
local token = cred_data.plex_token
|
2016-02-25 15:55:07 +01:00
|
|
|
local baseurl = 'http://yagyuu.local:32400' --replace it with yours
|
2016-02-25 15:25:50 +01:00
|
|
|
local response_body = {}
|
|
|
|
local request_constructor = {
|
|
|
|
url = baseurl..'/search?query='..query..'&X-Plex-Token='..token,
|
|
|
|
method = "GET",
|
|
|
|
sink = ltn12.sink.table(response_body),
|
|
|
|
headers = {
|
|
|
|
Accept = "application/json"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local ok, response_code, response_headers, response_status_line = http.request(request_constructor)
|
|
|
|
local data = json:decode(table.concat(response_body))._children[1]
|
2016-02-25 19:10:29 +01:00
|
|
|
|
2016-02-25 15:25:50 +01:00
|
|
|
local title = data.title
|
|
|
|
|
2016-02-25 15:55:07 +01:00
|
|
|
if data.parentIndex then
|
2016-02-29 22:04:43 +01:00
|
|
|
season = 'S'..convertNumbers(data.parentIndex)
|
2016-02-25 15:55:07 +01:00
|
|
|
else
|
|
|
|
season = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.index then
|
2016-02-29 22:04:43 +01:00
|
|
|
episode = 'E'..convertNumbers(data.index)
|
2016-02-25 15:55:07 +01:00
|
|
|
else
|
|
|
|
episode = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.grandparentTitle then
|
|
|
|
from = ' (aus '..data.grandparentTitle..' ['..season..episode..']'..') '
|
|
|
|
else
|
|
|
|
from = ''
|
|
|
|
end
|
|
|
|
|
2016-02-25 15:25:50 +01:00
|
|
|
if data.originalTitle then
|
|
|
|
origtitle = '\nOriginal: '..data.originalTitle
|
|
|
|
else
|
|
|
|
origtitle = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.studio then
|
|
|
|
studio = '\nStudio: '..data.studio
|
|
|
|
else
|
|
|
|
studio = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.originallyAvailableAt then
|
|
|
|
date = '\nAusstrahlung: '..makeOurDate(data.originallyAvailableAt)
|
|
|
|
else
|
|
|
|
date = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.contentRating then
|
2016-02-26 22:45:34 +01:00
|
|
|
fsk = '\nAltersfreigabe: '..gerRating(data.contentRating)
|
2016-02-25 15:25:50 +01:00
|
|
|
else
|
|
|
|
fsk = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.rating then
|
|
|
|
rating = '\nBewertung: '..data.rating
|
|
|
|
else
|
|
|
|
rating = ''
|
|
|
|
end
|
|
|
|
|
2016-02-25 19:10:29 +01:00
|
|
|
if data.summary then
|
2016-02-29 22:04:43 +01:00
|
|
|
desc = '\n\n'..string.gsub(data.summary, 'EditBackgroundNo(.*)', '')
|
2016-02-25 19:10:29 +01:00
|
|
|
else
|
|
|
|
desc = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.thumb then
|
|
|
|
pic = baseurl..data.thumb
|
|
|
|
end
|
2016-02-25 15:25:50 +01:00
|
|
|
|
2016-02-25 15:55:07 +01:00
|
|
|
local text = title..from..origtitle..studio..date..fsk..rating..desc..'\n'
|
2016-02-25 15:25:50 +01:00
|
|
|
|
2016-02-25 19:10:29 +01:00
|
|
|
|
|
|
|
if data.thumb then
|
|
|
|
return text, pic
|
|
|
|
else
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
2016-02-25 15:25:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
2016-02-25 19:10:29 +01:00
|
|
|
local query = URL.escape(matches[1])
|
2016-02-25 15:25:50 +01:00
|
|
|
local text, pic = get_plex(query)
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
local file = download_to_file(pic)
|
|
|
|
send_photo(receiver, file, ok_cb, false)
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2016-02-26 22:45:34 +01:00
|
|
|
description = "Suche für Plex Media Server",
|
|
|
|
usage = "/plex [BEGRIFF]",
|
|
|
|
patterns = {"^/[Pp][Ll][Ee][Xx] (.*)$"},
|
2016-02-25 15:25:50 +01:00
|
|
|
run = run
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|