ard.lua: Cleanup Ard.iter_formats
[libquvi-scripts.git] / share / lua / website / wdrmaus.lua
blob195e24e5d5b702ca661d4f99fc6b24146ed08542
2 -- libquvi-scripts
3 -- Copyright (C) 2013 Guido Leisker <guido@guido-leisker.de>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
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
20 -- 02110-1301 USA
22 -- About
23 -- wrdmaus.de falls into different sections each working
24 -- quite differently
26 -- elefantenseite:
27 -- flash gallery with link target to proper pages for each video
28 -- last part of url is id, configuration.php5
29 -- http://www.wdrmaus.de/elefantenseite/
30 -- http://www.wdrmaus.de/elefantenseite/#/anke_tanzt_zooztiere
32 -- kaeptnblaubaerseite:
33 -- single flash, users need to use html only page (html gallery)
34 -- and copy target links of videos
35 -- http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5
36 -- http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5?mid=1&dslSrc=rtmp://gffstream.fcod.llnwd.net/a792/e2/blaubaer/flash/oink_web-m.flv&isdnSrc=rtmp://gffstream.fcod.llnwd.net/a792/e2/blaubaer/flash/oink_web-s.flv
38 -- sachgeschichten:
39 -- html video gallery, users need to copy target links of videos
40 -- http://www.wdrmaus.de/sachgeschichten/sachgeschichten/
41 -- http://www.wdrmaus.de/sachgeschichten/sachgeschichten/sachgeschichte.php5?id=2702
43 -- entenseite (very few videos, not supported!):
44 -- http://www.wdrmaus.de/enteseite/index.php5
45 -- http://www.wdrmaus.de/enteseite/tuerenauf/index.php5?v=3#v2
47 -- There are more sections but they seem to provide no videos.
49 local WdrMaus = {} -- Utility functions unique to this script
51 -- Identify the script.
52 function ident(self)
53 package.path = self.script_dir .. '/?.lua'
54 local C = require 'quvi/const'
55 local r = {}
56 r.domain = "wdrmaus%.de"
57 r.formats = "default"
58 r.categories = C.proto_rtmp
59 local U = require 'quvi/util'
60 -- there seems to be no possiblity to really
61 -- make a decision here: we are using a less
62 -- strict pattern here
63 r.handles = U.handles(self.page_url, {r.domain})
64 return r
65 end
67 -- Query available formats.
68 function query_formats(self)
69 self.formats = 'default'
70 return self
71 end
73 -- Parse media URL.
74 function parse(self)
75 self.host_id = "wdrmaus"
77 local a = {
78 {pat='kaeptnblaubaerseite', func=WdrMaus.parseKaeptnblaubaerseite},
79 {pat='sachgeschichten', func=WdrMaus.parseSachgeschichten},
80 {pat='elefantenseite', func=WdrMaus.parseElefantenseite}
83 local U = require 'quvi/url'
84 local t = U.parse(self.page_url)
85 local s = {}
87 for _,v in pairs(a) do
88 if t.path:match(v.pat) then return v.func(self) end
89 table.insert(s, v.pat)
90 end
92 error(string.format("limited support for the {%s} sections only",
93 table.concat(s, ',')))
94 end
97 -- Utility functions
100 function WdrMaus.parseElefantenseite(self)
101 self.id = self.page_url:match('/([%w_]-)$')
102 or error('no match: media ID')
104 local rooturl = self.page_url:match('(%w+://.+/%w+)/.*')
105 or error('no match: root url')
107 local qo = {fetch_type='config'}
108 local configuration = quvi.fetch(rooturl .. '/data/configuration.php5', qo)
110 local streamingServerPath =
111 WdrMaus.getXMLvalue(configuration, 'streamingServerPath')
113 local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5', qo)
115 local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id)
116 local metadata = quvi.fetch(rooturl .. '/' .. metadataPath, qo);
118 streamingServerPath = string.gsub(streamingServerPath, '/$', '')
119 self.url = { streamingServerPath .. WdrMaus.getXMLvalue(metadata, 'file') }
120 self.title = WdrMaus.getXMLvalue(metadata, 'title')
122 -- no idea why this url has a diffent host
123 self.thumbnail_url = 'http://www.wdr.de/bilder/mediendb/elefant_online'
124 .. WdrMaus.getXMLvalue(metadata, 'image')
126 return self
129 function WdrMaus.parseKaeptnblaubaerseite(self)
130 self.id = self.page_url:match('/([^/]-)$') or error('no match: media ID')
132 local qo = {fetch_type='config'}
133 local metadatasite = quvi.fetch(
134 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5', qo)
136 local matcher = string.gsub(self.id, '-' , '.')
137 metadata = metadatasite:match('.*(<img.-' .. matcher .. ')')
138 or error('no match: metadata')
140 self.title = metadata:match('<p>%s-(.-)%s-<br') or error('no match: title')
141 local thumb_rel = metadata:match('<img src="(.-)"') or ''
143 thumb_rel = string.gsub(thumb_rel, '%.%.', '')
144 self.thumbnail_url = 'http://www.wdrmaus.de/kaeptnblaubaerseite' ..thumb_rel
146 self.url = { self.page_url:match('.-(rtmp.-flv)')
147 or error('no match: media stream URL') }
148 return self
151 function WdrMaus.parseSachgeschichten(self)
152 self.id = self.page_url:match('%d+$') or error('no match: media ID')
153 local metadata = quvi.fetch(self.page_url)
154 self.title = metadata:match('h1_019DCE">(.-)<') or error('no match: title')
155 self.url = { metadata:match('(rtmp.-mp4)')
156 or error('no match: media stream URL') }
157 return self
160 function WdrMaus.getXMLvalue(str, value)
161 ret = str:match('<' .. value .. '>(.-)</' .. value .. '>')
162 or error('Cannot match ' .. value)
163 return ret:match('<!%[CDATA%[(.+)]]>') or ret
166 function WdrMaus.getMetadataPathFromToc(toc, id)
167 -- the toc contains all paths for this root (f.i. elefantenkino)
168 local page = toc:match('<id>.-(' .. id .. '.-</xmlPath>)')
169 or error('no match: metadata path')
170 return WdrMaus.getXMLvalue(page, 'xmlPath')
173 -- vim: set ts=2 sw=2 tw=72 expandtab: