Neu: Plugin in Plex Media Server
This commit is contained in:
parent
f0db1fe156
commit
8b2be9798f
5
.gitignore
vendored
5
.gitignore
vendored
@ -7,7 +7,6 @@ plugins/dantest.lua
|
||||
plugins/stats2.lua
|
||||
plugins/help2.lua
|
||||
plugins/pegelf_img.lua
|
||||
plugins/plex.lua
|
||||
plugins/chantalle.lua
|
||||
plugins/plex_xml.lua
|
||||
plugins/wiiu.lua
|
||||
plugins/wiiu.lua
|
||||
plugins/plex_test.lua
|
@ -228,6 +228,7 @@ function create_cred()
|
||||
neutrino_apikey = "",
|
||||
owm_apikey = "",
|
||||
page2images_restkey = "",
|
||||
plex_token = "",
|
||||
soundcloud_client_id = "",
|
||||
tumblr_api_key = "",
|
||||
tw_consumer_key = "",
|
||||
|
88
plugins/plex.lua
Normal file
88
plugins/plex.lua
Normal file
@ -0,0 +1,88 @@
|
||||
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
|
||||
local baseurl = 'http://yagyuu.local:32400'
|
||||
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]
|
||||
|
||||
local title = data.title
|
||||
|
||||
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
|
||||
fsk = '\nAltersfreigabe: '..data.contentRating
|
||||
else
|
||||
fsk = ''
|
||||
end
|
||||
|
||||
if data.rating then
|
||||
rating = '\nBewertung: '..data.rating
|
||||
else
|
||||
rating = ''
|
||||
end
|
||||
|
||||
local desc = '\n\nBeschreibung: '..data.summary
|
||||
local pic = baseurl..data.thumb
|
||||
|
||||
local text = title..origtitle..studio..date..fsk..rating..desc..'\n'
|
||||
|
||||
return text, pic
|
||||
end
|
||||
|
||||
local function run(msg, matches)
|
||||
local query = matches[1]
|
||||
local query = string.gsub(query, ":", '%%3A' )
|
||||
local query = string.gsub(query, " ", '+' )
|
||||
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 {
|
||||
description = "",
|
||||
usage = "",
|
||||
patterns = {"^/plex (.*)$"},
|
||||
run = run
|
||||
}
|
||||
|
||||
end
|
92
plugins/pluginsold/plex_xml.lua
Normal file
92
plugins/pluginsold/plex_xml.lua
Normal file
@ -0,0 +1,92 @@
|
||||
-- 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, '—', ' — ')
|
||||
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
|
Reference in New Issue
Block a user