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/imdb.lua
2015-09-11 17:34:28 +02:00

64 lines
2.2 KiB
Lua

do
local BASE_URL = 'http://www.imdbapi.com'
function get_imdb_data (movie)
local url = BASE_URL..'/?t='..movie
local res,code = http.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json:decode(res)
return data
end
function send_imdb_data(data, receiver)
if data.Response == "False" then
text = 'Film nicht gefunden!'
send_msg(receiver, text, ok_cb, false)
else
local title = data.Title
local release = data.Released
if data.Runtime ~= "N/A" then runtime = '\nLaufzeit: '..data.Runtime else runtime = '' end
if data.Genre ~= "N/A" then genre = '\nGenre: '..data.Genre else genre = '' end
local director = data.Director
if data.Writer ~= "N/A" then writer = '\nWriter: '..data.Writer else writer = '' end
local actors = data.Actors
if data.Plot ~= "N/A" then plot = '\nStory: '..data.Plot else plot = '' end
if data.Metascore ~= "N/A" and data.imdbRating ~= "N/A" then
score = '\nBewertung: '..data.Metascore..' Metascore-Punkte und '..data.imdbRating..' von 10 Punkten von '..data.imdbVotes..' Votes auf IMDB'
elseif data.Metascore ~= "N/A" and data.imdbRating == "N/A" then
score = '\nBewertung: '..data.Metascore..' Metascore-Punkte'
elseif data.Metascore == "N/A" and data.imdbRating ~= "N/A" then
score = '\nBewertung: '..data.imdbRating..' von 10 Punkten von '..data.imdbVotes..' Votes auf IMDB'
else
score = ''
end
local link = 'http://imdb.com/title/'..data.imdbID
local text = title..'\nErscheinungsdatm: '..release..runtime..genre..'\nDirector: '..director..writer..'\nSchauspieler: '..actors..plot..score..'\n-- '..link
if data.Poster ~= "N/A" then
local image_url = data.Poster
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
end
function run(msg, matches)
local movie = matches[1]:gsub(' ', '+')
local data = get_imdb_data(movie)
local receiver = get_receiver(msg)
send_imdb_data(data, receiver)
end
return {
description = "Zeigt Info zu einem Film (von IMDB, englisch)",
usage = "/imdb [Film]: Zeigt Info zu Film",
patterns = {"^/imdb (.+)"},
run = run
}
end