2 -- Copyright (C) 2010-2013 Toni Gundogdu <legatvs@gmail.com>
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 CBSNews
= {} -- Utility functions unique to this script
23 -- Identify the script.
26 can_parse_url
= CBSNews
.can_parse_url(qargs
),
27 domains
= table.concat({'cbsnews.com'}, ',')
31 -- Parse media properties.
33 local p
= quvi
.http
.fetch(qargs
.input_url
).data
35 local d
= p
:match("data%-cbsvideoui%-options='(.-)'")
36 or error('no match: player options')
38 local J
= require
'json'
39 local v
= J
.decode(d
).state
.video
41 qargs
.duration_ms
= (v
.duration
or 0) *1000
43 qargs
.streams
= CBSNews
.iter_streams(v
)
45 qargs
.thumb_url
= v
.image
.path
or ''
47 qargs
.title
= v
.title
or ''
58 function CBSNews
.can_parse_url(qargs
)
59 local U
= require
'socket.url'
60 local t
= U
.parse(qargs
.input_url
)
61 if t
and t
.scheme
and t
.scheme
:lower():match('^http$')
62 and t
.host
and t
.host
:lower():match('^www%.cbsnews%.com$')
63 and t
.path
and t
.path
:lower():match('^/videos/.-/?$')
71 function CBSNews
.iter_streams(v
)
72 local S
= require
'quvi/stream'
77 for k
,_
in pairs(m
) do
79 if type(a
) == 'table' then
80 local t
= S
.stream_new(a
.uri
)
81 CBSNews
.optional_stream_props(t
, a
)
82 t
.id
= CBSNews
.to_id(t
, k
)
83 -- For lack of a better solution:
84 -- Set the 'desktop' stream as the 'best'
85 if k
== 'desktop' then
94 function CBSNews
.optional_stream_props(t
, a
)
95 t
.container
= t
.url
:match('%.(%w+)$') or ''
96 local b
= tonumber(a
.bitrate
or 0)
100 t
.video
.bitrate_kbit_s
= b
103 function CBSNews
.to_id(t
, k
)
104 return string.format('%s_%s_%dk', t
.container
, k
, t
.video
.bitrate_kbit_s
)
107 -- vim: set ts=2 sw=2 tw=72 expandtab: