mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: a5ee0f586232f40f0cd7fd5d7728ea7fe46b3eef
Parent: 718cda543de3788f758637b16bd9b2279fe3f460
Author: Ren Tatsumoto
Date:   Mon,  2 Nov 2020 09:20:24 +0300

add a base64 decoder

http://lua-users.org/wiki/BaseSixtyFour

Diffstat:
Msubs2srs.lua | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -184,6 +184,25 @@ local function trim(str) return str end +local base64d -- http://lua-users.org/wiki/BaseSixtyFour +do + local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' + base64d = function(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 +end + local function copy_sub_to_clipboard() platform.copy_to_clipboard("copy-on-demand", mp.get_property("sub-text")) end