--imdb.freedb.http-V.1.lua by chilla
--------------------------------------------------------------------------------------------------------------------------
bot = "IFINFO"
ifPrefix = "%!%+%-%?"
cmd1 = "imdb"
cmd2 = "freedb"
ifhelp = "\tPrefixa: ! - + ?\r\n\tSyntax: Prefix\""..cmd1.."\" Movie\r\n\tSyntax: Prefix\""..cmd2.."\" Artist\r\n\tSyntax: Prefix\""..cmd2.."\" Artist Album\r\n"
--------------------------------------------------------------------------------------------------------------------------
-- This shows also an album when search in freedb when set to value 1
showAlbum = 1
--------------------------------------------------------------------------------------------------------------------------
function DataArrival(curUser,data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind( data, "%b<>%s["..ifPrefix.."](%S+)" )
if (cmd and strlower(cmd) == strlower(cmd1)) then
local _,_,str1 = strfind(data,"%b<>%s+%S+%s+(.*)")
if str1 then
curUser:SendData(bot,GetImdbEntry(str1))
else
curUser:SendData(bot,ifhelp)
end
return 1
elseif (cmd and strlower(cmd) == strlower(cmd2)) then
local _,_,str1 = strfind(data,"%b<>%s+%S+%s+(.*)")
if str1 then
local sItem1 = gsub(str1,"%s","%+")
sItem1 = "freedb_search.php?words="..sItem1.."&allfields=NO&fields=artist&allcats=YES&grouping=none"
curUser:SendData(bot,GetFreeDBEntry(str1,sItem1))
else
curUser:SendData(bot,ifhelp)
end
return 1
end
end
end
--------------------------------------------------------------------------------------------------------------------------
-- **FUNCS**
--------------------------------------------------------------------------------------------------------------------------
function GetFreeDBEntry(str1,shttp,ret)
local set,httpn,sAlbum,host = 0,"","","www.freedb.org"
GETHTML = "GET /"..shttp.." HTTP/1.1\r\nHost: "..host.."\r\nUser-Agent: Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
socket, e = connect(host, 80)
local msg = ""
local msg2 = ""
if not e then
local line = ""
socket:timeout(2)
socket:send(GETHTML..strchar(13,10))
local handle = openfile("test2.html","w")
while not e do
line1, e = socket:receive("*l")
write(handle,line1.."\r\n")
if strfind(line1,"(.*)
") then
_,_,sAlbum = strfind(line1,"(.*)
")
end
if line1 == "" then
while line1 ~= "
" do
line1, e = socket:receive("*l")
write(handle,line1.."\r\n")
if strfind(line1, "(.*)
") then
local _,_, httpt,sname = strfind(line1, "(.*)
")
if set == 0 then
httpn = httpt
set = 1
end
msg = msg.."\tAlbum: "..sname.." Site: http://www.freedb.org/"..httpt.."\r\n"
end
if strfind(line1,"(.*)%. %s(%S+) (.*)") then
local _,_,track,length,title = strfind(line1," (.*)%. %s(%S+) (.*)")
msg2 = msg2.."\t"..track..". "..title.." ( "..length.." )\r\n"
end
end
end
end
closefile(handle)
socket:close()
end
print(e,i)
if set == 1 and showAlbum == 1 then
msg = msg.."\r\n\r\n"..GetFreeDBEntry("X",httpn,1)
end
if msg ~="" then
msg = "\tSearchItem : "..str1.."\r\n\r\n"..msg
end
if msg2 ~= "" then
msg2 = "\tAlbum: "..sAlbum.."\r\n\r\n"..msg2
end
if ret == 1 then
return msg2
else
return msg
end
end
--------------------------------------------------------------------------------------------------------------------------
function GetImdbEntry(sItem)
GETHTML = "GET /Tsearch?title="..sItem.." HTTP/1.1\r\nHost: www.imdb.com\r\nUser-Agent: Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
socket, e = connect("www.imdb.com", 80)
local msg = "\r\n"
if not e then
local line = ""
socket:timeout(2)
socket:send(GETHTML..strchar(13,10))
local handle = openfile("test.html","w")
while not e do
line1, e = socket:receive("*l")
write(handle,line1.."\r\n")
if line1 == "Movies
" then
line1, e = socket:receive("*l")
write(handle,line1.."\r\n")
while line1 ~= "" do
_,_,httpt,mname = strfind(line1,".*=\"(%S+)\">(.*).*")
if httpt and mname then
msg = msg.."\t"..mname.." Site: http://www.imdb.com"..httpt.."\r\n"
end
line1, e = socket:receive("*l")
write(handle,line1.."\r\n")
end
end
end
closefile(handle)
socket:close()
end
return "\tSearched Movie: "..sItem.."\r\n\r\n\tResults:\r\n"..msg
end
Title:
Post by: c h i l l a on 13 February, 2004, 21:15:22
just a little update, for google type
+google search
will only check google.de hope it works
Code Select --imdb.freedb.http-V.1.3.lua by chilla
--------------------------------------------------------------------------------------------------------------------------
bot = "IFINFO"
ifPrefix = "%!%+%-%?"
cmd1 = "imdb"
cmd2 = "freedb"
cmd3 = "google"
ihelp = "\tPrefixes: ! - + ?\r\n\r\n\tSyntax: Prefix\""..cmd1.."\" Movie\r\n"
fhelp = "\tPrefixes: ! - + ?\r\n\r\n\tSyntax: Prefix\""..cmd2.."\" Artist:Album\r\n\tSyntax: Prefix\""..cmd2.."\" Category Artist:Album\r\n"
--------------------------------------------------------------------------------------------------------------------------
-- This shows also an album when search in freedb when set to value 1
showAlbum = 1
--This is the maxiumum Socket Timeout time you want to have.
TMax = 3
--------------------------------------------------------------------------------------------------------------------------
Cats = { "blues","classical","country","data","folk","jazz","misc","newage","reggae","rock","soundtrack" }
--------------------------------------------------------------------------------------------------------------------------
function DataArrival(curUser,data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind( data, "%b<>%s["..ifPrefix.."](%S+)" )
if (cmd and strlower(cmd) == strlower(cmd1)) then
local _,_,str1 = strfind(data,"%b<>%s+%S+%s+(.*)")
if str1 then
curUser:SendData(bot,GetImdbEntry(str1))
else
curUser:SendData(bot,ihelp)
end
return 1
elseif (cmd and strlower(cmd) == strlower(cmd3)) then
local _,_,str1 = strfind(data,"%b<>%s+%S+%s+(.*)")
if str1 then
curUser:SendData(bot,GetGoogleEntry(str1))
else
curUser:SendData(bot,ihelp)
end
return 1
elseif (cmd and strlower(cmd) == strlower(cmd2)) then
local _,_,str1 = strfind(data,"%b<>%s+%S+%s+(.*)")
if str1 then
local sItem1 = gsub(str1,"%s","%+")
sItem1 = "freedb_search.php?words="..sItem1.."&allfields=NO&fields=artist&fields=title&allcats=YES&grouping=none"
if strfind(data,"%b<>%s+%S+%s+(%S+)%s+.*") then
_,_,str2,str3 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
local link = foreach(Cats, function(_,b)
if strlower(str2) == b then
local sItem1 = gsub(str3,"%s","%+")
return "freedb_search.php?words="..sItem1.."&allfields=NO&fields=artist&fields=title&allcats=NO&cats="..b.."&grouping=none"
end
end)
if link then
curUser:SendData(bot,"Category : "..str2.."\r\n\r\n"..GetFreeDBEntry(str3,link))
else
curUser:SendData(bot,GetFreeDBEntry(str1,sItem1))
end
str2,str3 = nil,nil
else
curUser:SendData(bot,GetFreeDBEntry(str1,sItem1))
end
else
curUser:SendData(bot,fhelp)
end
return 1
end
end
end
--------------------------------------------------------------------------------------------------------------------------
-- **FUNCS**
--------------------------------------------------------------------------------------------------------------------------
function GetFreeDBEntry(str1,shttp,ret)
local set,httpn,sAlbum,host,genre,year,tracks,ttime = 0,"","","www.freedb.org","-","-","-","-"
GETHTML = "GET /"..shttp.." HTTP/1.1\r\nHost: "..host.."\r\nUser-Agent: Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
socket, e = connect(host, 80)
local msg = ""
local msg2 = ""
if not e then
local line1 = ""
socket:timeout(TMax)
socket:send(GETHTML..strchar(13,10))
while not e do
line1, e = socket:receive("*l")
if ret == 1 and strfind(line1,"(.*)
") then
_,_,sAlbum = strfind(line1,"(.*)
")
elseif ret == 1 and strfind(line1,"genre:%s+(%S+)
") then
_,_,genre = strfind(line1,"genre:%s+(%S+)
")
elseif ret == 1 and strfind(line1,"total time:%s+(%S+)
") then
_,_,ttime = strfind(line1,"total time:%s+(%S+)
")
elseif ret == 1 and strfind(line1,"tracks:%s+(%d+)
") then
_,_,tracks = strfind(line1,"tracks:%s+(%d+)
")
elseif ret == 1 and strfind(line1,"year:%s+(%d+)
") then
_,_,year = strfind(line1,"year:%s+(%d+)
")
end
if line1 == "" then
while line1 ~= "
" do
line1, e = socket:receive("*l")
if strfind(line1, "(.*)
") then
local _,_, httpt,sname = strfind(line1, "(.*)
")
local _,_,genre = strfind(httpt,"%?cat=(%a+)&")
genre = strupper(strsub(genre,1,1))..strsub(genre,2,strlen(genre))
if set == 0 then
httpn = httpt
set = 1
end
msg = msg.."\tGenre: "..genre.." :: "..sname.." :: Link: [URL]http://www.freedb.org/[/URL]"..httpt.."\r\n"
elseif ret == 1 and strfind(line1,"(.*)%. %s(%S+) (.*)") then
local _,_,track,length,title = strfind(line1," (.*)%. %s(%S+) (.*)")
msg2 = msg2.."\t"..track..". "..title.." ( "..length.." )\r\n"
end
end
break
end
end
socket:close()
else
return "\tServer: "..host.." is currently offline."
end
if set == 1 and showAlbum == 1 then
msg = msg.."\t_______________________\r\n\r\n"..GetFreeDBEntry("X",httpn,1)
end
if msg ~="" then
msg = "\tSearchItem : "..str1.."\r\n\r\n"..msg
else
msg = "\tNothing found for: "..str1.."\r\n"
end
if msg2 ~= "" then
msg2 = "\tAlbum: "..sAlbum.."\r\n\tGenre: "..genre..", Year: "..year..", Tracks: "..tracks..", Total Time: "..ttime.."\r\n\r\n"..msg2
end
if ret == 1 then
return msg2
else
return msg
end
end
--------------------------------------------------------------------------------------------------------------------------
function GetImdbEntry(sItem)
local sItem1 = gsub(sItem," ","%%20")
GETHTML = "GET /find?tt=on;nm=on;mx=20;q="..sItem1.." HTTP/1.1\r\nHost: [URL]www.imdb.com\r\nUser-Agent:[/URL] Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
socket, e = connect("www.imdb.com", 80)
local msg = "\r\n"
if not e then
local line1 = ""
socket:timeout(TMax)
socket:send(GETHTML..strchar(13,10))
while (not e) and (line1) do
line1, e = socket:receive("*l")
if strsub(line1,3,22) == "Exact Matches" then
line1, e = socket:receive("*l")
while (not e) and (line1 ~= " ") do
local _,_,httpt,mname = strfind(line1,"^ 1. (.*) ")
if httpt and mname then
msg = msg.."\t"..mname.." :: Link: [URL]http://www.imdb.com[/URL]"..httpt.."\r\n"
end
line1, e = socket:receive("*l")
end
break
end
end
socket:close()
else
return "\tServer: [URL]www.imdb.com[/URL] is currently offline."
end
if msg ~="\r\n" then
return "\tSearched Movie: "..sItem.."\r\n\tResults:\r\n"..msg
else
return "\tNothing found for: "..sItem.."\r\n"
end
end
--------------------------------------------------------------------------------------------------------------------------
function GetGoogleEntry(sItem)
local sItem1 = gsub(sItem," ","+")
GETHTML = "GET /search?q="..sItem1.."&ie=UTF-8&oe=UTF-8&hl=de&btnG=Google+Suche HTTP/1.1\r\nHost: [URL]www.google.de\r\nUser-Agent:[/URL] Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
socket, e = connect("www.google.de", 80)
local msg = "\r\n"
if not e then
local line1 = ""
socket:timeout(TMax)
socket:send(GETHTML..strchar(13,10))
while (not e) and (line1) do
line1, e = socket:receive("*l")
if strfind(line1,"(.*)") then
local _,_,text1,text2 = strfind(line1,"
(.*)")
text1 = gsub(text1,"[<>]","")
text1 = gsub(text1,"/b","/")
text2 = gsub(text2,"%b<>","")
msg = msg.."\t- "..text2.."\r\n\tLink: "..text1.."\r\n\r\n"
elseif strfind(line1,"