ard.lua: Cleanup Ard.iter_formats
[libquvi-scripts.git] / share / lua / website / ted.lua
blob1debf01c5a8b3094ccd84373bc5c767d13610fc7
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 self.url = {p:match('(http://download.-)"')
64 or error("no match: media stream URL")}
65 return self
66 end
69 -- Utility functions
72 function Ted.is_external(self, page)
73 -- Some of the videos are hosted elsewhere.
74 self.redirect_url = page:match('name="movie"%s+value="(.-)"') or ''
75 return #self.redirect_url > 0
76 end
78 -- vim: set ts=4 sw=4 tw=72 expandtab: