]> git.sesse.net Git - vlc/commitdiff
Simplify and fix some lua scripts.
authorAntoine Cellerier <dionoea@videolan.org>
Fri, 12 Sep 2008 16:02:00 +0000 (18:02 +0200)
committerAntoine Cellerier <dionoea@videolan.org>
Fri, 12 Sep 2008 16:02:20 +0000 (18:02 +0200)
share/lua/meta/01_musicbrainz.lua
share/lua/playlist/appletrailers.lua
share/lua/playlist/break.lua
share/lua/playlist/canalplus.lua
share/lua/playlist/dailymotion.lua
share/lua/playlist/france2.lua
share/lua/playlist/googlevideo.lua
share/lua/playlist/megavideo.lua
share/lua/playlist/metacafe.lua
share/lua/playlist/youtube.lua

index 74f07e5155f7b30db82fce14af436fea50558ecc..a1ef0d79d4622fe3673fb7ac225719ce4438d687 100644 (file)
@@ -45,7 +45,7 @@ function fetch_art()
     local page = s:read( 65653 )
 
     -- FIXME: multiple results may be available
-    asin = string.gsub( page, "^.*<asin>([^<]*)</asin>.*$", "%1" )
+    _,_,asin = string.find( page, "<asin>(.-)</asin>" )
     if asin ~= page then
         return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
     else
index 0509d8f50ce501ad6624ac3927fd888125b53381..754425533adce83e066185c3dbefaf3aec1b63bd 100644 (file)
 -- Probe function.
 function probe()
     return vlc.access == "http"
-        and string.match( vlc.path, "trailers.apple.com" ) 
+        and string.match( vlc.path, "www.apple.com/trailers" ) 
+end
+
+function find( haystack, needle )
+    local _,_,r = string.find( haystack, needle )
+    return r
 end
 
 -- Parse function.
@@ -33,19 +38,17 @@ function parse()
     do 
         line = vlc.readline()
         if not line then break end
-        if string.match( line, "http://movies.apple.com/movies/.*%.mov" )
-        or string.match( line, "http://images.apple.com/movies/.*%.mov" )
-        then
-            if string.match( line, "http://movies.apple.com/movies/.*%.mov" ) then
-                path = vlc.strings.decode_uri( string.gsub( line, "^.*(http://movies.apple.com/movies/.*%.mov).*$", "%1" ) )
-            elseif string.match( line, "http://images.apple.com/movies/.*%.mov" ) then
-                path = vlc.strings.decode_uri( string.gsub( line, "^.*(http://images.apple.com/movies/.*%.mov).*$", "%1" ) )
-            end
-            if string.match( path, "480p" ) then
+        for path in string.gmatch( line, "http://movies.apple.com/movies/.-%.mov" ) do
+            path = vlc.strings.decode_uri( path )
+            if string.match( path, "320" ) then
+                extraname = " (320p)"
+            elseif string.match( path, "480" ) then
                 extraname = " (480p)"
-            elseif string.match( path, "720p" ) then
+            elseif string.match( path, "640" ) then
+                extraname = " (640p)"
+            elseif string.match( path, "720" ) then
                 extraname = " (720p)"
-            elseif string.match( path, "1080p" ) then
+            elseif string.match( path, "1080" ) then
                 extraname = " (1080p)"
             else
                 extraname = ""
@@ -54,11 +57,11 @@ function parse()
         end
         if string.match( line, "<title>" )
         then
-            title = vlc.strings.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) )
+            title = vlc.strings.decode_uri( find( line, "<title>(.-)<" ) )
         end
         if string.match( line, "<meta name=\"Description\"" )
         then
-            description = vlc.strings.resolve_xml_special_chars( string.gsub( line, "^.*name=\"Description\" content=\"([^\"]*)\".*$", "%1" ) )
+            description = vlc.strings.resolve_xml_special_chars( find( line, "name=\"Description\" content=\"(.-)\"" ) )
         end
     end
     return p
index 1c18a0c867efb212c52ab573e45e92da85ebaaa9..b14c087a2f1cd9d8f87a33bfc5e36a5030afcec6 100644 (file)
@@ -21,7 +21,7 @@
 -- Probe function.
 function probe()
     return vlc.access == "http"
-        and string.match( vlc.path, "www.break.com" ) 
+        and string.match( vlc.path, "break.com" ) 
 end
 
 -- Parse function.
@@ -34,19 +34,20 @@ function parse()
         line = vlc.readline()
         if not line then break end
         if string.match( line, "sGlobalContentFilePath=" ) then
-            filepath= string.gsub( line, ".*sGlobalContentFilePath='([^']*).*", "%1" )
+            _,_,filepath= string.find( line, "sGlobalContentFilePath='(.-)'" )
         end
         if string.match( line, "sGlobalFileName=" ) then
