2 -- Copyright (C) 2010-2012 Toni Gundogdu <legatvs@gmail.com>
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 -- This library is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU Lesser General Public
8 -- License as published by the Free Software Foundation; either
9 -- version 2.1 of the License, or (at your option) any later version.
11 -- This library is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 -- Lesser General Public License for more details.
16 -- You should have received a copy of the GNU Lesser General Public
17 -- License along with this library; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 -- NOTE: Vimeo is picky about the user-agent string.
26 local Vimeo
= {} -- Utility functions unique to this script.
28 -- Identify the media script.
30 local A
= require
'quvi/accepts'
32 accepts
= A
.accepts(qargs
.input_url
, {"vimeo%.com"}, {"/%d+$"})
37 -- Parse media stream URL.
39 Vimeo
.normalize(qargs
)
41 local p
= quvi
.fetch(qargs
.input_url
)
42 local U
= require
'quvi/util'
44 qargs
.id
= qargs
.input_url
:match('/(%d+)$') or error('no match: media ID')
45 qargs
.duration_ms
=(tonumber(p
:match('"duration":(%d+)')) or 0) * 1000
46 qargs
.thumb_url
= U
.slash_unescape(p
:match('"thumbnail":"(.-)"') or '')
48 local s
= p
:match('"title":(.-),') or ''
49 qargs
.title
= U
.slash_unescape(s
):gsub('^"',''):gsub('"$','')
51 qargs
.streams
= Vimeo
.iter_streams(qargs
, p
)
60 function Vimeo
.iter_streams(qargs
, page
)
61 local p
= page
:match('"profiles":{(.-)},') or error('no match: profiles')
63 local rs
= page
:match('"signature":"(.-)"')
64 or error('no match: request signature')
66 local rt
= page
:match('"timestamp":(%d+)')
67 or error('no match: request timestamp')
69 local f
= "http://player.vimeo.com/play_redirect?clip_id=%s"
70 .. "&sig=%s&time=%s&quality=%s&type=moogaloop_local"
72 local S
= require
'quvi/stream'
75 for e
,a
in p
:gmatch('"(.-)":{(.-)}') do -- For each profile.
76 for q
in a
:gmatch('"(.-)":%d+') do -- For each quality in the profile.
77 local u
= string.format(f
, qargs
.id
, rs
, rt
, q
)
78 local t
= S
.stream_new(u
)
79 t
.video
.encoding
= string.lower(e
or '')
80 t
.id
= Vimeo
.to_id(t
, q
)
92 function Vimeo
.normalize(qargs
)
93 local u
= qargs
.input_url
:gsub("player.", "") -- player.vimeo.com
94 qargs
.input_url
= u
:gsub("/video/", "/")
97 function Vimeo
.ch_best(t
)
98 t
[1].flags
.best
= true -- Should be the 'hd'.
101 -- Return an ID for a stream.
102 function Vimeo
.to_id(t
, quality
)
103 return string.format("%s_%s", quality
, t
.video
.encoding
)
106 -- vim: set ts=2 sw=2 tw=72 expandtab: