Package: libquvi-scripts
Version: 0.4.8-3
Severity: wishlist

Please support the German television services ARD and ZDF. For starters
I attached some ideas on how to do that. The attached webscripts are
still incomplete:

1) They only provide the best quality stream even though there are
   multiple.
2) They fail to provide stream information (length, format, etc.).
3) They are probably fragile. For instance the ARD script should
   probably do proper character set reencoding.

Suggestions welcome.

Helmut

PS: Oh. You need a license? I hereby grant BSD-3 on the attached
    webscripts. Downlicense as GPL-something if you wish so.
-- TODO: Support worse formats.

function ident(self)
    --package.path = self.script_dir .. '/?.lua'
    package.path = '/usr/share/libquvi-scripts/lua/website/?.lua'
    local C      = require 'quvi/const'
    local r      = {}
    r.domain     = "www%.ardmediathek%.de"
    r.formats    = "default"
    r.categories = C.proto_rtmp
    local U      = require 'quvi/util'
    r.handles    = U.handles(self.page_url, {r.domain},
                             {"/das%-erste/"} , {"documentId=%d+"})
    return r
end

function query_formats(self)
    return self
end

function parse(self)
    self.host_id = "ardmediathek"

    self.id = self.page_url:match("%?documentId=(%d+)")
            or error ("no match: media id")

    local page = quvi.fetch(self.page_url)

    self.title = page:match('<meta property="og:title" content="(.-)"/>')
            or error ("no match: media title")

    self.duration = 0

    local url
    for a, b in page:gmatch(
            'mediaCollection%.addMediaStream%(%d+, %d+, ' ..
            '"(rtmp://.-/)", "mp4:(.-)%?.-", ".-"%);') do
        -- The url contains escaped ISO-8859-1 characters, but the
        -- server expects the url in UTF-8.
        b = b:gsub("%%[Cc]4",   "\195\132")
            :gsub("%%[Dd]6",    "\195\150")
            :gsub("%%[Dd][Cc]", "\195\156")
            :gsub("%%[Ee]4",    "\195\164")
            :gsub("%%[Ff]6",    "\195\182")
            :gsub("%%[Ff][Cc]", "\195\188")
            :gsub("%%[Dd][Ff]", "\195\159")
        -- Last stream has best quality
        url = a .. b
    end
    if not url then
        error ("no match: media stream")
    end

    self.url = {url}
    return self
end

-- vim: set ts=4 sw=4 tw=72 expandtab:
-- TODO: Support RTSP streams on hstreaming.zdf.de

function ident(self)
    --package.path = self.script_dir .. '/?.lua'
    package.path = '/usr/share/libquvi-scripts/lua/website/?.lua'
    local C      = require 'quvi/const'
    local r      = {}
    r.domain     = "zdf%.de"
    r.formats    = "default"
    r.categories = C.proto_mms
    local U      = require 'quvi/util'
    r.handles    = U.handles(self.page_url, {r.domain},
                             {"/ZDFmediathek/beitrag/video/"})
    return r
end

function query_formats(self)
    return self
end

function parse(self)
    self.host_id = "zdfmediathek"

    self.id = self.page_url:match("/ZDFmediathek/beitrag/video/(%d+)")
            or error ("no match: media id")

    local page = quvi.fetch(self.page_url)

    self.title = page:match(
            "<title>(.-) %- ZDFmediathek %- ZDF Mediathek</title>")
            or error ("no match: media title")

    local metaurl = page:match(
            '<a href="(http://wstreaming%.zdf%.de/.-)" ')
            or error ("no match: metaurl")

    local meta = quvi.fetch(metaurl)

    self.duration = 0
    self.url      = {meta:match('<Ref href="(.-)"/>')
                     or error ("no match: stream")}

    return self
end

-- vim: set ts=4 sw=4 tw=72 expandtab:

Reply via email to