ard.lua: Cleanup Ard.iter_formats
[libquvi-scripts.git] / share / lua / website / lego.lua
blob571e17931c22e698d0cc20851f9dfb3dc42886a8
2 -- libquvi-scripts
3 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2012 Ross Burton <ross@burtonini.com>
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 -- Identify the script.
25 function ident(self)
26 package.path = self.script_dir .. '/?.lua'
27 local C = require 'quvi/const'
28 local r = {}
29 r.domain = "city%.lego%.com"
30 r.formats = "default"
31 r.categories = C.proto_http
32 local U = require 'quvi/util'
33 r.handles = U.handles(self.page_url, {r.domain}, {"/.+/movies/.+$"})
34 -- http://city.lego.com/en-gb/movies/mini-movies/gold-run/
35 return r
36 end
38 -- Query available formats.
39 function query_formats(self)
40 self.formats = "default"
41 return self
42 end
44 -- Parse video URL.
45 function parse(self)
46 self.host_id = "lego"
48 local p = quvi.fetch(self.page_url)
50 local d = p:match('FirstVideoData = {(.-)};')
51 or error('no match: FirstVideoData')
53 self.title = d:match('"Name":"(.-)"')
54 or error('no match: media title')
56 self.id = d:match('"LikeObjectGuid":"(.-)"') -- Lack of a better.
57 or error('no match: media ID')
59 self.url = {d:match('"VideoFlash":%{"Url":"(.-)"')
60 or error('no match: media stream URL')}
62 -- TODO: return self.thumbnail_url
64 return self
65 end