summaryrefslogtreecommitdiff
path: root/.local/share
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2014-01-14 11:13:47 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2014-01-14 11:13:47 +0100
commit952242168babec26e4c80a321ce5abc3e551eabd (patch)
tree6485f0722c59100e0f4cbe7b194048981d32bf8a /.local/share
parenta3eb16b4f7a91bb25d64da2fb09b6099717939b9 (diff)
downloaddotfiles-952242168babec26e4c80a321ce5abc3e551eabd.tar.gz
dotfiles-952242168babec26e4c80a321ce5abc3e551eabd.tar.bz2
dotfiles-952242168babec26e4c80a321ce5abc3e551eabd.zip
quvi/zdf: Support hd formats
THis commits also cleans up the code a bit.
Diffstat (limited to '.local/share')
-rw-r--r--.local/share/libquvi-scripts/lua/website/zdfmediathek.lua60
1 files changed, 46 insertions, 14 deletions
diff --git a/.local/share/libquvi-scripts/lua/website/zdfmediathek.lua b/.local/share/libquvi-scripts/lua/website/zdfmediathek.lua
index ca2cc28..af061fc 100644
--- a/.local/share/libquvi-scripts/lua/website/zdfmediathek.lua
+++ b/.local/share/libquvi-scripts/lua/website/zdfmediathek.lua
@@ -5,10 +5,9 @@ function ident(self)
local r = {}
r.domain = "zdf%.de"
r.formats = "default|best"
- r.categories = C.proto_rtmp
+ r.categories = C.proto_http
local U = require 'quvi/util'
- r.handles = U.handles(self.page_url, {r.domain},
- {"/ZDFmediathek/"})
+ r.handles = U.handles(self.page_url, {r.domain}, {"/ZDFmediathek/"})
return r
end
@@ -26,28 +25,61 @@ function parse(self)
self.id = self.page_url:match("/ZDFmediathek/#?/?beitrag/video/(%d+)")
or error ("no match: media id")
- local xmlwebservice_url = "http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?id=" .. self.id
+ local xml = { "http://www.zdf.de/",
+ "ZDFmediathek/xmlservice/web/beitragsDetails?id=", self.id }
- local c = quvi.fetch(xmlwebservice_url, {fetch_type='config'})
- if c:match('<error>') then
- local s = c:match('<message>(.-)[\n<]')
- error( (not s) and "no match: error message" or s )
+ local c = quvi.fetch(table.concat(xml), {fetch_type='config'})
+ if not(c:match('<statuscode>ok</statuscode>')) then
+ local msg = { 'error: ', xml_get(c, 'statuscode', false),
+ ' - ', xml_get(c, 'debuginfo', false) }
+ error(table.concat(msg))
end
- self.title = c:match('<title>([^<]*)</title>')
- or error("no match: media title")
+ self.title = xml_get(c, 'title', false)
+ self.thumbnail_url = c:match('<teaserimage alt=".-" key="946x532">'..
+ '([^<]+)</teaserimage>')
- self.thumbnail_url = c:match('<teaserimage alt="[^"]*" key="946x532">([^<]*)</teaserimage>')
+ local url = c:match('<quality>veryhigh</quality>%s*' ..
+ '<url>(http://n?rodl%.zdf%.de/[^<]+%.mp4)</url>')
- local url = c:match('<quality>veryhigh</quality>[ \n]*<url>(http://nrodl.zdf.de/[^<]*\.mp4)</url>')
-
- if (c:match('<width>1024</width>')) then
+ if (c:match('<height>576</height>%s*<width>1024</width>')) then
url = string.gsub(url, "1456k_p13v11", "2256k_p14v11")
end
+ meta = c:match('<quality>hd</quality>%s*<url>([^>]+%.meta)</url>')
+ if meta then
+ url = http_mp4_from_meta(meta) or url
+ -- OLD code:
+ -- known replacements from veryhigh mp4 to hd mp4:
+ -- either: suffix _hd instead of _vh
+ --url = string.gsub(url, "_vh.mp4", "_hd.mp4")
+ -- or:
+ --url = string.gsub(url, "1596k_p13v9", "3056k_p15v9")
+ end
+
self.url = { url }
return self
end
+
+-- utlity
+
+--
+function http_mp4_from_meta(meta_url)
+ local c = quvi.fetch(meta_url, {fetch_type='config'})
+ local path = c:match("mp4:(.-%.mp4)")
+
+ return path and "http://nrodl.zdf.de/none/" .. path or nil
+end
+
+
+--For very simple XML value extraction.
+function xml_get(d, e, is_cdata)
+ local p = is_cdata and '.-%w+%[(.-)%].-' or '(.-)'
+ local t = {'<',e,'>', p, '</',e,'>'}
+ return d:match(table.concat(t))
+ or error(table.concat({'no match: element: ',e}))
+end
+
-- vim: set ts=4 sw=4 tw=72 expandtab: