Commit d7e042e8 authored by Pierre Ynard's avatar Pierre Ynard

vimeo.lua: rewrite due to website changes

The config is not available within the page anymore, we have to call an
API URL to fetch it
parent 4ab7dfbf
--[[ --[[
$Id$ $Id$
Copyright © 2009 the VideoLAN team Copyright © 2009-2013 the VideoLAN team
Authors: Konstantin Pavlov (thresh@videolan.org) Authors: Konstantin Pavlov (thresh@videolan.org)
François Revol (revol@free.fr) François Revol (revol@free.fr)
Pierre Ynard
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -34,92 +35,58 @@ end ...@@ -34,92 +35,58 @@ end
-- Probe function. -- Probe function.
function probe() function probe()
return vlc.access == "http" return ( vlc.access == "http" or vlc.access == "https" )
and string.match( vlc.path, "vimeo.com/%d+$" ) and ( string.match( vlc.path, "vimeo%.com/%d+$" )
or string.match( vlc.path, "player%.vimeo%.com" ) )
-- do not match other addresses, -- do not match other addresses,
-- else we'll also try to decode the actual video url -- else we'll also try to decode the actual video url
end end
-- Parse function. -- Parse function.
function parse() function parse()
agent = vlc.var.inherit(nil,"http-user-agent") if not string.match( vlc.path, "player%.vimeo%.com" ) then -- Web page URL
while true do
local line = vlc.readline()
if not line then break end
path = string.match( line, "data%-config%-url=\"(.-)\"" )
if path then
path = vlc.strings.resolve_xml_special_chars( path )
return { { path = path } }
end
end
if string.match( string.lower(agent), ".*vlc.*" ) then vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
vlc.msg.dbg("Wrong agent, adapting...") return { }
return { { path = vlc.access .. "://" .. vlc.path; options = {":http-user-agent=Mozilla/5.0" } } }
end else -- API URL
_,_,id = string.find( vlc.path, "vimeo.com/([0-9]*)") local prefres = get_prefres()
prefres = get_prefres() local line = vlc.readline() -- data is on one line only
ishd = false
quality = "sd" for stream in string.gmatch( line, "{([^}]*\"profile\":[^}]*)}" ) do
codec = nil local url = string.match( stream, "\"url\":\"(.-)\"" )
line2 = "" if url then
while true do path = url
line = vlc.readline() if prefres < 0 then
if not line then break end break
if string.match( line, "{config:.*") then
line2 = line;
while not string.match( line2, "}};") do
line2 = vlc.readline()
if not line2 then break end
line = line .. line2;
end end
local height = string.match( stream, "\"height\":(%d+)[,}]" )
if not height or tonumber(height) <= prefres then
break
end
end
end end
-- Try to find the video's title
if string.match( line, "<meta property=\"og:title\"" ) then if not path then
_,_,name = string.find (line, "content=\"(.*)\">" ) vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
end return { }
if string.match( line, "{config:.*\"title\":\"" ) then
_,_,name = string.find (line, "\"title\":\"([^\"]*)\"," )
end
-- Try to find image for thumbnail
if string.match( line, "<meta property=\"og:image\"" ) then
_,_,arturl = string.find (line, "content=\"(.*)\">" )
end
if string.match( line, "<meta itemprop=\"thumbnailUrl\"" ) then
_,_,arturl = string.find (line, "content=\"(.*)\">" )
end
-- Try to find duration
if string.match( line, "{config:.*\"duration\":" ) then
_,_,duration = string.find (line, "\"duration\":([0-9]*)," )
end
-- Try to find request signature (needed to construct video url)
if string.match( line, "{config:.*\"signature\":" ) then
_,_,rsig = string.find (line, "\"signature\":\"([0-9a-f]*)\"," )
end
-- Try to find request signature time (needed to construct video url)
if string.match( line, "{config:.*\"timestamp\":" ) then
_,_,tstamp = string.find (line, "\"timestamp\":([0-9]*)," )
end
-- Try to find the available codecs
if string.match( line, "{config:.*,\"files\":{\"vp6\":" ) then
codec = "vp6"
end
if string.match( line, "{config:.*,\"files\":{\"vp8\":" ) then
codec = "vp8"
end
if string.match( line, "{config:.*,\"files\":{\"h264\":" ) then
codec = "h264"
end
-- Try to find whether video is HD actually
if string.match( line, "{config:.*,\"hd\":1" ) then
ishd = true
end
if string.match( line, "{config:.*\"height\":" ) then
_,_,height = string.find (line, "\"height\":([0-9]*)," )
end end
if not line2 then break end
end
if not codec then local name = string.match( line, "\"title\":\"(.-)\"" )
vlc.msg.err("unable to find codec info") local artist = string.match( line, "\"owner\":{[^}]-\"name\":\"(.-)\"" )
return {} local arturl = string.match( line, "\"thumbs\":{\"[^\"]+\":\"(.-)\"" )
end local duration = string.match( line, "\"duration\":(%d+)[,}]" )
if ishd and ( not height or prefres < 0 or prefres >= tonumber(height) ) then return { { path = path; name = name; artist = artist; arturl = arturl; duration = duration } }
quality = "hd"
end end
path = "http://player.vimeo.com/play_redirect?quality="..quality.."&codecs="..codec.."&clip_id="..id.."&time="..tstamp.."&sig="..rsig.."&type=html5_desktop_local"
return { { path = path; name = name; arturl = arturl; duration = duration } }
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