new plugin imdb.lua

This commit is contained in:
Akamaru 2015-09-11 17:34:28 +02:00
parent 2bc1afcd3d
commit e8a5cf7b26
2 changed files with 64 additions and 34 deletions

64
plugins/imdb.lua Normal file
View File

@ -0,0 +1,64 @@
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

View File

@ -1,34 +0,0 @@
do
local function imdb(movie)
local http = require("socket.http")
local movie = movie:gsub(' ', '+')
local url = "http://www.imdbapi.com/?t=" .. movie
local response, code, headers = http.request(url)
if code ~= 200 then
return "Error: " .. code
end
if #response > 0 then
local r = json:decode(response)
r['Url'] = "http://imdb.com/title/" .. r.imdbID
local t = ""
for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end
return t:sub(1, -3)
end
return nil
end
local function run(msg, matches)
return imdb(matches[1])
end
return {
description = "IMDB plugin for telegram",
usage = "!imdb [movie]",
patterns = {"^!imdb (.+)"},
run = run
}
end