-            filename = string.gsub( line, ".*sGlobalFileName='([^']*).*", "%1")
+            _,_,filename = string.find( line, ".*sGlobalFileName='(.-)'")
         end
         if string.match( line, "sGlobalContentTitle=" ) then
-            filetitle = string.gsub( line, ".*sGlobalContentTitle='([^']*).*", "%1")
+            _,_,filetitle = string.find( line, "sGlobalContentTitle='(.-)'")
         end
         if string.match( line, "el=\"videothumbnail\" href=\"" ) then
-            arturl = string.gsub( line, ".*el=\"videothumbnail\" href=\"([^\"]*).*", "%1" )
+            _,_,arturl = string.find( line, "el=\"videothumbnail\" href=\"(.-)\"" )
         end
         if string.match( line, "videoPath" ) then
-            return { { path = ( string.gsub( line, ".*videoPath', '([^']*).*", "%1" ) )..filepath.."/"..filename..".flv"; title = filetitle; arturl = arturl } }
+            _,_,videopath = string.find( line, ".*videoPath', '(.-)'" )
+            return { { path = videopath..filepath.."/"..filename..".flv"; title = filetitle; arturl = arturl } }
         end
     end
 end
index 0605f7fa5f218d4cc5262ef92ab78e8b352d4e29..0b0af9a80bd3f119a8efbc7cc4d607d63b1e1e24 100644 (file)
@@ -27,8 +27,9 @@ end
 function parse()
     p = {}
     --vlc.msg.dbg( vlc.path )
-    if string.match( vlc.path, "www.canalplus.fr/index.php%?pid=" )
+    if string.match( vlc.path, "www.canalplus.fr/.*%?pid=.*" )
     then -- This is the HTML page's URL
+        local _,_,pid = string.find( vlc.path, "pid(%d-)%-" )
         local id, name, description, arturl
         while true do
             -- Try to find the video's title
@@ -37,12 +38,12 @@ function parse()
             -- vlc.msg.dbg( line )
             if string.match( line, "aVideos" ) then
                 if string.match( line, "CONTENT_ID.*=" ) then
-                    id = string.gsub( line, "^.*\"(.*)\".*$", "%1" )
+                    _,_,id = string.find( line, "\"(.-)\"" )
                 elseif string.match( line, "CONTENT_VNC_TITRE" ) then
-                    arturl = string.gsub( line, "^.*src=\"(.*)\".*$", "%1" )
-                    name = string.gsub( line, "^.*title=\"(.*)\".*$", "%1" )
+                    _,_,arturl = string.find( line, "src=\"(.-)\"" )
+                    _,_,name = string.find( line, "title=\"(.-)\"" )
                 elseif string.match( line, "CONTENT_VNC_DESCRIPTION" ) then
-                    description = string.gsub( line, "^.*\"(.*)\".*$", "%1" )
+                    _,_,description = string.find( line, "\"(.-)\"" )
                 end
                 if id and string.match( line, "new Array" ) then
                     add_item( p, id, name, description, arturl )
@@ -63,16 +64,16 @@ function parse()
             if not line then break end
             --vlc.msg.dbg( line )
             if string.match( line, "<hi" ) then
-                local path = string.gsub( line, "^.*%[(.-)%].*$", "%1" )
+                local _,_,path = string.find( line, "%[(http.-)%]" )
                 return { { path = path } }
             end
         end
-        vlc.msg.err( "canalplus: can't find video in page" )
     end
 end
 
 function get_url_param( url, name )
-    return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" )
+    local _,_,ret = string.find( url, "[&?]"..name.."=([^&]*)" )
+    return ret
 end
 
 function add_item( p, id, name, description, arturl )
index 009eb1372dfda1f679341b3000e4aa5b143afd30..e850bcf6c19c35325006cf17a70216bafe7aa6fc 100644 (file)
 function probe()
     return vlc.access == "http"
         and string.match( vlc.path, "dailymotion.com" ) 
-        and string.match( vlc.peek( 256 ), "<!DOCTYPE.*<title>Video " )
+        and string.match( vlc.peek( 2048 ), "<!DOCTYPE.*video_type" )
+end
+
+function find( haystack, needle )
+    local _,_,ret = string.find( haystack, needle )
+    return ret
 end
 
 -- Parse function.
@@ -36,8 +41,8 @@ function parse()
         if not line then break end
         if string.match( line, "param name=\"flashvars\" value=\".*video=" )
         then
-            arturl = vlc.strings.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*preview=([^&]*).*$", "%1" ) )
-            videos = vlc.strings.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*video=([^&]*).*$", "%1" ) )
+            arturl = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*preview=([^&]*)" ) )
+            videos = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*video=([^&]*)" ) )
        --[[ we get a list of different streams available, at various codecs
             and resolutions:
             /A@@spark||/B@@spark-mini||/C@@vp6-hd||/D@@vp6||/E@@h264
@@ -74,10 +79,13 @@ function parse()
                 path = "http://dailymotion.com" .. available[bestcodec]
             end
         end
+        if string.match( line, "<meta name=\"title\"" )
+        then
+            name = vlc.strings.resolve_xml_special_chars( find( line, "name=\"title\" content=\"(.-)\"" ) )
+        end
         if string.match( line, "<meta name=\"description\"" )
         then
-            name = vlc.strings.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ (.*) %w+ %w+ %w+ %w+ Videos\..*$", "%1" ) )
-            description = vlc.strings.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ .* %w+ %w+ %w+ %w+ Videos\. ([^\"]*)\".*$", "%1" ) )
+            description = vlc.strings.resolve_xml_special_chars( find( line, "name=\"description\" content=\"(.-)\"" ) )
         end
         if path and name and description and arturl then break end
     end
index 343f7a44548b6a81b18e356cd9ec04654e1079d6..3d9ad1e2468d4b5900535aefced0675bdf412ffa 100644 (file)
@@ -34,15 +34,16 @@ function parse()
         line = vlc.readline()
         if not line then break end
         if string.match( line, "class=\"editiondate\"" ) then
-            editiondate = string.gsub( line, "^.*<h1>(.*)</h1>.*$", "%1" )
+            _,_,editiondate = string.find( line, "<h1>(.-)</h1>" )
         end
         if string.match( line, "mms.*%.wmv" ) then
-            video = string.gsub( line, "^.*mms(.*%.wmv).*$", "mmsh%1" )
+            _,_,video = string.find( line, "mms(.-%.wmv)" )
+            video = "mmsh"..video
             table.insert( p, { path = video; name = editiondate } )
         end
         if string.match( line, "class=\"subjecttimer\"" ) then
             oldtime = time
-            time = string.gsub( line, "^.*href=\"([^\"]*)\".*$", "%1" )
+            _,_,time = string.find( line, "href=\"(.-)\"" )
             if oldtime then
                 table.insert( p, { path = video; name = name; duration = time - oldtime; options = { ':start-time='..tostring(oldtime); ':stop-time='..tostring(time) } } )
             end
index 8fe4648aac51660112249f799321e6961356b28c..dbb702cd120a50a3a22e3413f4e67e966bcc14ba 100644 (file)
@@ -19,7 +19,8 @@
 --]]
 
 function get_url_param( url, name )
-    return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" )
+    local _,_,ret = string.find( url, "[&?]"..name.."=([^&]*)" )
+    return ret
 end
 
 -- Probe function.
@@ -51,22 +52,22 @@ function parse()
             if not line then break end
             if string.match( line, "media:content.*flv" )
             then
-                local s = string.gsub( line, "^.*<media:content(.-)/>.*$", "%1" )
+                local _,_,s = string.find( line, "<media:content(.-)/>" )
                 path = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
                 duration = get_arg( s, "duration" )
             end
             if string.match( line, "media:thumbnail" )
             then
-                local s = string.gsub( line, "^.*<media:thumbnail(.-)/>.*$", "%1" )
+                local _,_,s = string.find( line, "<media:thumbnail(.-)/>" )
                 arturl = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
             end
             if string.match( line, "media:title" )
             then
-                name = string.gsub( line, "^.*<media:title>(.-)</media:title>.*$", "%1" )
+                _,_,name = string.find( line, "<media:title>(.-)</media:title>" )
             end
             if string.match( line, "media:description" )
             then
-                description = string.gsub( line, "^.*<media:description>(.-)</media:description>.*$", "%1" )
+                _,_,description = string.find( line, "<media:description>(.-)</media:description>" )
             end
         end
         return { { path = path; name = name; arturl = arturl; duration = duration; description = description } }
index 412e1d3d1a95e436cfc7603c76949f5333d0cc23..9048fff9528993b17d1521568d6143e930ee0757 100644 (file)
@@ -31,7 +31,7 @@ function parse()
 
     -- we have to get the xml
     if string.match( vlc.path, "www.megavideo.com.*&v=.*&u=.*" ) then
-        id = string.gsub( vlc.path, "www.megavideo.com.*v=([^&]*).*$", "%1" )
+        _,_,id = string.find( vlc.path, "www.megavideo.com.*v=([^&]*)" )
         path = "http://www.megavideo.com/xml/videolink.php?v=" .. id
         return { { path = path } }
     end
@@ -51,7 +51,7 @@ function parse()
                 line = vlc.readline()
             end
             -- now gets the encoded url
-            s = string.gsub( xml, ".*ROW url=\"([^\"]*).*", "%1" )
+            _,_,s = string.find( xml, ".*ROW url=\"(.-)\"" )
             path = ""
             i = 1
             while s:byte(i) do
index b7ceb3e851968838134f953d54e22fd2f44d3568..89a9a34ca0258cb2398379575ea777469f727c0c 100644 (file)
@@ -28,6 +28,7 @@ end
 
 -- Parse function.
 function parse()
+    vlc.msg.warn("FIXME")
     if string.match( vlc.path, "watch/" )
     then -- This is the HTML page's URL
         while true do
@@ -35,18 +36,19 @@ function parse()
             line = vlc.readline()
             if not line then break end
             if string.match( line, "<meta name=\"title\"" ) then
-                name = string.gsub( line, "^.*content=\"Metacafe %- ([^\"]*).*$", "%1" )  
+                _,_,name = string.find( line, "content=\"Metacafe %- (.-)\"" )  
             end
             if string.match( line, "<meta name=\"description\"" ) then
-                description = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )  
+                _,_,description = string.find( line, "content=\"(.-)\"" )  
             end
             if string.match( line, "<link rel=\"image_src\"" ) then
-                arturl = string.gsub( line, "^.*href=\"([^\"]*)\".*$", "%1" )
+                _,_,arturl = string.find( line, "href=\"(.-)\"" )
             end
             if name and description and arturl then break end
         end
         return { { path = string.gsub( vlc.path, "^.*watch/(.*[^/])/?$", "http://www.metacafe.com/fplayer/%1.swf" ); name = name; description = description; arturl = arturl;  } }
     else -- This is the flash player's URL
-        return { { path = string.gsub( vlc.path, "^.*mediaURL=([^&]*).*$", "%1" ) } }
+        local _,_,path = string.find( vlc.path, "mediaURL=([^&]*)" )
+        return { { path = path } }
     end
 end
index 0643c249be91d1f99be7a463e41aa32d979cd6ba..204b7ae7b01abfc66655a42a0538c0675a7b02c1 100644 (file)
@@ -20,7 +20,8 @@
 
 -- Helper function to get a parameter's value in a URL
 function get_url_param( url, name )
-    return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" )
+    local _, _, res = string.find( url, "[&?]"..name.."=([^&]*)" )
+    return res
 end
 
 function get_arturl( path, video_id )
@@ -62,22 +63,23 @@ function parse()
             line = vlc.readline()
             if not line then break end
             if string.match( line, "<meta name=\"title\"" ) then
-                name = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
+                _,_,name = string.find( line, "content=\"(.-)\"" )
             end
             if string.match( line, "<meta name=\"description\"" ) then
-                description = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
+               -- Don't ask me why they double encode ...
+                _,_,description = vlc.strings.resolve_xml_special_chars(vlc.strings.resolve_xml_special_chars(string.find( line, "content=\"(.-)\"" )))
             end
             if string.match( line, "subscribe_to_user=" ) then
-                artist = string.gsub( line, ".*subscribe_to_user=([^&]*).*", "%1" )
+                _,_,artist = string.find( line, "subscribe_to_user=([^&]*)" )
             end
             -- OLD: var swfArgs = {hl:'en',BASE_YT_URL:'http://youtube.com/',video_id:'XPJ7d8dq0t8',l:'292',t:'OEgsToPDskLFdOYrrlDm3FQPoQBYaCP1',sk:'0gnr-AE6QZJEZmCMd3lq_AC'};
             -- NEW: var swfArgs = { "BASE_YT_URL": "http://youtube.com", "video_id": "OHVvVmUNBFc", "l": 88, "sk": "WswKuJzDBsdD6oG3IakCXgC", "t": "OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp", "plid": "AARGnwWMrmGkbpOxAAAA4AT4IAA", "tk": "mEL4E7PqHeaZp5OG19NQThHt9mXJU4PbRTOw6lz9osHi4Hixp7RE1w=="};
             if string.match( line, "swfArgs" ) and string.match( line, "video_id" ) then
                 if string.match( line, "BASE_YT_URL" ) then
-                    base_yt_url = string.gsub( line, ".*\"BASE_YT_URL\": \"([^\"]*).*", "%1" )
+                    _,_,base_yt_url = string.find( line, "\"BASE_YT_URL\": \"(.-)\"" )
                 end
-                t = string.gsub( line, ".*\"t\": \"([^\"]*).*", "%1" )
-                -- vlc.msg_err( t )
+                _,_,t = string.find( line, "\"t\": \"(.-)\"" )
+                -- vlc.msg.err( t )
                 -- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" )
             end
             if name and description and artist --[[and video_id]] then break end