From 03f4cce8245467812f362cf4b8b65a24e49f7a7c Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Thu, 3 Jan 2013 14:07:56 +0200 Subject: [PATCH] wdrmaus.lua: fail if URL path patterns do not match Have the script raise an error if none of the URL path patterns. Otherwise the users will only get a cryptic error about missing media property values. Other: * Set "fetch_type=config" for quvi.fetch(non-page_url) calls * Replace if-elseif -block with a lookup table * Trim a long line to fit 72 chars * Remove an extra newline Signed-off-by: Toni Gundogdu --- share/lua/website/wdrmaus.lua | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/share/lua/website/wdrmaus.lua b/share/lua/website/wdrmaus.lua index 8432589..3ee2520 100644 --- a/share/lua/website/wdrmaus.lua +++ b/share/lua/website/wdrmaus.lua @@ -46,7 +46,6 @@ -- -- There are more sections but they seem to provide no videos. - local WdrMaus = {} -- Utility functions unique to this script -- Identify the script. @@ -75,18 +74,23 @@ end function parse(self) self.host_id = "wdrmaus" + local a = { + {pat='kaeptnblaubaerseite', func=WdrMaus.parseKaeptnblaubaerseite}, + {pat='sachgeschichten', func=WdrMaus.parseSachgeschichten}, + {pat='elefantenseite', func=WdrMaus.parseElefantenseite} + } + local U = require 'quvi/url' local t = U.parse(self.page_url) + local s = {} - if t.path:match('elefantenseite') then - WdrMaus.parseElefantenseite(self) - elseif t.path:match('kaeptnblaubaerseite') then - WdrMaus.parseKaeptnblaubaerseite(self) - elseif t.path:match('sachgeschichten') then - WdrMaus.parseSachgeschichten(self) + for _,v in pairs(a) do + if t.path:match(v.pat) then return v.func(self) end + table.insert(s, v.pat) end - return self + error(string.format("limited support for the {%s} sections only", + table.concat(s, ','))) end -- @@ -98,11 +102,13 @@ function WdrMaus.parseElefantenseite(self) or error('no match: media id') local rooturl = self.page_url:match('(%w+://.+/%w+)/.*') - local configuration = quvi.fetch(rooturl .. '/data/configuration.php5') - local streamingServerPath = WdrMaus.getXMLvalue(configuration, 'streamingServerPath') - local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5') + local qo = {fetch_type='config'} + local configuration = quvi.fetch(rooturl .. '/data/configuration.php5', qo) + local streamingServerPath = + WdrMaus.getXMLvalue(configuration, 'streamingServerPath') + local toc = quvi.fetch(rooturl .. '/data/tableOfContents.php5', qo) local metadataPath = WdrMaus.getMetadataPathFromToc(toc, self.id) - local metadata = quvi.fetch(rooturl .. '/' .. metadataPath); + local metadata = quvi.fetch(rooturl .. '/' .. metadataPath, qo); streamingServerPath = string.gsub(streamingServerPath, '/$', '') self.url = { streamingServerPath @@ -118,8 +124,9 @@ end function WdrMaus.parseKaeptnblaubaerseite(self) self.id = self.page_url:match('/([^/]-)$') + local qo = {fetch_type='config'} local metadatasite = quvi.fetch( - 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5') + 'http://www.wdrmaus.de/kaeptnblaubaerseite/baerchen/tv.php5', qo) local matcher = string.gsub(self.id, '-' , '.') metadata = metadatasite:match('.*(%s-(.-)%s-(.-)<') self.url = { metadata:match('(rtmp.-mp4)') } self.format = 'default' -- 2.11.4.GIT