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 = '['
|
|
|
|
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
|
|
|
|
local description = movie_info.Plot
|
|
|
|
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..'\\n<i>' .. movie_info.Plot .. '</i>'
|
|
|
|
local text = text: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
|
|
|
|
results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","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"}},'
|
|
|
|
end
|
|
|
|
|
|
|
|
local results = results:sub(0, -2)
|
|
|
|
local results = results..']'
|
|
|
|
utilities.answer_inline_query(self, inline_query, results, 10000)
|
|
|
|
end
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-08-05 15:06:15 +02:00
|
|
|
function imdb:action(msg, config)
|
|
|
|
local input = utilities.input(msg.text)
|
|
|
|
if not input then
|
|
|
|
if msg.reply_to_message and msg.reply_to_message.text then
|
|
|
|
input = msg.reply_to_message.text
|
|
|
|
else
|
|
|
|
utilities.send_message(self, msg.chat.id, imdb.doc, true, msg.message_id, true)
|
|
|
|
return
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
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
|