FIX: website/ted.lua: Check for extern media
[libquvi-scripts.git] / share / lua / website / ted.lua
blob74d2dd83c533f367cad03399bc55b152c3b10e88
2 -- libquvi-scripts
3 -- Copyright (C) 2012,2013 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"
50 local p = quvi.fetch(self.page_url)
52 if Ted.is_external(self, p) then return self end
54 self.id = p:match('ti:"(%d+)"') or error("no match: media ID")
56 self.title = p:match('<title>(.-)%s+|') or error("no match: media title")
58 self.thumbnail_url = p:match('"og:image" content="(.-)"') or ''
60 return self
61 end
64 -- Utility functions
67 function Ted.is_external(self, p)
68 self.url = {p:match('(http://download.-)"') or ''}
69 if #self.url[1] ==0 then -- Try the first iframe
70 self.redirect_url = p:match('<iframe src="(.-)"') or ''
71 if #self.redirect_url >0 then
72 return true
73 else
74 error('no match: media stream URL')
75 end
76 end
77 return false
78 end
80 -- vim: set ts=4 sw=4 tw=72 expandtab: