Update NEWS for v0.9.20131130
[libquvi-scripts.git] / share / lua / website / wdrmaus.lua
1
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.
11 --
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.
16 --
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
21
22 -- About
23 -- wrdmaus.de falls into different sections each working
24 -- quite differently
25 --
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
31 --
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
37 --
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
42 --
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
46 --
47 -- There are more sections but they seem to provide no videos.
48
49 local WdrMaus = {} -- Utility functions unique to this script
50
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
66
67 -- Query available formats.
68 function query_formats(self)
69 self.formats = 'default'
70 return self
71 end
72
73 -- Parse media URL.
74 function parse(self)
75 self.host_id = "wdrmaus"
76
77 local a = {
78 {pat='kaeptnblaubaerseite', func=WdrMaus.parseKaeptnblaubaerseite},
79 {pat='sachgeschichten', func=WdrMaus.parseSachgeschichten},
80 {pat='elefantenseite', func=WdrMaus.parseElefantenseite}
81 }
82
83 local U = require 'quvi/url'
84 local t = U.parse(self.page_url)
85 local s = {}
86
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
91
92 error(string.format("limited support for the {%s} sections only",
93 table.concat(s, ',')))
94 end
95
96 --
97 -- Utility functions
98 --
99
100 function WdrMaus.parseElefantenseite(self)
101 self.id = self.page_url:match('/([%w_]-)$')
102 or error('no match: media ID')
103
104 local rooturl = self.page_url:match('(%w+://.+/%w+)/.*')
105 or error('no match: root url')
106
107 local qo = {fetch_type='config'}
108 local configuration = quvi.fetch(rooturl .. '/data/configuration.php5', qo)
109
110 local streamingServerPath =
111 WdrMaus.getXMLvalue(configuration, 'streamingServerPath')
112
113 local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5', qo)
114
115 local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id)
116 local metadata = quvi.fetch(rooturl .. '/' .. metadataPath, qo);
117
118 streamingServerPath = string.gsub(streamingServerPath, '/$', '')
119 self.url = { streamingServerPath .. WdrMaus.getXMLvalue(metadata, 'file') }
120 self.title = WdrMaus.getXMLvalue(metadata, 'title')
121
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')
125
126 return self
127 end
128
129 function WdrMaus.parseKaeptnblaubaerseite(self)
130 self.id = self.page_url:match('/([^/]-)$') or error('no match: media ID')
131
132 local qo = {fetch_type='config'}
133 local metadatasite = quvi.fetch(
134 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5', qo)
135
136 local matcher = string.gsub(self.id, '-' , '.')
137 metadata = metadatasite:match('.*(<img.-' .. matcher .. ')')
138 or error('no match: metadata')
139
140 self.title = metadata:match('<p>%s-(.-)%s-<br') or error('no match: title')
141 local thumb_rel = metadata:match('<img src="(.-)"') or ''
142
143 thumb_rel = string.gsub(thumb_rel, '%.%.', '')
144 self.thumbnail_url = 'http://www.wdrmaus.de/kaeptnblaubaerseite' ..thumb_rel
145
146 self.url = { self.page_url:match('.-(rtmp.-flv)')
147 or error('no match: media stream URL') }
148 return self
149 end
150
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
158 end
159
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
164 end
165
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')
171 end
172
173 -- vim: set ts=2 sw=2 tw=72 expandtab: