Add support for wdrmaus.de
[libquvi-scripts.git] / share / lua / website / wdrmaus.lua
blob8432589d75cba1abd64bc1527f218a03647b38be
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.
50 local WdrMaus = {} -- Utility functions unique to this script
52 -- Identify the script.
53 function ident(self)
54 package.path = self.script_dir .. '/?.lua'
55 local C = require 'quvi/const'
56 local r = {}
57 r.domain = "wdrmaus%.de"
58 r.formats = "default"
59 r.categories = C.proto_rtmp
60 local U = require 'quvi/util'
61 -- there seems to be no possiblity to really
62 -- make a decision here: we are using a less
63 -- strict pattern here
64 r.handles = U.handles(self.page_url, {r.domain})
65 return r
66 end
68 -- Query available formats.
69 function query_formats(self)
70 self.formats = 'default'
71 return self
72 end
74 -- Parse media URL.
75 function parse(self)
76 self.host_id = "wdrmaus"
78 local U = require 'quvi/url'
79 local t = U.parse(self.page_url)
81 if t.path:match('elefantenseite') then
82 WdrMaus.parseElefantenseite(self)
83 elseif t.path:match('kaeptnblaubaerseite') then
84 WdrMaus.parseKaeptnblaubaerseite(self)
85 elseif t.path:match('sachgeschichten') then
86 WdrMaus.parseSachgeschichten(self)
87 end
89 return self
90 end
93 -- Utility functions
96 function WdrMaus.parseElefantenseite(self)
97 self.id = self.page_url:match('\/([%w_]-)$')
98 or error('no match: media id')
100 local rooturl = self.page_url:match('(%w+://.+/%w+)/.*')
101 local configuration = quvi.fetch(rooturl .. '/data/configuration.php5')
102 local streamingServerPath = WdrMaus.getXMLvalue(configuration, 'streamingServerPath')
103 local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5')
104 local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id)
105 local metadata = quvi.fetch(rooturl .. '/' .. metadataPath);
107 streamingServerPath = string.gsub(streamingServerPath, '/$', '')
108 self.url = { streamingServerPath
109 .. WdrMaus.getXMLvalue(metadata, 'file') }
110 self.title = WdrMaus.getXMLvalue(metadata, 'title')
111 -- no idea why this url has a diffent host
112 self.thumbnail_url = 'http://www.wdr.de/bilder/mediendb/elefant_online'
113 .. WdrMaus.getXMLvalue(metadata, 'image')
114 self.format = 'default'
116 return self
119 function WdrMaus.parseKaeptnblaubaerseite(self)
120 self.id = self.page_url:match('/([^/]-)$')
121 local metadatasite = quvi.fetch(
122 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5')
123 local matcher = string.gsub(self.id, '-' , '.')
124 metadata = metadatasite:match('.*(<img.-' .. matcher .. ')')
125 self.title = metadata:match('<p>%s-(.-)%s-<br')
126 local thumb_rel = metadata:match('<img src="(.-)"') or ''
127 thumb_rel = string.gsub(thumb_rel, '%.%.', '')
128 self.thumbnail_url =
129 'http://www.wdrmaus.de/kaeptnblaubaerseite'
130 .. thumb_rel
131 self.url = { self.page_url:match('.-(rtmp.-flv)') }
132 self.format = 'default'
134 return self
137 function WdrMaus.parseSachgeschichten(self)
138 self.id = self.page_url:match('%d+$')
139 local metadata = quvi.fetch(
140 self.page_url)
141 self.title = metadata:match('h1_019DCE">(.-)<')
142 self.url = { metadata:match('(rtmp.-mp4)') }
143 self.format = 'default'
144 return self
147 function WdrMaus.getXMLvalue(str, value)
148 ret = str:match('<' .. value .. '>(.-)</' .. value .. '>')
149 or error('Cannot match ' .. value)
150 ret = ret:match('<!%[CDATA%[(.+)]]>') or ret
151 return ret
154 function WdrMaus.getMetadataPathFromToc(toc, id)
155 -- the toc contains all paths for this root (f.i. elefantenkino)
156 local page = string.match(toc, '<id>.-(' .. id .. '.-</xmlPath>)')
157 return WdrMaus.getXMLvalue(page, 'xmlPath')
160 -- vim: set ts=2 sw=2 tw=72 expandtab: