Commit: 2e04adcbaef160e66c30d86fb3a8dd57c78837c0
Parent: aa7d2a3a9d9e40373b72ea90128dc39d0d3acf90
Author: Ren Tatsumoto
Date: Thu, 15 Oct 2020 06:36:04 +0300
config supports both collection_path and anki_user as ways to specify media output dir
Diffstat:
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -36,7 +36,8 @@ For complete usage guide, see <https://github.com/Ajatt-Tools/mpvacious/blob/mas
]]
local config = {
- collection_path = string.format('%s/.local/share/Anki2/%s/collection.media/', os.getenv("HOME"), os.getenv("USER")),
+ collection_path = '', -- full path to the collection. most users should leave it empty.
+ anki_user = 'User 1', -- your anki username. it is displayed on the title bar of the Anki window.
autoclip = false, -- copy subs to the clipboard or not
nuke_spaces = true, -- remove all spaces or not
snapshot_quality = 5, -- from 0=lowest to 100=highest
@@ -84,6 +85,17 @@ local function is_empty(var)
return var == nil or var == '' or (type(var) == 'table' and next(var) == nil)
end
+local function is_dir(path)
+ if is_empty(path) then
+ return false
+ end
+ local file_info = utils.file_info(path)
+ if file_info == nil then
+ return false
+ end
+ return file_info.is_dir == true
+end
+
local function capitalize_first_letter(string)
return string:gsub("^%l", string.upper)
end
@@ -332,7 +344,16 @@ local function join_media_fields(note1, note2)
return note1
end
+local function construct_collection_path()
+ return string.format('%s/.local/share/Anki2/%s/collection.media/', os.getenv("HOME"), config.anki_user)
+end
+
local function check_config_sanity()
+ if not is_dir(config.collection_path) then
+ -- collection path wasn't specified. construct it using config.anki_user
+ config.collection_path = construct_collection_path()
+ end
+
if config.snapshot_width < 1 then
config.snapshot_width = -2
end