3 -- Copyright (C) 2010-2011,2013 Toni Gundogdu <legatvs@gmail.com>
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
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
24 -- NOTE: mp4s do not appear to be available (404) even if listed.
27 local Spiegel
= {} -- Utility functions unique to this script
29 -- Identify the script.
31 package
.path
= self
.script_dir
.. '/?.lua'
32 local C
= require
'quvi/const'
34 r
.domain
= "spiegel%.de"
35 r
.formats
= "default|best"
36 r
.categories
= C
.proto_http
37 local U
= require
'quvi/util'
38 r
.handles
= U
.handles(self
.page_url
, {r
.domain
}, {"/video/"})
42 -- Query available formats.
43 function query_formats(self
)
44 Spiegel
.get_media_id(self
)
46 local config
= Spiegel
.get_config(self
)
47 local formats
= Spiegel
.iter_formats(config
)
50 for _
,v
in pairs(formats
) do
51 table.insert(t
, Spiegel
.to_s(v
))
55 self
.formats
= table.concat(t
, "¦")
62 self
.host_id
= "spiegel"
64 local p
= quvi
.fetch(self
.page_url
)
66 self
.title
= p
:match('"spVideoTitle">(.-)<')
67 or error('no match: media title')
69 Spiegel
.get_media_id(self
)
71 local config
= Spiegel
.get_config(self
)
72 local formats
= Spiegel
.iter_formats(config
)
74 local U
= require
'quvi/util'
75 local format = U
.choose_format(self
, formats
,
77 Spiegel
.choose_default
,
79 or error("unable to choose format")
80 self
.duration
= (format.duration
or 0) * 1000 -- to msec
81 self
.url
= {format.url
or error("no match: media url")}
90 function Spiegel
.get_media_id(self
)
91 self
.id
= self
.page_url
:match("/video/.-video%-(.-)%.")
92 or error ("no match: media id")
95 function Spiegel
.get_config(self
)
96 local fmt_s
= "http://video.spiegel.de/flash/%s.xml"
97 local config_url
= string.format(fmt_s
, self
.id
)
98 return quvi
.fetch(config_url
, {fetch_type
= 'config'})
101 function Spiegel
.iter_formats(config
)
102 local p
= '<filename>(.-)<'
104 .. '.-<totalbitrate>(%d+)'
107 .. '.-<duration>(%d+)'
109 for fn
,c
,b
,w
,h
,d
in config
:gmatch(p
) do
110 local cn
= fn
:match('%.(%w+)$') or error('no match: container')
111 local u
= 'http://video.spiegel.de/flash/' .. fn
112 -- print(u,c,b,w,h,cn,d)
113 table.insert(t
, {codec
=string.lower(c
), url
=u
,
114 width
=tonumber(w
), height
=tonumber(h
),
115 bitrate
=tonumber(b
), duration
=tonumber(d
),
121 function Spiegel
.choose_best(formats
) -- Highest quality available
122 local r
= {width
=0, height
=0, bitrate
=0, url
=nil}
123 local U
= require
'quvi/util'
124 for _
,v
in pairs(formats
) do
125 if U
.is_higher_quality(v
,r
) then
132 function Spiegel
.choose_default(formats
) -- Lowest quality available
133 local r
= {width
=0xffff, height
=0xffff, bitrate
=0xffff, url
=nil}
134 local U
= require
'quvi/util'
135 for _
,v
in pairs(formats
) do
136 if U
.is_lower_quality(v
,r
) then
143 function Spiegel
.to_s(t
)
144 return string.format('%s_%s_%sk_%sp',
145 t
.container
, t
.codec
, t
.bitrate
, t
.height
)
148 -- vim: set ts=4 sw=4 tw=72 expandtab: