--[[
ZDF Nachrichten-App
Vers.: 0.5
Copyright (C) 2016, bazi98
with many hints and codessniplets from SatBaby, big thx. frm my to him
License: GPL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
Copyright (C) for the linked video and for the heute-Logo by the ZDF or the respective owners!
]]
--[[ Bugliste:
Fehlende Automtik bei Auswahl- und Feiertagsberücksichtigung bei der 12:00 Uhr,17:00 Uhr-Ausgaben von der Seite
http://www.zdf.de/ZDFmediathek/hauptnavigation/nachrichten/ganze-sendungen?bc=nrt;nrg&gs=166&flash=off
dort sind sowohl die 12:00 Uhr, 17:00 Uhr und 19:00 Uhr-Ausgaben der Nachrichten gemeinsam aufgeführt,
die 19:00 Uhr Hauptsendung kann zuverlässig anders ausgelesen werden, die anderen Sendungen nicht
]]
local json = require "json"
basisurl = "http://www.zdf.de"
basisstreamurl = "http://nrodl.zdf.de/none/zdf/"
HD = "3256k_p15v12.mp4"
MD = "2328k_p35v12.mp4"
SD = "1456k_p13v12.mp4"
LD = "436k_p9v12.mp4"
qual = HD
heute=(os.date ("%d.%m.%Y"))
heute2=(os.date ("%y/%m/%y%m%d"))
gestern = (os.date("%d.%m.%Y", os.time() - 3600*24))
gestern2 = (os.date ("%y/%m/%y%m%d", os.time() - 3600*24))
wochentag = (os.date ("%A")) --- Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
time = (os.date ("%H%M"))
--Objekte
function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end
function init()
n = neutrino();
p = {}
func = {}
pmid = 0
stream = 1
tmpPath = "/tmp"
zdf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0uzgcivo6bgWyKkcBEo28QnUmIR//WG66G6TRw7uvF+dxBxGBQw6FAyEOH28757IEwRU+KpjnnwXLD/yp2n4/e3XmZPli5osDi3WiFSkbT9xTU6AfIVlVVekcsp6+XDARoQcOmPrTC0J/hQX/WgjJfX+Vi1dUlPXFYmkz1mxYB5WyMz+dr+ZmbdpeXcB0hFnOZSp+BF+g/PRB+n5d47SFybaePWCp9Bq1BTGX9sTt/8RIxHULwnSKf9VFpM0gFvEv3gmirvcRMRfSj7ye1YhK7pt+3rxvgnXoSRPzZS1wvInY3OE51z6C9kCfGfDYSYr5LokLccy6Rz4K7wLfB4RSrumWQFIz9D3Okn7IiMqqOAAAAAElFTkSuQmCC")
end
function add_stream(t,u)
p[#p+1]={title=t,url=u,access=stream}
end
function getdata(Url,outputfile)
if Url == nil then return nil end
if Curl == nil then
Curl = curl.new()
end
local ret, data = Curl:download{url=Url,A="Mozilla/5.0;",followRedir=true,o=outputfile }
if ret == CURL.OK then
return data
else
return nil
end
end
-- function from http://lua-users.org/wiki/BaseSixtyFour
-- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- decode
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
function decodeImage(b64Image)
local imgTyp = b64Image:match("data:image/(.-);base64,")
local repData = "data:image/" .. imgTyp .. ";base64,"
local b64Data = string.gsub(b64Image, repData, "");
local tmpImg = os.tmpname()
local retImg = tmpImg .. "." .. imgTyp
local f = io.open(retImg, "w+")
f:write(dec(b64Data))
f:close()
os.remove(tmpImg)
return retImg
end
function fill_playlist()
--- ZDF heute Express, Kurznachrichten zu wechslenden Uhrzeit, wird jeweils die aktuellste angeboten
local data = getdata('www.zdf.de/ZDFmediathek/kanaluebersicht/aktuellste/218522?flash=off',nil)
if data then
local xpress_seite,h = data:match('"(/ZDFmediathek/beitrag/video/%d+/heute%-Xpress.-flash=off)".- (%d%d:%d%d)<')
data = getdata('http://www.zdf.de'..xpress_seite,nil)
if data then
local xpress = data:match('2000 = "1230") and ( time <= "1430") and (wochentag ~= "Saturday" ) and (wochentag ~= "Sunday" ) then
add_stream("heute am Mittag vom " .. heute .. "-12.00 Uhr",basisstreamurl .. heute2 .. "_h12_" ..qual)
end
--- ZDF heute in Deutschland 14.00 Uhr, wird nur Montag bis Freitag und nicht an Feiertagen gesendet
local data = getdata('http://www.zdf.de/ZDFmediathek/kanaluebersicht/aktuellste/1522522?bc=rub;kua884718&flash=off',nil)
if data then
local deutschland_seite,h = data:match('"(/ZDFmediathek/beitrag/video/%d+/ZDF%-heute%-in%-Deutschland%-vom-.-?bc=rub;.-flash=off)".- (%d%d:%d%d)<')
data = getdata('http://www.zdf.de'..deutschland_seite,nil)
if data then
local deutschland = data:match('2000 = "1730") and ( time <= "1945") and (wochentag ~= "Saturday" ) then
add_stream("heute am Nachmittag vom " .. heute .. "-17.00 Uhr",basisstreamurl .. heute2 .. "_h17_" ..qual)
end
--- ZDF heute 19:00 Hauptsendung, täglich, es wird immer die letzte Sendung angeboten, keine Feiertagsanpassung nötig
if ( time >= "1955") then
add_stream("heute Hauptausgabe vom " .. heute .. "-19.00 Uhr",basisstreamurl .. heute2 .. "_h19_" ..qual)
else
add_stream("heute Hauptausgabe vom " .. gestern .. "-19.00 Uhr",basisstreamurl .. gestern2 .. "_h19_" ..qual)
end
--- ZDF heute journal, täglich ca. 21:45 Uhr
local data = getdata('http://www.zdf.de/ZDFmediathek/hauptnavigation/nachrichten/ganze-sendungen?bc=nrt;nrg&gs=228&flash=off',nil)
if data then
local hjo_seite,h = data:match('"(/ZDFmediathek/beitrag/video/%d+/ZDF%-heute%-journal.-flash=off)">.- (%d%d:%d%d)<')
data = getdata('http://www.zdf.de'..hjo_seite,nil)
if data then
local hjo = data:match('2000