2 -- Copyright (C) 2010-2011,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/>.
22 -- NOTE: Some streams (e.g. 3gp) do not appear to be available (404) even
23 -- if they are listed in the config XML.
26 local Spiegel
= {} -- Utility functions unique to this script
28 -- Identify the script.
30 package
.path
= self
.script_dir
.. '/?.lua'
31 local C
= require
'quvi/const'
33 r
.domain
= "spiegel%.de"
34 r
.formats
= "default|best"
35 r
.categories
= C
.proto_http
36 local U
= require
'quvi/util'
37 r
.handles
= U
.handles(self
.page_url
, {r
.domain
}, {"/video/"})
41 -- Query available formats.
42 function query_formats(self
)
43 Spiegel
.get_media_id(self
)
45 local config
= Spiegel
.get_config(self
)
46 local formats
= Spiegel
.iter_formats(config
)
49 for _
,v
in pairs(formats
) do
50 table.insert(t
, Spiegel
.to_s(v
))
54 self
.formats
= table.concat(t
, "¦")
61 self
.host_id
= "spiegel"
63 local p
= quvi
.fetch(self
.page_url
)
65 self
.title
= p
:match('"spVideoTitle">(.-)<')
66 or error('no match: media title')
68 self
.thumbnail_url
= p
:match('"og:image" content="(.-)"') or ''
70 Spiegel
.get_media_id(self
)
72 local config
= Spiegel
.get_config(self
)
73 local formats
= Spiegel
.iter_formats(config
)
75 local U
= require
'quvi/util'
76 local format = U
.choose_format(self
, formats
,
78 Spiegel
.choose_default
,
80 or error("unable to choose format")
81 self
.duration
= (format.duration
or 0) * 1000 -- to msec
82 self
.url
= {format.url
or error("no match: media url")}
91 function Spiegel
.get_media_id(self
)
92 self
.id
= self
.page_url
:match("/video/.-video%-(.-)%.")
93 or error ("no match: media id")
96 function Spiegel
.get_config(self
)
97 local fmt_s
= "http://video.spiegel.de/flash/%s.xml"
98 local config_url
= string.format(fmt_s
, self
.id
)
99 return quvi
.fetch(config_url
, {fetch_type
= 'config'})
102 function Spiegel
.iter_formats(config
)
103 local p
= '<filename>(.-)<'
105 .. '.-<totalbitrate>(%d+)'
108 .. '.-<duration>(%d+)'
110 for fn
,c
,b
,w
,h
,d
in config
:gmatch(p
) do
111 local cn
= fn
:match('%.(%w+)$') or error('no match: container')
112 local u
= 'http://video.spiegel.de/flash/' .. fn
113 -- print(u,c,b,w,h,cn,d)
114 table.insert(t
, {codec
=string.lower(c
), url
=u
,
115 width
=tonumber(w
), height
=tonumber(h
),
116 bitrate
=tonumber(b
), duration
=tonumber(d
),
122 function Spiegel
.choose_best(formats
) -- Highest quality available
123 local r
= {width
=0, height
=0, bitrate
=0, url
=nil}
124 local U
= require
'quvi/util'
125 for _
,v
in pairs(formats
) do
126 if U
.is_higher_quality(v
,r
) then
133 function Spiegel
.choose_default(formats
)
137 function Spiegel
.to_s(t
)
138 return string.format('%s_%s_%sk_%sp',
139 t
.container
, t
.codec
, t
.bitrate
, t
.height
)
142 -- vim: set ts=4 sw=4 tw=72 expandtab: