Update NEWS for v0.9.20131130
[libquvi-scripts.git] / share / lua / website / wdrmaus.lua
Commit [+]AuthorDateLineData
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +01001
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
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +010049local WdrMaus = {} -- Utility functions unique to this script
50
51-- Identify the script.
52function 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
65end
66
67-- Query available formats.
68function query_formats(self)
69 self.formats = 'default'
70 return self
71end
72
73-- Parse media URL.
74function parse(self)
75 self.host_id = "wdrmaus"
76
03f4cce8
TG
Toni Gundogdu2013-01-03 14:07:56 +020077 local a = {
78 {pat='kaeptnblaubaerseite', func=WdrMaus.parseKaeptnblaubaerseite},
79 {pat='sachgeschichten', func=WdrMaus.parseSachgeschichten},
80 {pat='elefantenseite', func=WdrMaus.parseElefantenseite}
81 }
82
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +010083 local U = require 'quvi/url'
84 local t = U.parse(self.page_url)
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +020085 local s = {}
86d1c641 Guido Leisker2013-01-03 08:55:39 +010086
03f4cce8
TG
Toni Gundogdu2013-01-03 14:07:56 +020087 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)
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +010090 end
91
03f4cce8
TG
Toni Gundogdu2013-01-03 14:07:56 +020092 error(string.format("limited support for the {%s} sections only",
93 table.concat(s, ',')))
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +010094end
95
96--
97-- Utility functions
98--
99
100function WdrMaus.parseElefantenseite(self)
ef578748 Toni Gundogdu2013-02-07 21:02:54 +0200101 self.id = self.page_url:match('/([%w_]-)$')
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200102 or error('no match: media ID')
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100103
104 local rooturl = self.page_url:match('(%w+://.+/%w+)/.*')
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200105 or error('no match: root url')
106
03f4cce8
TG
Toni Gundogdu2013-01-03 14:07:56 +0200107 local qo = {fetch_type='config'}
108 local configuration = quvi.fetch(rooturl .. '/data/configuration.php5', qo)
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200109
03f4cce8
TG
Toni Gundogdu2013-01-03 14:07:56 +0200110 local streamingServerPath =
111 WdrMaus.getXMLvalue(configuration, 'streamingServerPath')
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200112
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +0200113 local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5', qo)
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200114
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100115 local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id)
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +0200116 local metadata = quvi.fetch(rooturl .. '/' .. metadataPath, qo);
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100117
118 streamingServerPath = string.gsub(streamingServerPath, '/$', '')
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200119 self.url = { streamingServerPath .. WdrMaus.getXMLvalue(metadata, 'file') }
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100120 self.title = WdrMaus.getXMLvalue(metadata, 'title')
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200121
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100122 -- 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')
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100125
126 return self
127end
128
129function WdrMaus.parseKaeptnblaubaerseite(self)
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200130 self.id = self.page_url:match('/([^/]-)$') or error('no match: media ID')
131
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +0200132 local qo = {fetch_type='config'}
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100133 local metadatasite = quvi.fetch(
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +0200134 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5', qo)
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200135
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100136 local matcher = string.gsub(self.id, '-' , '.')
137 metadata = metadatasite:match('.*(<img.-' .. matcher .. ')')
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200138 or error('no match: metadata')
139
140 self.title = metadata:match('<p>%s-(.-)%s-<br') or error('no match: title')
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100141 local thumb_rel = metadata:match('<img src="(.-)"') or ''
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200142
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100143 thumb_rel = string.gsub(thumb_rel, '%.%.', '')
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200144 self.thumbnail_url = 'http://www.wdrmaus.de/kaeptnblaubaerseite' ..thumb_rel
86d1c641 Guido Leisker2013-01-03 08:55:39 +0100145
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200146 self.url = { self.page_url:match('.-(rtmp.-flv)')
147 or error('no match: media stream URL') }
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100148 return self
149end
150
151function WdrMaus.parseSachgeschichten(self)
3096ff93 Toni Gundogdu2013-01-04 00:39:27 +0200152 self.id = self.page_url:match('%d+$') or error('no match: media ID')
03f4cce8 Toni Gundogdu2013-01-03 14:07:56 +0200153 local metadata = quvi.fetch(self.page_url)
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200154 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') }
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100157 return self
158end
159
160function WdrMaus.getXMLvalue(str, value)
161 ret = str:match('<' .. value .. '>(.-)</' .. value .. '>')
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200162 or error('Cannot match ' .. value)
163 return ret:match('<!%[CDATA%[(.+)]]>') or ret
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100164end
165
166function WdrMaus.getMetadataPathFromToc(toc, id)
167 -- the toc contains all paths for this root (f.i. elefantenkino)
3096ff93
TG
Toni Gundogdu2013-01-04 00:39:27 +0200168 local page = toc:match('<id>.-(' .. id .. '.-</xmlPath>)')
169 or error('no match: metadata path')
86d1c641
GL
Guido Leisker2013-01-03 08:55:39 +0100170 return WdrMaus.getXMLvalue(page, 'xmlPath')
171end
172
173-- vim: set ts=2 sw=2 tw=72 expandtab: