Commit 130ff9a3 authored by Rémi Duraffort's avatar Rémi Duraffort

lua: improve the apple trailer sd:

 * fetch the list of video for one item only if required
 * use the provided thumbnail if available.
parent 3b98bdf8
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
-- Probe function. -- Probe function.
function probe() function probe()
return vlc.access == "http" return vlc.access == "http"
and string.match( vlc.path, "www.apple.com/trailers" ) and string.match( vlc.path, "trailers.apple.com" )
end end
function find( haystack, needle ) function find( haystack, needle )
...@@ -33,36 +33,37 @@ end ...@@ -33,36 +33,37 @@ end
-- Parse function. -- Parse function.
function parse() function parse()
p = {} local playlist = {}
local description = ''
local art_url = ''
while true while true
do do
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
for path in string.gmatch( line, "http://movies.apple.com/movies/.-%.mov" ) do
path = vlc.strings.decode_uri( path ) if string.match( line, "class=\".-first" ) then
if string.match( path, "320" ) then description = find( line, "h%d.->(.-)</h%d")
extraname = " (320p)"
elseif string.match( path, "480" ) then
extraname = " (480p)"
elseif string.match( path, "640" ) then
extraname = " (640p)"
elseif string.match( path, "720" ) then
extraname = " (720p)"
elseif string.match( path, "1080" ) then
extraname = " (1080p)"
else
extraname = ""
end
table.insert( p, { path = path; name = title..extraname; description = description; url = vlc.path; options = ":http-user-agent=\"QuickTime\"" } )
end end
if string.match( line, "<title>" ) if string.match( line, 'img src=') then
then for img in string.gmatch(line, '<img src="(http://.*\.jpg)" ') do
title = vlc.strings.decode_uri( find( line, "<title>(.-)<" ) ) art_url = img
end
for i,value in pairs(playlist) do
if value.arturl == '' then
playlist[i].arturl = art_url
else break end
end
end end
if string.match( line, "<meta name=\"Description\"" ) if string.match( line, "class=\"hd\".-\.mov") then
then for urlline,resolution in string.gmatch(line, "class=\"hd\".-href=\"(.-.mov)\".-(%d+.-p)") do
description = vlc.strings.resolve_xml_special_chars( find( line, "name=\"Description\" content=\"(.-)\"" ) ) urlline = string.gsub( urlline, "_"..resolution, "_h"..resolution )
table.insert( playlist, { path = urlline,
name = description .. " (" .. resolution .. ")",
arturl = art_url,
options = {":http-user-agent=QuickTime/7.2", ":demux=avformat,ffmpeg",":play-and-pause"} } )
end
end end
end end
return p return playlist
end end
...@@ -32,7 +32,6 @@ end ...@@ -32,7 +32,6 @@ end
function main() function main()
fd = vlc.stream( "http://trailers.apple.com/trailers/home/feeds/just_hd.json" ) fd = vlc.stream( "http://trailers.apple.com/trailers/home/feeds/just_hd.json" )
if not fd then return nil end if not fd then return nil end
options = {":http-user-agent=QuickTime/7.2",":demux=avformat,ffmpeg",":play-and-pause"}
line = fd:readline() line = fd:readline()
while line ~= nil while line ~= nil
do do
...@@ -45,31 +44,10 @@ function main() ...@@ -45,31 +44,10 @@ function main()
end end
url = find( line, "location\":\"(.-)\"") url = find( line, "location\":\"(.-)\"")
playlist = vlc.stream( "http://trailers.apple.com"..url.."includes/playlists/web.inc" ) node = vlc.sd.add_item( {title = title,
if not playlist then path = "http://trailers.apple.com"..url.."includes/playlists/web.inc",
vlc.msg.info("Didn't get playlist...") arturl = art})
end
node = vlc.sd.add_node( {title=title,arturl=art} )
playlistline = playlist:readline()
description =""
if not playlistline then vlc.msg.info("Empty playlists-file") end
while playlistline ~= nil
do
if string.match( playlistline, "class=\".-first" ) then
description = find( playlistline, "h%d.->(.-)</h%d")
end
if string.match( playlistline, "class=\"hd\".-\.mov") then
for urlline,resolution in string.gmatch(playlistline, "class=\"hd\".-href=\"(.-.mov)\".-(%d+.-p)") do
urlline = string.gsub( urlline, "_"..resolution, "_h"..resolution )
node:add_subitem( {path = urlline,
title=title.." "..description.." ("..resolution..")",
options=options, arturl=art })
end
end
playlistline = playlist:readline()
end
end end
line = fd:readline() line = fd:readline()
end 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