2016-04-11 06:04:47 +02:00
|
|
|
local imdb = {}
|
|
|
|
|
|
|
|
imdb.command = 'imdb <query>'
|
2016-05-27 05:28:44 +02:00
|
|
|
|
|
|
|
function imdb:init(config)
|
|
|
|
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
|
2016-08-05 15:06:15 +02:00
|
|
|
imdb.inline_triggers = {
|
|
|
|
"^imdb (.+)"
|
|
|
|
}
|
2016-06-11 14:46:41 +02:00
|
|
|
imdb.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[imdb* _<Film>_
|
2016-08-05 15:06:15 +02:00
|
|
|
Sucht _Film_ bei IMDb]]
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
local BASE_URL = 'https://www.omdbapi.com'
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
function imdb:get_imdb_info(id)
|
|
|
|
local url = BASE_URL..'/?i='..id
|
|
|
|
local res, code = https.request(url)
|
|
|
|
if code ~= 200 then return end
|
|
|
|
local movie_info = json.decode(res)
|
|
|
|
return movie_info
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
function imdb:inline_callback(inline_query, config, matches)
|
|
|
|
local query = matches[1]
|
|
|
|
local url = BASE_URL..'/?s='..URL.escape(query)
|
|
|
|
local res, code = https.request(url)
|
|
|
|
if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end
|
|
|
|
local data = json.decode(res)
|
|
|
|
if data.Response ~= "True" then utilities.answer_inline_query(self, inline_query) return end
|
|
|
|
|
|
|
|
local results = '['
|
2016-08-07 21:20:48 +02:00
|
|
|
local id = 500
|
2016-08-05 15:06:15 +02:00
|
|
|
for num in pairs(data.Search) do
|
|
|
|
if num > 5 then
|
|
|
|
break;
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
2016-08-05 15:06:15 +02:00
|
|
|
local imdb_id = data.Search[num].imdbID
|
|
|
|
local movie_info = imdb:get_imdb_info(imdb_id)
|
|
|
|
local title = movie_info.Title
|
|
|
|
local year = movie_info.Year
|
2016-08-05 15:20:08 +02:00
|
|
|
local text = '<b>'..movie_info.Title.. ' ('..movie_info.Year..')</b> von '..movie_info.Director..'\\n'..string.gsub(movie_info.imdbRating, '%.', ',')..'/10 | '..movie_info.Runtime..' | '.. movie_info.Genre
|
|
|
|
if movie_info.Plot then
|
|
|
|
text = text..'\\n<i>'..movie_info.Plot..'</i>'
|
|
|
|
description = movie_info.Plot
|
|
|
|
else
|
|
|
|
description = 'Keine Beschreibung verfügbar'
|
|
|
|
end
|
2016-08-05 15:06:15 +02:00
|
|
|
local text = text:gsub('"', '\\"')
|
2016-08-05 15:20:08 +02:00
|
|
|
local text = text:gsub("'", "\'")
|
2016-08-06 22:36:02 +02:00
|
|
|
local description = description:gsub('"', '\\"')
|
|
|
|
local description = description:gsub("'", "\'")
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
if movie_info.Poster == "N/A" then
|
|
|
|
img_url = 'https://anditest.perseus.uberspace.de/inlineQuerys/imdb/logo.jpg'
|
|
|
|
else
|
|
|
|
img_url = movie_info.Poster
|
|
|
|
end
|
2016-08-07 21:20:48 +02:00
|
|
|
results = results..'{"type":"article","id":"'..id..'","title":"'..title..' ('..year..')","description":"'..description..'","url":"http://imdb.com/title/'..imdb_id..'","hide_url":true,"thumb_url":"'..img_url..'","reply_markup":{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'..imdb_id..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}},'
|
|
|
|
id = id+1
|
2016-08-05 15:06:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local results = results:sub(0, -2)
|
|
|
|
local results = results..']'
|
2016-08-05 15:21:32 +02:00
|
|
|
utilities.answer_inline_query(self, inline_query, results, 10000)
|
2016-08-05 15:06:15 +02:00
|
|
|
end
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
function imdb:action(msg, config)
|
2016-08-14 16:30:06 +02:00
|
|
|
local input = utilities.input_from_msg(msg)
|
2016-08-05 15:06:15 +02:00
|
|
|
if not input then
|
2016-08-14 16:30:06 +02:00
|
|
|
utilities.send_reply(self, msg, imdb.doc, true)
|
|
|
|
return
|
2016-08-05 15:06:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local url = BASE_URL..'/?t='..URL.escape(input)
|
|
|
|
local jstr, res = https.request(url)
|
|
|
|
if res ~= 200 then
|
|
|
|
utilities.send_reply(self, msg, config.errors.connection)
|
|
|
|
return
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
local jdat = json.decode(jstr)
|
|
|
|
if jdat.Response ~= 'True' then
|
|
|
|
utilities.send_reply(self, msg, config.errors.results)
|
|
|
|
return
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
local output = '<b>'..jdat.Title.. ' ('..jdat.Year..')</b> von '..jdat.Director..'\n'
|
|
|
|
output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n'
|
|
|
|
output = output..'<i>' .. jdat.Plot .. '</i>'
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
utilities.send_reply(self, msg, output, 'HTML', '{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'.. jdat.imdbID..'"}]]}')
|
|
|
|
|
|
|
|
if jdat.Poster ~= "N/A" then
|
|
|
|
local file = download_to_file(jdat.Poster)
|
|
|
|
utilities.send_photo(self, msg.chat.id, file)
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
return imdb
|