ted.lua: Support the "default" format only
[libquvi-scripts.git] / share / lua / website / ted.lua
blobfb07ee2b3929899aec89f2e95460c798d4e18074
2 -- libquvi-scripts
3 -- Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
5 --
6 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
7 --
8 -- This library is free software; you can redistribute it and/or
9 -- modify it under the terms of the GNU Lesser General Public
10 -- License as published by the Free Software Foundation; either
11 -- version 2.1 of the License, or (at your option) any later version.
13 -- This library 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 GNU
16 -- Lesser General Public License for more details.
18 -- You should have received a copy of the GNU Lesser General Public
19 -- License along with this library; if not, write to the Free Software
20 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 -- 02110-1301 USA
24 local Ted = {} -- Utility functions unique to this script
26 -- Identify the script.
27 function ident(self)
28 package.path = self.script_dir .. '/?.lua'
29 local C = require 'quvi/const'
30 local r = {}
31 r.domain = "ted%.com"
32 r.formats = "default|best"
33 r.categories = C.proto_http
34 local U = require 'quvi/util'
35 r.handles = U.handles(self.page_url, {r.domain}, {"/talks/.+$"})
36 return r
37 end
39 -- Query available formats.
40 function query_formats(self)
41 self.formats = "default"
42 Ted.is_external(self, quvi.fetch(self.page_url))
43 return self
44 end
46 -- Parse video URL.
47 function parse(self)
48 self.host_id = "ted"
49 local p = quvi.fetch(self.page_url)
51 if Ted.is_external(self, p) then
52 return self
53 end
55 self.id = p:match('ti:"(%d+)"')
56 or error("no match: media id")
58 self.title = p:match('<title>(.-)%s+|')
59 or error("no match: media title")
61 self.thumbnail_url = p:match('rel="image_src" href="(.-)"') or ''
63 local u = p:match('"og:video"%s+content="(.-)"')
64 or error("no match: media url")
65 self.url = {u}
67 return self
68 end
71 -- Utility functions
74 function Ted.is_external(self, page)
75 -- Some of the videos are hosted elsewhere.
76 self.redirect_url = page:match('name="movie"%s+value="(.-)"') or ''
77 return #self.redirect_url > 0
78 end
80 -- vim: set ts=4 sw=4 tw=72 expandtab: