Set release details for 0.2.13
[quvi.git] / share / lua / website / vimeo.lua
blob1c635f53a4fd5e05f9c6520a02246e983bea3489
2 -- quvi
3 -- Copyright (C) 2010 Toni Gundogdu <legatvs@gmail.com>
4 --
5 -- This file is part of quvi <http://quvi.sourceforge.net/>.
6 --
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
12 -- This library is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 -- Lesser General Public License for more details.
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 -- 02110-1301 USA
23 -- Identify the script.
24 function ident (self)
25 package.path = self.script_dir .. '/?.lua'
26 local C = require 'quvi/const'
27 local r = {}
28 r.domain = "vimeo.com"
29 r.formats = "default|best|hd"
30 r.categories = C.proto_http
31 r.handles =
32 (self.page_url ~= nil and self.page_url:find(r.domain) ~= nil)
33 return r
34 end
36 -- Parse video URL.
37 function parse (self)
38 self.host_id = "vimeo"
40 is_player, _, self.id =
41 self.page_url:find("^http://player.vimeo.com/video/(%d+)")
43 if ( is_player ~= nil ) then
44 self.page_url = "http://vimeo.com/" .. vid
45 end
47 if (self.id == nil) then
48 local _,_,s = self.page_url:find('vimeo.com/(%d+)')
49 self.id = s
50 end
52 if (self.id == nil) then error ("no match: video") end
54 local config_url = "http://vimeo.com/moogaloop/load/clip:" .. self.id
55 local config = quvi.fetch (config_url, {fetch_type = 'config'})
57 local _,_,s = config:find("<caption>(.-)</")
58 self.title = s or error ("no match: video title")
60 local _,_,s = config:find("<request_signature>(.-)</")
61 local sign = s or error ("no match: request signature")
63 local _,_,s = config:find("<request_signature_expires>(.-)</")
64 local exp = s or error ("no match: request signature expires")
66 local _,_,s = config:find("<hd_button>(%d)</")
67 local hd_button = s or error ("no match: hd button")
69 local q = "sd" -- Same as "default".
70 if (self.requested_format == "hd" or self.requested_format == "best") then
71 if (hd_button == "1") then
72 q = "hd"
73 end
74 end
76 self.url = {
77 string.format("http://vimeo.com/moogaloop/play/clip:%s/%s/%s/?q=%s",
78 self.id, sign, exp, q)
81 return self
82 end
84 -- vim: set ts=4 sw=4 tw=72 expandtab: