FIX: media/publicsenat: Reimpl. support
[libquvi-scripts.git] / share / media / publicsenat.lua
blob301473a07375c812431b2d06063c4822cdf63332
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2010,2012 Raphaƫl Droz <raphael.droz+floss@gmail.com>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.googlecode.com/>.
6 --
7 -- This program is free software: you can redistribute it and/or
8 -- modify it under the terms of the GNU Affero General Public
9 -- License as published by the Free Software Foundation, either
10 -- version 3 of the License, or (at your option) any later version.
12 -- This program 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
15 -- GNU Affero General Public License for more details.
17 -- You should have received a copy of the GNU Affero General
18 -- Public License along with this program. If not, see
19 -- <http://www.gnu.org/licenses/>.
22 local PublicSenat = {} -- Utility functions unique to this script.
24 -- Identify the script.
25 function ident(qargs)
26 return {
27 can_parse_url = PublicSenat.can_parse_url(qargs),
28 domains = table.concat({'publicsenat.fr'}, ',')
30 end
32 -- Parse media properties.
33 function parse(qargs)
34 local p = quvi.http.fetch(qargs.input_url).data
36 local u = p:match('id="dmcloudUrlEmissionSelect" value="(.-)"')
37 or error('no match: emission URL')
39 local e = quvi.http.fetch(u).data
40 local d = e:match('info = (.-);') or error('no match: info')
42 local J = require 'json'
43 local j = J.decode(d)
45 qargs.id = qargs.input_url:match("/vod/.-/(%d+)$") or ''
47 qargs.title = p:match('<title>(.-)%s+%|') or ''
49 qargs.streams = PublicSenat.iter_streams(j)
51 qargs.thumb_url = j.thumbnail_url or ''
53 return qargs
54 end
57 -- Utility functions.
60 function PublicSenat.can_parse_url(qargs)
61 local U = require 'socket.url'
62 local t = U.parse(qargs.input_url)
63 if t and t.scheme and t.scheme:lower():match('^http$')
64 and t.host and t.host:lower():match('publicsenat%.fr$')
65 and t.path and t.path:lower():match('^/vod/.-/%d+')
66 then
67 return true
68 else
69 return false
70 end
71 end
73 function PublicSenat.iter_streams(j)
74 local S = require 'quvi/stream'
75 return {S.stream_new(j.mp4_url)}
76 end
78 -- vim: set ts=2 sw=2 tw=72 expandtab: