media/videa.lua: Relicense under AGPLv3+
[libquvi-scripts.git] / share / media / senat.lua
blobc3f7c8136392c8ac25635347d5455844a25659e0
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2012 Raphaƫl Droz <raphael.droz+floss@gmail.com>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
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 Senat = {} -- Utility functions unique to this script.
24 -- Identify the script.
25 function ident(qargs)
26 return {
27 can_parse_url = Senat.can_parse_url(qargs),
28 domains = table.concat({'videos.senat.fr'}, ',')
30 end
32 -- Parse media properties.
33 function parse(qargs)
34 local C = require 'quvi/const'
35 local o = { [C.qoo_fetch_from_charset] = 'iso-8859-1' }
36 local p = quvi.http.fetch(qargs.input_url, o).data
38 qargs.id = qargs.input_url:match('/video(%d+)%.html$') or ''
40 qargs.title = p:match('<title>(.-)</title>') or ''
42 qargs.thumb_url = p:match('image=(.-)&') or ''
44 qargs.streams = Senat.iter_streams(p)
46 return qargs
47 end
50 -- Utility functions.
53 function Senat.can_parse_url(qargs)
54 local U = require 'socket.url'
55 local t = U.parse(qargs.input_url)
56 local p = '^/%w+/videos/%d+/video%d+%.html$'
57 if t and t.scheme and t.scheme:lower():match('^http$')
58 and t.host and t.host:lower():match('^videos%.senat%.fr$')
59 and t.path and t.path:lower():match(p)
60 then
61 return true
62 else
63 return false
64 end
65 end
67 function Senat.iter_streams(p)
68 local v = p:match('name="flashvars" value="(.-)"')
69 or error('no match: flash vars')
71 local u = v:match('file=(.-flv)')
72 or error('no match: media stream URL')
74 local S = require 'quvi/stream'
75 local t = S.stream_new(u)
77 t.video.height= v:match('height=(%d+)') or 0
78 t.video.width = v:match('width=(%d+)') or 0
80 return {t}
81 end
83 -- vim: set ts=2 sw=2 tw=72 expandtab: