]> git.sesse.net Git - vlc/blob - share/lua/playlist/vimeo.lua
vimeo.lua: spoof user-agent with something inconspicuous
[vlc] / share / lua / playlist / vimeo.lua
1 --[[
2  $Id$
3
4  Copyright © 2009 the VideoLAN team
5
6  Authors: Konstantin Pavlov (thresh@videolan.org)
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 --]]
22
23 -- Probe function.
24 function probe()
25     return vlc.access == "http"
26         and string.match( vlc.path, "vimeo.com/%d+" )
27             or string.match( vlc.path, "vimeo.com/moogaloop/load" )
28 end
29
30 -- Parse function.
31 function parse()
32     p = {}
33     if string.match ( vlc.path, "vimeo.com/%d+" ) then
34         _,_,id = string.find( vlc.path, "vimeo.com/(.*)")
35         -- Vimeo disables HD if the user-agent contains "VLC", so we
36         -- set it to something inconspicuous. We do it here because
37         -- they seem to do some detection across requests
38         return { { path = "http://vimeo.com/moogaloop/load/clip:" .. id .. "/local/", name = "Vimeo playlist", options = { ":http-user-agent=Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2" } } }
39     end
40
41     if string.match ( vlc.path, "vimeo.com/moogaloop" ) then
42         while true do
43             -- Try to find the video's title
44             line = vlc.readline()
45             if not line then break end
46             if string.match( line, "<caption>(.*)</caption>" ) then
47                 _,_,name = string.find (line, "<caption>(.*)</caption>" )
48             end
49             -- Try to find id of the video
50             _,_,id = string.find (vlc.path, "vimeo.com/moogaloop/load/clip:(.*)/local/")
51             -- Try to find image for thumbnail
52             if string.match( line, "<thumbnail>(.*)</thumbnail>" ) then
53                 _,_,arturl = string.find (line, "<thumbnail>(.*)</thumbnail>" )
54             end
55             -- Try to find request signature (needed to construct video url)
56             if string.match( line, "<request_signature>(.*)</request_signature>" ) then
57                 _,_,rsig = string.find (line, "<request_signature>(.*)</request_signature>" )
58             end
59             -- Try to find request signature expiration time (needed to construct video url)
60             if string.match( line, "<request_signature_expires>(.*)</request_signature_expires>" ) then
61                 _,_,rsigtime = string.find (line, "<request_signature_expires>(.*)</request_signature_expires>" )
62             end
63             -- Try to find whether video is HD actually
64             if string.match( line, "<isHD>1</isHD>" ) then
65                 ishd = true
66             end
67         end
68         table.insert( p, { path = "http://vimeo.com/moogaloop/play/clip:"..id.."/"..rsig.."/"..rsigtime; name = name; arturl = arturl } )
69         if ishd == true then
70             table.insert( p, { path = "http://vimeo.com/moogaloop/play/clip:"..id.."/"..rsig.."/"..rsigtime.."/?q=hd"; name = name.." (HD)"; arturl = arturl } )
71         end
72     end
73     return p
74 end