+ if not data then
+ vlc.msg.warn("[IMDb] Not data received!")
+ waitlbl:set_text('Sorry, an error occured while searching for <a href="'
+ .. url .. '">' .. title .. "</a>.<br />Please try again later.")
+ return
+ end
+
+ -- Probe result & parse it
+ if string.find(data, "<h6>Overview</h6>") then
+ -- We found a direct match
+ parse_moviepage(data)
+ else
+ -- We have a list of results to parse
+ parse_resultspage(data)
+ end
+end
+
+-- Called when clicked on the "Open" button
+function click_open()
+ -- Get user selection
+ selection = list:get_selection()
+ if not selection then return end
+
+ local sel = nil
+ for idx, selectedItem in pairs(selection) do
+ sel = idx
+ break
+ end
+ if not sel then return end
+ local imdbID = titles[sel].id
+
+ -- Update information message
+ url = "http://www.imdb.org/title/" .. imdbID .. "/"
+ title = titles[sel].title
+
+ dlg:del_widget(list)
+ dlg:del_widget(button_open)
+ list = nil
+ button_open = nil
+ waitlbl:set_text("Loading IMDb page for <a href=\"" .. url .. "\">" .. title .. "</a>.")
+ dlg:update()
+
+ local s, msg = vlc.stream(url)
+ if not s then
+ waitlbl:set_text('Sorry, an error occured while looking for <a href="'
+ .. url .. '">' .. title .. "</a>.")
+ vlc.msg.warn("[IMDb] " .. msg)
+ return
+ end
+
+ data = s:read(65000)
+ if data and string.find(data, "<h6>Overview</h6>") then
+ parse_moviepage(data)
+ else
+ waitlbl:set_text('Sorry, no results found for <a href="'
+ .. url .. '">' .. title .. "</a>.")
+ end
+end
+
+-- Parse the results page and find titles, years & URL's
+function parse_resultspage(data)
+ vlc.msg.dbg("[IMDb] Analysing results page")