[vlc-commits] commit: Lua: fix Allocine extension ( =?UTF-8?Q?Jean=2DPhilippe=20Andr=C3=A9=20?=)

git at videolan.org git at videolan.org
Mon Jan 17 17:49:06 CET 2011


vlc | branch: master | Jean-Philippe André <jpeg at videolan.org> | Sat Jan 15 21:35:17 2011 +0100| [e9196c3fc2ca2daf438c1fd90bd10f8404fd4f4a] | committer: Jean-Philippe André 

Lua: fix Allocine extension

It was broken a looong time ago because the XML structure
of their web page is broken

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9196c3fc2ca2daf438c1fd90bd10f8404fd4f4a
---

 share/lua/extensions/allocine-fr.lua |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/share/lua/extensions/allocine-fr.lua b/share/lua/extensions/allocine-fr.lua
index e3637c1..7388707 100644
--- a/share/lua/extensions/allocine-fr.lua
+++ b/share/lua/extensions/allocine-fr.lua
@@ -172,6 +172,9 @@ function click_chercher()
             -- Read <table> tag as xml
             local substring = string.sub(data, first, last or -1)
 
+            -- Fix Allocine's broken XML (!!!)
+            substring = string.gsub(substring, "<div class=\"spacer vmargin10\">", "")
+
             local xml = simplexml.parse_string(substring)
             for _, tr in ipairs(xml.children) do
                 -- Get film title & year
@@ -317,18 +320,15 @@ function open_fiche(url)
     local synopsis = string.gsub(sub, ".*Synopsis :(.*)", "<h2>Synposis</h2>%1")
 
     -- Note
-    first, _ = string.find(data, "Note Moyenne:")
-    if first then
-        local _, note = string.find(data, "span class=\"lighten\">%(", first)
-        if note then
-            note = string.sub(data, note+1, note+3)
-            note = string.gsub(note, "%).*$", "")
-            page = page .. "Note moyenne: <b>" .. note .. " / 4</b>"
-            local nbpeople = string.gsub(data, ".*pour (%d+) notes.*", "%1")
-            if nbpeople then
-                page = page .. " (" .. nbpeople .. " votes)"
-            end
+    for w in string.gmatch(data, "property=\"v:average\"[^>]*>([^<]+)</span>") do
+        local note = trim(w)
+        page = page .. "Note moyenne: <b>" .. note .. " / 4</b>"
+        for y in string.gmatch(data, "property=\"v:count\"[^>]*>([^<]+)</span>") do
+           local nbpeople = trim(y)
+           page = page .. " (" .. nbpeople .. " votes)"
+           break
         end
+        break
     end
 
     -- Synopsis



More information about the vlc-commits mailing list