diff --git a/plugins/imdb.lua b/plugins/imdb.lua new file mode 100644 index 0000000..1387e4d --- /dev/null +++ b/plugins/imdb.lua @@ -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 \ No newline at end of file diff --git a/plugins/pluginsold/imdb.lua b/plugins/pluginsold/imdb.lua deleted file mode 100644 index 026e595..0000000 --- a/plugins/pluginsold/imdb.lua +++ /dev/null @@ -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 \ No newline at end of file