Merge branch 'tg/add-videobash'
[quvi.git] / share / lua / website / globo.lua
blob21f6f88d42fbedf06f70a500932b937b2cca2fb9
2 -- quvi
3 -- Copyright (C) 2010,2011 quvi project
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 -- 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.
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
40 -- Query available formats.
41 function query_formats(self)
42 self.formats = 'default'
43 return self
44 end
46 -- Parse media URL.
47 function parse (self)
48 self.host_id = "globo"
49 local page = quvi.fetch(self.page_url)
51 local _,_,s = page:find('midiaId: (.-),')
52 self.id = s or error ("no match: media id")
54 local _,_,s = page:find('<title>.*-.*- (.-)</title>')
55 self.title = s or error ("no match: media title")
57 local config_url =
58 "http://playervideo.globo.com/webmedia/GMCPlayListASX"
59 .. "?flash=true&midiaId="
60 .. self.id
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.
66 local opts = {fetch_type = 'config', user_agent = 'iphone'}
67 local xml = quvi.fetch(config_url, opts)
68 local _,_,d,s = xml:find('<video duration="(.-)" src="(.-)%?')
69 self.duration = tonumber(d) or 0
70 self.url = {s or error('no match: media url')}
72 return self
73 end
75 -- vim: set ts=4 sw=4 tw=72 expandtab: