Commit eebbc711 authored by Antoine Cellerier's avatar Antoine Cellerier

Simplify and fix some lua scripts.

(cherry picked from commit 90199a69)
parent 95320ee3
...@@ -45,7 +45,7 @@ function fetch_art() ...@@ -45,7 +45,7 @@ function fetch_art()
local page = s:read( 65653 ) local page = s:read( 65653 )
-- FIXME: multiple results may be available -- FIXME: multiple results may be available
asin = string.gsub( page, "^.*<asin>([^<]*)</asin>.*$", "%1" ) _,_,asin = string.find( page, "<asin>(.-)</asin>" )
if asin ~= page then if asin ~= page then
return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg" return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
else else
......
...@@ -23,7 +23,12 @@ ...@@ -23,7 +23,12 @@
-- Probe function. -- Probe function.
function probe() function probe()
return vlc.access == "http" 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 end
-- Parse function. -- Parse function.
...@@ -33,19 +38,17 @@ function parse() ...@@ -33,19 +38,17 @@ function parse()
do do
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if string.match( line, "http://movies.apple.com/movies/.*%.mov" ) for path in string.gmatch( line, "http://movies.apple.com/movies/.-%.mov" ) do
or string.match( line, "http://images.apple.com/movies/.*%.mov" ) path = vlc.strings.decode_uri( path )
then if string.match( path, "320" ) then
if string.match( line, "http://movies.apple.com/movies/.*%.mov" ) then extraname = " (320p)"
path = vlc.strings.decode_uri( string.gsub( line, "^.*(http://movies.apple.com/movies/.*%.mov).*$", "%1" ) ) elseif string.match( path, "480" ) then
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
extraname = " (480p)" extraname = " (480p)"
elseif string.match( path, "720p" ) then elseif string.match( path, "640" ) then
extraname = " (640p)"
elseif string.match( path, "720" ) then
extraname = " (720p)" extraname = " (720p)"
elseif string.match( path, "1080p" ) then elseif string.match( path, "1080" ) then
extraname = " (1080p)" extraname = " (1080p)"
else else
extraname = "" extraname = ""
...@@ -54,11 +57,11 @@ function parse() ...@@ -54,11 +57,11 @@ function parse()
end end
if string.match( line, "<title>" ) if string.match( line, "<title>" )
then then
title = vlc.strings.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) ) title = vlc.strings.decode_uri( find( line, "<title>(.-)<" ) )
end end
if string.match( line, "<meta name=\"Description\"" ) if string.match( line, "<meta name=\"Description\"" )
then 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
end end
return p return p
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
-- Probe function. -- Probe function.
function probe() function probe()
return vlc.access == "http" return vlc.access == "http"
and string.match( vlc.path, "www.break.com" ) and string.match( vlc.path, "break.com" )
end end
-- Parse function. -- Parse function.
...@@ -34,19 +34,20 @@ function parse() ...@@ -34,19 +34,20 @@ function parse()
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if string.match( line, "sGlobalContentFilePath=" ) then if string.match( line, "sGlobalContentFilePath=" ) then
filepath= string.gsub( line, ".*sGlobalContentFilePath='([^']*).*", "%1" ) _,_,filepath= string.find( line, "sGlobalContentFilePath='(.-)'" )
end end
if string.match( line, "sGlobalFileName=" ) then if string.match( line, "sGlobalFileName=" ) then
filename = string.gsub( line, ".*sGlobalFileName='([^']*).*", "%1") _,_,filename = string.find( line, ".*sGlobalFileName='(.-)'")
end end
if string.match( line, "sGlobalContentTitle=" ) then if string.match( line, "sGlobalContentTitle=" ) then
filetitle = string.gsub( line, ".*sGlobalContentTitle='([^']*).*", "%1") _,_,filetitle = string.find( line, "sGlobalContentTitle='(.-)'")
end end
if string.match( line, "el=\"videothumbnail\" href=\"" ) then if string.match( line, "el=\"videothumbnail\" href=\"" ) then
arturl = string.gsub( line, ".*el=\"videothumbnail\" href=\"([^\"]*).*", "%1" ) _,_,arturl = string.find( line, "el=\"videothumbnail\" href=\"(.-)\"" )
end end
if string.match( line, "videoPath" ) then 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 end
end end
...@@ -27,8 +27,9 @@ end ...@@ -27,8 +27,9 @@ end
function parse() function parse()
p = {} p = {}
--vlc.msg.dbg( vlc.path ) --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 then -- This is the HTML page's URL
local _,_,pid = string.find( vlc.path, "pid(%d-)%-" )
local id, name, description, arturl local id, name, description, arturl
while true do while true do
-- Try to find the video's title -- Try to find the video's title
...@@ -37,12 +38,12 @@ function parse() ...@@ -37,12 +38,12 @@ function parse()
-- vlc.msg.dbg( line ) -- vlc.msg.dbg( line )
if string.match( line, "aVideos" ) then if string.match( line, "aVideos" ) then
if string.match( line, "CONTENT_ID.*=" ) 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 elseif string.match( line, "CONTENT_VNC_TITRE" ) then
arturl = string.gsub( line, "^.*src=\"(.*)\".*$", "%1" ) _,_,arturl = string.find( line, "src=\"(.-)\"" )
name = string.gsub( line, "^.*title=\"(.*)\".*$", "%1" ) _,_,name = string.find( line, "title=\"(.-)\"" )
elseif string.match( line, "CONTENT_VNC_DESCRIPTION" ) then elseif string.match( line, "CONTENT_VNC_DESCRIPTION" ) then
description = string.gsub( line, "^.*\"(.*)\".*$", "%1" ) _,_,description = string.find( line, "\"(.-)\"" )
end end
if id and string.match( line, "new Array" ) then if id and string.match( line, "new Array" ) then
add_item( p, id, name, description, arturl ) add_item( p, id, name, description, arturl )
...@@ -63,16 +64,16 @@ function parse() ...@@ -63,16 +64,16 @@ function parse()
if not line then break end if not line then break end
--vlc.msg.dbg( line ) --vlc.msg.dbg( line )
if string.match( line, "<hi" ) then if string.match( line, "<hi" ) then
local path = string.gsub( line, "^.*%[(.-)%].*$", "%1" ) local _,_,path = string.find( line, "%[(http.-)%]" )
return { { path = path } } return { { path = path } }
end end
end end
vlc.msg.err( "canalplus: can't find video in page" )
end end
end end
function get_url_param( url, name ) function get_url_param( url, name )
return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" ) local _,_,ret = string.find( url, "[&?]"..name.."=([^&]*)" )
return ret
end end
function add_item( p, id, name, description, arturl ) function add_item( p, id, name, description, arturl )
......
...@@ -25,7 +25,12 @@ ...@@ -25,7 +25,12 @@
function probe() function probe()
return vlc.access == "http" return vlc.access == "http"
and string.match( vlc.path, "dailymotion.com" ) 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 end
-- Parse function. -- Parse function.
...@@ -36,8 +41,8 @@ function parse() ...@@ -36,8 +41,8 @@ function parse()
if not line then break end if not line then break end
if string.match( line, "param name=\"flashvars\" value=\".*video=" ) if string.match( line, "param name=\"flashvars\" value=\".*video=" )
then then
arturl = vlc.strings.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*preview=([^&]*).*$", "%1" ) ) arturl = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*preview=([^&]*)" ) )
videos = vlc.strings.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*video=([^&]*).*$", "%1" ) ) videos = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*video=([^&]*)" ) )
--[[ we get a list of different streams available, at various codecs --[[ we get a list of different streams available, at various codecs
and resolutions: and resolutions:
/A@@spark||/B@@spark-mini||/C@@vp6-hd||/D@@vp6||/E@@h264 /A@@spark||/B@@spark-mini||/C@@vp6-hd||/D@@vp6||/E@@h264
...@@ -74,10 +79,13 @@ function parse() ...@@ -74,10 +79,13 @@ function parse()
path = "http://dailymotion.com" .. available[bestcodec] path = "http://dailymotion.com" .. available[bestcodec]
end end
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\"" ) if string.match( line, "<meta name=\"description\"" )
then 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( find( line, "name=\"description\" content=\"(.-)\"" ) )
description = vlc.strings.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ .* %w+ %w+ %w+ %w+ Videos\. ([^\"]*)\".*$", "%1" ) )
end end
if path and name and description and arturl then break end if path and name and description and arturl then break end
end end
......
...@@ -34,15 +34,16 @@ function parse() ...@@ -34,15 +34,16 @@ function parse()
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if string.match( line, "class=\"editiondate\"" ) then if string.match( line, "class=\"editiondate\"" ) then
editiondate = string.gsub( line, "^.*<h1>(.*)</h1>.*$", "%1" ) _,_,editiondate = string.find( line, "<h1>(.-)</h1>" )
end end
if string.match( line, "mms.*%.wmv" ) then 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 } ) table.insert( p, { path = video; name = editiondate } )
end end
if string.match( line, "class=\"subjecttimer\"" ) then if string.match( line, "class=\"subjecttimer\"" ) then
oldtime = time oldtime = time
time = string.gsub( line, "^.*href=\"([^\"]*)\".*$", "%1" ) _,_,time = string.find( line, "href=\"(.-)\"" )
if oldtime then if oldtime then
table.insert( p, { path = video; name = name; duration = time - oldtime; options = { ':start-time='..tostring(oldtime); ':stop-time='..tostring(time) } } ) table.insert( p, { path = video; name = name; duration = time - oldtime; options = { ':start-time='..tostring(oldtime); ':stop-time='..tostring(time) } } )
end end
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
--]] --]]
function get_url_param( url, name ) function get_url_param( url, name )
return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" ) local _,_,ret = string.find( url, "[&?]"..name.."=([^&]*)" )
return ret
end end
-- Probe function. -- Probe function.
...@@ -51,22 +52,22 @@ function parse() ...@@ -51,22 +52,22 @@ function parse()
if not line then break end if not line then break end
if string.match( line, "media:content.*flv" ) if string.match( line, "media:content.*flv" )
then 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" )) path = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
duration = get_arg( s, "duration" ) duration = get_arg( s, "duration" )
end end
if string.match( line, "media:thumbnail" ) if string.match( line, "media:thumbnail" )
then 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" )) arturl = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
end end
if string.match( line, "media:title" ) if string.match( line, "media:title" )
then then
name = string.gsub( line, "^.*<media:title>(.-)</media:title>.*$", "%1" ) _,_,name = string.find( line, "<media:title>(.-)</media:title>" )
end end
if string.match( line, "media:description" ) if string.match( line, "media:description" )
then then
description = string.gsub( line, "^.*<media:description>(.-)</media:description>.*$", "%1" ) _,_,description = string.find( line, "<media:description>(.-)</media:description>" )
end end
end end
return { { path = path; name = name; arturl = arturl; duration = duration; description = description } } return { { path = path; name = name; arturl = arturl; duration = duration; description = description } }
......
...@@ -31,7 +31,7 @@ function parse() ...@@ -31,7 +31,7 @@ function parse()
-- we have to get the xml -- we have to get the xml
if string.match( vlc.path, "www.megavideo.com.*&v=.*&u=.*" ) then 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 path = "http://www.megavideo.com/xml/videolink.php?v=" .. id
return { { path = path } } return { { path = path } }
end end
...@@ -51,7 +51,7 @@ function parse() ...@@ -51,7 +51,7 @@ function parse()
line = vlc.readline() line = vlc.readline()
end end
-- now gets the encoded url -- now gets the encoded url
s = string.gsub( xml, ".*ROW url=\"([^\"]*).*", "%1" ) _,_,s = string.find( xml, ".*ROW url=\"(.-)\"" )
path = "" path = ""
i = 1 i = 1
while s:byte(i) do while s:byte(i) do
......
...@@ -28,6 +28,7 @@ end ...@@ -28,6 +28,7 @@ end
-- Parse function. -- Parse function.
function parse() function parse()
vlc.msg.warn("FIXME")
if string.match( vlc.path, "watch/" ) if string.match( vlc.path, "watch/" )
then -- This is the HTML page's URL then -- This is the HTML page's URL
while true do while true do
...@@ -35,18 +36,19 @@ function parse() ...@@ -35,18 +36,19 @@ function parse()
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if string.match( line, "<meta name=\"title\"" ) then if string.match( line, "<meta name=\"title\"" ) then
name = string.gsub( line, "^.*content=\"Metacafe %- ([^\"]*).*$", "%1" ) _,_,name = string.find( line, "content=\"Metacafe %- (.-)\"" )
end end
if string.match( line, "<meta name=\"description\"" ) then if string.match( line, "<meta name=\"description\"" ) then
description = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" ) _,_,description = string.find( line, "content=\"(.-)\"" )
end end
if string.match( line, "<link rel=\"image_src\"" ) then if string.match( line, "<link rel=\"image_src\"" ) then
arturl = string.gsub( line, "^.*href=\"([^\"]*)\".*$", "%1" ) _,_,arturl = string.find( line, "href=\"(.-)\"" )
end end
if name and description and arturl then break end if name and description and arturl then break end
end end
return { { path = string.gsub( vlc.path, "^.*watch/(.*[^/])/?$", "http://www.metacafe.com/fplayer/%1.swf" ); name = name; description = description; arturl = arturl; } } 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 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
end end
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
-- Helper function to get a parameter's value in a URL -- Helper function to get a parameter's value in a URL
function get_url_param( url, name ) function get_url_param( url, name )
return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" ) local _, _, res = string.find( url, "[&?]"..name.."=([^&]*)" )
return res
end end
function get_arturl( path, video_id ) function get_arturl( path, video_id )
...@@ -62,22 +63,23 @@ function parse() ...@@ -62,22 +63,23 @@ function parse()
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if string.match( line, "<meta name=\"title\"" ) then if string.match( line, "<meta name=\"title\"" ) then
name = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" ) _,_,name = string.find( line, "content=\"(.-)\"" )
end end
if string.match( line, "<meta name=\"description\"" ) then 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 end
if string.match( line, "subscribe_to_user=" ) then if string.match( line, "subscribe_to_user=" ) then
artist = string.gsub( line, ".*subscribe_to_user=([^&]*).*", "%1" ) _,_,artist = string.find( line, "subscribe_to_user=([^&]*)" )
end end
-- OLD: var swfArgs = {hl:'en',BASE_YT_URL:'http://youtube.com/',video_id:'XPJ7d8dq0t8',l:'292',t:'OEgsToPDskLFdOYrrlDm3FQPoQBYaCP1',sk:'0gnr-AE6QZJEZmCMd3lq_AC'}; -- 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=="}; -- 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, "swfArgs" ) and string.match( line, "video_id" ) then
if string.match( line, "BASE_YT_URL" ) 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 end
t = string.gsub( line, ".*\"t\": \"([^\"]*).*", "%1" ) _,_,t = string.find( line, "\"t\": \"(.-)\"" )
-- vlc.msg_err( t ) -- vlc.msg.err( t )
-- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" ) -- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" )
end end
if name and description and artist --[[and video_id]] then break end if name and description and artist --[[and video_id]] then break end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment