]> git.sesse.net Git - vlc/blob - share/lua/playlist/vimeo.lua
vimeo.lua: convert to --preferred-resolution
[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 function get_prefres()
24     local prefres = -1
25     if vlc.var and vlc.var.inherit then
26         prefres = vlc.var.inherit(nil, "preferred-resolution")
27         if prefres == nil then
28             prefres = -1
29         end
30     end
31     return prefres
32 end
33
34 -- Probe function.
35 function probe()
36     return vlc.access == "http"
37         and string.match( vlc.path, "vimeo.com/%d+" )
38             or string.match( vlc.path, "vimeo.com/moogaloop/load" )
39 end
40
41 -- Parse function.
42 function parse()
43     if string.match ( vlc.path, "vimeo.com/%d+" ) then
44         _,_,id = string.find( vlc.path, "vimeo.com/(.*)")
45         -- Vimeo disables HD if the user-agent contains "VLC", so we
46         -- set it to something inconspicuous. We do it here because
47         -- they seem to do some detection across requests
48         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" } } }
49     end
50
51     if string.match ( vlc.path, "vimeo.com/moogaloop" ) then
52         prefres = get_prefres()
53         ishd = false
54         while true do
55             -- Try to find the video's title
56             line = vlc.readline()
57             if not line then break end
58             if string.match( line, "<caption>(.*)</caption>" ) then
59                 _,_,name = string.find (line, "<caption>(.*)</caption>" )
60             end
61             -- Try to find id of the video
62             _,_,id = string.find (vlc.path, "vimeo.com/moogaloop/load/clip:(.*)/local/")
63             -- Try to find image for thumbnail
64             if string.match( line, "<thumbnail>(.*)</thumbnail>" ) then
65                 _,_,arturl = string.find (line, "<thumbnail>(.*)</thumbnail>" )
66             end
67             -- Try to find request signature (needed to construct video url)
68             if string.match( line, "<request_signature>(.*)</request_signature>" ) then
69                 _,_,rsig = string.find (line, "<request_signature>(.*)</request_signature>" )
70             end
71             -- Try to find request signature expiration time (needed to construct video url)
72             if string.match( line, "<request_signature_expires>(.*)</request_signature_expires>" ) then
73                 _,_,rsigtime = string.find (line, "<request_signature_expires>(.*)</request_signature_expires>" )
74             end
75             -- Try to find whether video is HD actually
76             if string.match( line, "<isHD>1</isHD>" ) then
77                 ishd = true
78             end
79             if string.match( line, "<height>%d+</height>" ) then
80                 _,_,height = string.find( line, "<height>(%d+)</height>" )
81             end
82         end
83         path = "http://vimeo.com/moogaloop/play/clip:"..id.."/"..rsig.."/"..rsigtime
84         if ishd and ( not height or prefres < 0 or prefres >= tonumber(height) ) then
85             path = path.."/?q=hd"
86         end
87         return { { path = path; name = name; arturl = arturl } }
88     end
89     return {}
90 end