Merge branch 'tg/next/0.4_add_wdrmaus' into next
[libquvi-scripts.git] / share / lua / website / wdrmaus.lua
blob3ee2520d0e0173d7c393b89352366fe614a3a2d7
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 local qo = {fetch_type='config'}
106 local configuration = quvi.fetch(rooturl .. '/data/configuration.php5', qo)
107 local streamingServerPath =
108 WdrMaus.getXMLvalue(configuration, 'streamingServerPath')
109 local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5', qo)
110 local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id)
111 local metadata = quvi.fetch(rooturl .. '/' .. metadataPath, qo);
113 streamingServerPath = string.gsub(streamingServerPath, '/$', '')
114 self.url = { streamingServerPath
115 .. WdrMaus.getXMLvalue(metadata, 'file') }
116 self.title = WdrMaus.getXMLvalue(metadata, 'title')
117 -- no idea why this url has a diffent host
118 self.thumbnail_url = 'http://www.wdr.de/bilder/mediendb/elefant_online'
119 .. WdrMaus.getXMLvalue(metadata, 'image')
120 self.format = 'default'
122 return self
125 function WdrMaus.parseKaeptnblaubaerseite(self)
126 self.id = self.page_url:match('/([^/]-)$')
127 local qo = {fetch_type='config'}
128 local metadatasite = quvi.fetch(
129 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5', qo)
130 local matcher = string.gsub(self.id, '-' , '.')
131 metadata = metadatasite:match('.*(<img.-' .. matcher .. ')')
132 self.title = metadata:match('<p>%s-(.-)%s-<br')
133 local thumb_rel = metadata:match('<img src="(.-)"') or ''
134 thumb_rel = string.gsub(thumb_rel, '%.%.', '')
135 self.thumbnail_url =
136 'http://www.wdrmaus.de/kaeptnblaubaerseite'
137 .. thumb_rel
138 self.url = { self.page_url:match('.-(rtmp.-flv)') }
139 self.format = 'default'
141 return self
144 function WdrMaus.parseSachgeschichten(self)
145 self.id = self.page_url:match('%d+$')
146 local metadata = quvi.fetch(self.page_url)
147 self.title = metadata:match('h1_019DCE">(.-)<')
148 self.url = { metadata:match('(rtmp.-mp4)') }
149 self.format = 'default'
150 return self
153 function WdrMaus.getXMLvalue(str, value)
154 ret = str:match('<' .. value .. '>(.-)</' .. value .. '>')
155 or error('Cannot match ' .. value)
156 ret = ret:match('<!%[CDATA%[(.+)]]>') or ret
157 return ret
160 function WdrMaus.getMetadataPathFromToc(toc, id)
161 -- the toc contains all paths for this root (f.i. elefantenkino)
162 local page = string.match(toc, '<id>.-(' .. id .. '.-</xmlPath>)')
163 return WdrMaus.getXMLvalue(page, 'xmlPath')
166 -- vim: set ts=2 sw=2 tw=72 expandtab: