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

76 lines
2.5 KiB
Lua
Raw Normal View History

2015-09-11 17:34:28 +02:00
do
2015-11-12 17:42:03 +01:00
local BASE_URL = 'https://www.omdbapi.com'
2015-09-11 17:34:28 +02:00
2015-11-12 17:42:03 +01:00
function get_imdb_data (movie, id)
if id then
url = BASE_URL..'/?i=tt'..movie
else
url = BASE_URL..'/?t='..movie
end
local res,code = https.request(url)
2015-09-11 17:34:28 +02:00
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
2015-11-12 17:42:03 +01:00
if data.Type ~= "movie" then Type = '\nTyp: '..data.Type else Type = '' end
2015-09-11 17:34:28 +02:00
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
2015-11-12 17:42:03 +01:00
local text = title..Type..'\nErscheinungsdatm: '..release..runtime..genre..'\nDirector: '..director..writer..'\nSchauspieler: '..actors..plot..score..'\n-- '..link
if data.Poster ~= "N/A" then
2015-09-11 17:34:28 +02:00
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)
2015-11-12 17:42:03 +01:00
if matches[2] then
local movie = matches[2]
data = get_imdb_data(movie, true)
else
local movie = url_encode(matches[1]:gsub(' ', '+'))
data = get_imdb_data(movie, nil)
end
2015-09-11 17:34:28 +02:00
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",
2015-11-12 17:42:03 +01:00
patterns = {"^/imdb (.+)",
"imdb.com/title/(tt)(%d+[%d%.,]*)"
},
2015-09-11 17:34:28 +02:00
run = run
}
end