2 -- Copyright (C) 2013 Mohamed El Morabity <melmorabity@fedoraproject.org>
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 -- This program is free software: you can redistribute it and/or
7 -- modify it under the terms of the GNU Affero General Public
8 -- License as published by the Free Software Foundation, either
9 -- version 3 of the License, or (at your option) any later version.
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU Affero General Public License for more details.
16 -- You should have received a copy of the GNU Affero General
17 -- Public License along with this program. If not, see
18 -- <http://www.gnu.org/licenses/>.
21 local Ina
= {} -- Utility functions unique to this script
23 -- Identify the media script.
26 can_parse_url
= Ina
.can_parse_url(qargs
),
27 domains
= table.concat({'ina.fr'}, ',')
31 -- Parse the media properties.
33 -- Make mandatory: needed to fetch the video data XML.
34 qargs
.id
= qargs
.input_url
:match('/video/(%w+)')
35 or qargs
.input_url
:match('/audio/(%w+)')
36 or error('no match: media ID')
38 -- Fetch the video data XML
39 local u
= string.format('http://player.ina.fr/notices/%s.mrss?site=visio',
41 local c
= quvi
.http
.fetch(u
).data
42 local P
= require
'lxp.lom'
45 qargs
.streams
= Ina
.iter_streams(x
)
47 qargs
.title
= qargs
.streams
[1].nostd
.title
49 qargs
.thumb_url
= qargs
.streams
[1].nostd
.thumb_url
51 qargs
.duration_ms
= qargs
.streams
[1].nostd
.duration_ms
60 function Ina
.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('^https?$')
64 and t
.host
and t
.host
:lower():match('ina%.fr$')
65 and t
.path
and (t
.path
:lower():match('^/video/%w+')
66 or t
.path
:lower():match('^/audio/%w+'))
74 function Ina
.iter_streams(x
)
75 local S
= require
'quvi/stream'
76 local L
= require
'quvi/lxph'
78 local c
= L
.find_first_tag(x
, 'channel')
79 local m
= L
.find_first_tag(L
.find_first_tag(c
, 'item'),
81 local t
= L
.find_first_tag(m
, 'media:thumbnail')
83 local u
= m
.attr
.url
or error('no match: media stream URL')
85 local s
= S
.stream_new(u
)
87 title
= L
.find_first_tag(c
, 'title')[1] or '',
88 thumb_url
= t
.attr
.url
,
89 duration_ms
= tonumber(m
.attr
.duration
) * 1000
95 -- vim: set ts=2 sw=2 tw=72 expandtab: