Commit: 7fa880be81988d65b928461ea0db33dca8cda79e
Parent: 349b4774fb51c1ee1fa4fce0da9f6c93815e26b7
Author: Ren Tatsumoto
Date: Sat, 9 Apr 2022 13:56:05 +0300
let the user disable audio or snapshots
Diffstat:
3 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/.github/RELEASE/subs2srs.conf b/.github/RELEASE/subs2srs.conf
@@ -9,6 +9,8 @@ deck_name=Bank::subs2srs
model_name=Japanese sentences
# Field names as they appear in the selected note type.
+# If you set `audio_field` or `image_field` empty,
+# the corresponding media file will not be created.
sentence_field=SentKanji
audio_field=SentAudio
image_field=Image
diff --git a/encoder.lua b/encoder.lua
@@ -1,5 +1,6 @@
local mp = require('mp')
local utils = require('mp.utils')
+local helpers = require('helpers')
local _config, _store_fn, _os_temp_dir, _subprocess
local encoder
@@ -149,34 +150,42 @@ end
-- main interface
local create_snapshot = function(timestamp, filename)
- local source_path = mp.get_property("path")
- local output_path = utils.join_path(_os_temp_dir(), filename)
- local args = encoder.make_snapshot_args(source_path, output_path, timestamp)
- local on_finish = function()
- _store_fn(filename, output_path)
- os.remove(output_path)
+ if not helpers.is_empty(_config.image_field) then
+ local source_path = mp.get_property("path")
+ local output_path = utils.join_path(_os_temp_dir(), filename)
+ local args = encoder.make_snapshot_args(source_path, output_path, timestamp)
+ local on_finish = function()
+ _store_fn(filename, output_path)
+ os.remove(output_path)
+ end
+ _subprocess(args, on_finish)
+ else
+ print("Snapshot will not be created.")
end
- _subprocess(args, on_finish)
end
local create_audio = function(start_timestamp, end_timestamp, filename, padding)
- local source_path = mp.get_property("path")
- local output_path = utils.join_path(_os_temp_dir(), filename)
+ if not helpers.is_empty(_config.audio_field) then
+ local source_path = mp.get_property("path")
+ local output_path = utils.join_path(_os_temp_dir(), filename)
- if padding > 0 then
- start_timestamp, end_timestamp = pad_timings(padding, start_timestamp, end_timestamp)
- end
+ if padding > 0 then
+ start_timestamp, end_timestamp = pad_timings(padding, start_timestamp, end_timestamp)
+ end
- local args = encoder.make_audio_args(source_path, output_path, start_timestamp, end_timestamp)
- for arg in string.gmatch(_config.use_ffmpeg and _config.ffmpeg_audio_args or _config.mpv_audio_args, "%S+") do
- -- Prepend before output path
- table.insert(args, #args, arg)
- end
- local on_finish = function()
- _store_fn(filename, output_path)
- os.remove(output_path)
+ local args = encoder.make_audio_args(source_path, output_path, start_timestamp, end_timestamp)
+ for arg in string.gmatch(_config.use_ffmpeg and _config.ffmpeg_audio_args or _config.mpv_audio_args, "%S+") do
+ -- Prepend before output path
+ table.insert(args, #args, arg)
+ end
+ local on_finish = function()
+ _store_fn(filename, output_path)
+ os.remove(output_path)
+ end
+ _subprocess(args, on_finish)
+ else
+ print("Audio will not be created.")
end
- _subprocess(args, on_finish)
end
local init = function(config, store_fn, os_temp_dir, subprocess)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (C) 2020-2022 Ren Tatsumoto
+Copyright (C) 2020-2022 Ren Tatsumoto and contributors
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
@@ -419,9 +419,13 @@ end
local function construct_note_fields(sub_text, snapshot_filename, audio_filename)
local ret = {
[config.sentence_field] = sub_text,
- [config.image_field] = string.format('<img alt="snapshot" src="%s">', snapshot_filename),
- [config.audio_field] = string.format('[sound:%s]', audio_filename),
}
+ if not helpers.is_empty(config.image_field) then
+ ret[config.image_field] = string.format('<img alt="snapshot" src="%s">', snapshot_filename)
+ end
+ if not helpers.is_empty(config.audio_field) then
+ ret[config.audio_field] = string.format('[sound:%s]', audio_filename)
+ end
if config.miscinfo_enable == true then
ret[config.miscinfo_field] = substitute_fmt(config.miscinfo_format)
end
@@ -434,7 +438,9 @@ end
local function join_media_fields(new_data, stored_data)
for _, field in pairs { config.audio_field, config.image_field, config.miscinfo_field } do
- new_data[field] = table.get(stored_data, field, "") .. table.get(new_data, field, "")
+ if not helpers.is_empty(field) then
+ new_data[field] = table.get(stored_data, field, "") .. table.get(new_data, field, "")
+ end
end
return new_data
end