Commit: 2e1dde4c299605d2475589af3223a6c0ca64ddbd
Parent: 1816dc8ccc885c620b1bb5ee22779dc1a7913620
Author: Ren Tatsumoto
Date: Wed, 26 Aug 2020 09:43:47 +0300
fight against anki limitations
Diffstat:
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -170,6 +170,33 @@ local function format_time(time)
end
end
+local function anki_compatible_length(str)
+ -- anki forcibly mutilates all filenames longer than 64 characters
+ -- leave 25 characters for the filename
+ -- the rest is reserved for the timestamp, which is added later
+ local args = {
+ 'awk',
+ '-v', string.format('str=%s', str),
+ '-v', 'limit=25',
+ 'BEGIN{print substr(str, 1, limit); exit}'
+ }
+
+ local ret = mp.command_native{
+ name = "subprocess",
+ playback_only = false,
+ capture_stdout = true,
+ args = args
+ }
+
+ if ret.status == 0 then
+ ret.stdout = remove_newlines(ret.stdout)
+ ret.stdout = remove_leading_trailing_spaces(ret.stdout)
+ return ret.stdout
+ else
+ return 'subs2srs'
+ end
+end
+
local function construct_filename(sub)
local filename = mp.get_property("filename") -- filename without path
@@ -177,6 +204,10 @@ local function construct_filename(sub)
filename = remove_text_in_brackets(filename)
filename = remove_special_characters(filename)
+ if contains_non_latin_letters(filename) then
+ filename = anki_compatible_length(filename)
+ end
+
filename = string.format(
'%s_(%s-%s)',
filename,