[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:52:09 CET 2011


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

Lua: fix Allocine extension

It was broken a looong time ago because the XML structure
of their web page is broken
(cherry picked from commit e9196c3fc2ca2daf438c1fd90bd10f8404fd4f4a)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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