Update NEWS for v0.9.20131130
[libquvi-scripts.git] / share / lua / website / globo.lua
1
2 -- libquvi-scripts
3 -- Copyright (C) 2010-2012 quvi project
4 --
5 -- This file is part of libquvi-scripts <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.
11 --
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.
16 --
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
21 --
22
23 -- Note: Video URL verification which is done after parsing the details
24 -- in this script *will* fail if you are using a proxy that omits the
25 -- user-agent.
26
27 -- Identify the script.
28 function ident(self)
29 package.path = self.script_dir .. '/?.lua'
30 local C = require 'quvi/const'
31 local r = {}
32 r.domain = "video%.globo%.com"
33 r.formats = "default"
34 r.categories = C.proto_http
35 local U = require 'quvi/util'
36 r.handles = U.handles(self.page_url, {r.domain}, {"/Videos/"})
37 return r
38 end
39
40 -- Query available formats.
41 function query_formats(self)
42 self.formats = 'default'
43 return self
44 end
45
46 -- Parse media URL.
47 function parse(self)
48 self.host_id = "globo"
49
50 local p = quvi.fetch(self.page_url)
51
52 self.id = p:match('midiaId: (.-),')
53 or error("no match: media ID")
54
55 self.title = p:match('<title>.*-.*- (.-)</title>')
56 or error("no match: media title")
57
58 local c_url = "http://playervideo.globo.com/webmedia/GMCPlayListASX"
59 .. "?flash=true&midiaId="
60 .. self.id
61
62 -- Unless user-agent is set here to 'iphone', URL verification
63 -- *will* fail (HTTP/403) later. Fetching below itself does not
64 -- need it, just the URL verification. We set it here to be safe.
65
66 local o = {fetch_type='config', user_agent='iphone'}
67 local c = quvi.fetch(config_url, o)
68 local _,_,d,s = c:find('<video duration="(.-)" src="(.-)%?')
69 self.duration = tonumber(d) or 0
70 self.url = {s or error('no match: media URL')}
71
72 return self
73 end
74
75 -- vim: set ts=4 sw=4 tw=72 expandtab: