3 -- Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
5 -- This file is part of libquvi-scripts <http://quvi.googlecode.com/>.
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
12 -- This library 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 GNU
15 -- Lesser General Public License for more details.
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 local CanalPlus
= {} -- Utility functions unique to to this script.
24 -- Identify the script.
26 package
.path
= self
.script_dir
.. '/?.lua'
27 local C
= require
'quvi/const'
29 r
.domain
= "canalplus%.fr"
30 r
.formats
= "default|best"
31 r
.categories
= C
.proto_rtmp
32 local U
= require
'quvi/util'
33 r
.handles
= U
.handles(self
.page_url
, {r
.domain
}, {"/pid%d",
34 -- presidentielle2012.canalplus.fr
35 "/emissions", "/candidats", "/debats",
36 -- canalstreet.canalplus.fr
37 "/musique", "/actu", "/humour", "/tendances", "/sport", "/arts", "/danse"})
42 -- Query available formats.
43 function query_formats(self
)
44 local config
= CanalPlus
.get_config(self
)
45 local U
= require
'quvi/util'
46 local formats
= CanalPlus
.iter_formats(self
, config
, U
)
49 for _
,v
in pairs(formats
) do
50 table.insert(t
, CanalPlus
.to_s(v
))
54 self
.formats
= table.concat(t
, "|")
61 self
.host_id
= 'canalplus'
62 local config
= CanalPlus
.get_config(self
)
63 local U
= require
'quvi/util'
65 local formats
= CanalPlus
.iter_formats(self
, config
, U
)
66 local format = U
.choose_format(self
, formats
,
67 CanalPlus
.choose_best
,
68 CanalPlus
.choose_default
,
70 or error("unable to choose format")
71 self
.url
= {format.url
or error("no match: media url")}
80 function CanalPlus
.get_config(self
)
82 local page
= quvi
.fetch(self
.page_url
)
85 self
.title
= page
:match('videoTitre%s-=%s-"(.-)"')
86 if not self
.title
then
87 -- presidentielle2012.canalplus.fr
88 self
.title
= page
:match('property="og:title"%s+content="(.-)"')
89 or error('no match: media title')
92 self
.id
= page
:match('videoId=(%d+)')
93 or page
:match('videoId%s+=%s+"(%d+)"')
94 or error('no match: media ID')
97 "http://service.canal-plus.com/video/rest/getVideosLiees/cplus/"
100 t
.data
= quvi
.fetch(c_url
, {fetch_type
= 'config'})
105 function CanalPlus
.iter_formats(self
, config
, U
)
108 local p
= '<ID>' .. self
.id
.. '</ID>'
115 .. '.-<BAS_DEBIT>(.-)<'
116 .. '.-<HAUT_DEBIT>(.-)<'
119 -- sd = low definition flv
120 -- hd = high definition flv
121 -- hq = high definition mp4
123 local thumb
,sd_url
,hd_url
,hq_url
= config
.data
:match(p
)
124 if not sd_url
then error("no match: media url") end
126 self
.thumbnail_url
= thumb
or ''
128 table.insert(t
, {url
=sd_url
, quality
="sd"})
129 table.insert(t
, {url
=hd_url
, quality
="hd"})
130 table.insert(t
, {url
=hq_url
, quality
="hq"})
135 function CanalPlus
.choose_best(formats
) -- Whatever matches 'hd' first
137 for _
,v
in pairs(formats
) do
138 if CanalPlus
.to_s(v
):find('hd') then
145 function CanalPlus
.choose_default(formats
) -- Whatever matches 'sd' first
147 for _
,v
in pairs(formats
) do
148 if CanalPlus
.to_s(v
):find('sd') then
155 function CanalPlus
.to_s(t
)
159 -- vim: set ts=4 sw=4 tw=72 expandtab: