[vlc-devel] [PATCH] vimeo playback now hides user agent automatically
Stephen Parry
sgparry at mainscreen.com
Fri Mar 1 21:09:11 CET 2013
Vimeo injects garbage into pages fetched by any user agent recognisable as
being VLC. Amended parse routine to check the current user agent; if the user
agent is set to VLC then parse returns a replacement playlist entry with the
same url but with an option setting the user agent to something that vimeo will
not trash.
The main playlist parsing loop then re-opens the stream with the correct agent
and calls vimeo.lua a second time; the stream is then parsed as before to get
the actual shortlived video url.
---
share/lua/playlist/vimeo.lua | 146 ++++++++++++++++++++++--------------------
1 file changed, 77 insertions(+), 69 deletions(-)
diff --git a/share/lua/playlist/vimeo.lua b/share/lua/playlist/vimeo.lua
index 1200e44..09a71d7 100644
--- a/share/lua/playlist/vimeo.lua
+++ b/share/lua/playlist/vimeo.lua
@@ -42,77 +42,85 @@ end
-- Parse function.
function parse()
- _,_,id = string.find( vlc.path, "vimeo.com/([0-9]*)")
- prefres = get_prefres()
- ishd = false
- quality = "sd"
- codec = nil
- line2 = ""
- while true do
- line = vlc.readline()
- if not line then break end
- 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
+ agent = vlc.var.inherit(nil,"http-user-agent")
+ vlc.msg.dbg("Agent="..agent)
+ if string.match( string.lower(agent), ".*vlc.*" ) then
+ vlc.msg.dbg("Wrong agent...")
+ return { { path = vlc.access .. "://" .. vlc.path; options = {":http-user-agent=Mozilla/5.0" } } }
+ else
+ vlc.msg.dbg("Good agent...")
+ _,_,id = string.find( vlc.path, "vimeo.com/([0-9]*)")
+ prefres = get_prefres()
+ ishd = false
+ quality = "sd"
+ codec = nil
+ line2 = ""
+ while true do
+ line = vlc.readline()
+ if not line then break end
+ 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
+ -- Try to find the video's title
+ if string.match( line, "<meta property=\"og:title\"" ) then
+ _,_,name = string.find (line, "content=\"(.*)\">" )
+ end
+ 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
+ if not line2 then break end
end
- -- Try to find the video's title
- if string.match( line, "<meta property=\"og:title\"" ) then
- _,_,name = string.find (line, "content=\"(.*)\">" )
- end
- 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
- if not line2 then break end
- end
- if not codec then
- vlc.msg.err("unable to find codec info")
- return {}
- end
+ if not codec then
+ vlc.msg.err("unable to find codec info")
+ return {}
+ end
- if ishd and ( not height or prefres < 0 or prefres >= tonumber(height) ) then
- quality = "hd"
+ if ishd and ( not height or prefres < 0 or prefres >= tonumber(height) ) then
+ quality = "hd"
+ 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
- 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
--
1.7.9.5
More information about the vlc-devel
mailing list