- implement base64 encoded netzkino icon
authorsvenhoefer <svenhoefer@svenhoefer.com>
Thu, 7 Aug 2014 12:12:16 +0000 (14:12 +0200)
committerEzak <kazems@gmx.de>
Sat, 25 Oct 2014 15:41:13 +0000 (17:41 +0200)
var/plugins/netzkino.lua

index 9b05e2f..20bca0d 100644 (file)
@@ -22,6 +22,45 @@ function key_setup(a)
        return ret
 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 init()
        -- set collectgarbage() interval from 200 (default) to 50
        collectgarbage('setpause', 50)
@@ -41,9 +80,11 @@ function init()
        wget_busy_file = "/tmp/.netzkino_wget.busy"
 
        -- use netzkino icon placed in same dir as the plugin ...
-       netzkino_png = script_path() .. "netzkino.png"
+       --netzkino_png = script_path() .. "netzkino.png"
        -- ... or use icon placed in one of neutrino's icon dirs
        --netzkino_png = "netzkino"
+       -- ... or use a base64 encoded icon
+       netzkino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/tJ84gSgI/bJujbeS9YPXdcLEifKJp57tfhIOkpDc/NofPfeuJ32dEJe+t8TkAqjSixk1Seo5yCmgMI0JheYvq123aE5sqEQqTcKFCwiI894CcDZrgWISDeBHx4mSG3fxr9kagqXev2TC1c/tF/gU5kpOQwApURgAAAABJRU5ErkJggg==");
 
        -- create download script
        create_downloader();