Commit: 4f537874f2ca23bb28fa1dd8f4c5576313b2fa80
Parent: 1613dfd0d1c4cfb2a3887ebcc16e5e7775db762d
Author: Ren Tatsumoto
Date: Fri, 14 May 2021 14:59:29 +0000
Merge pull request #42 from Luukuton/master
fixed some regressions when deleting the episode number and added a new option
Diffstat:
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/.github/RELEASE/subs2srs.conf b/.github/RELEASE/subs2srs.conf
@@ -68,6 +68,10 @@ tag_nuke_parentheses=no
# Remove the episode number before substituting %n into tag
tag_del_episode_num=yes
+# Remove everything after the episode number before substituting %n into tag
+# Does nothing if the previous option tag_del_episode_num is disabled.
+tag_del_after_episode_num=yes
+
# Convert filename to lowercase for tagging.
tag_filename_lowercase=no
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -71,6 +71,7 @@ local config = {
tag_nuke_brackets = true, -- delete all text inside brackets before subsituting filename into tag
tag_nuke_parentheses = false, -- delete all text inside parentheses before subsituting filename into tag
tag_del_episode_num = true, -- delete the episode number if found
+ tag_del_after_episode_num = true, -- delete everything after the found episode number (does nothing if tag_del_episode_num is disabled)
tag_filename_lowercase = false, -- convert filename to lowercase for tagging.
-- Misc info
@@ -307,26 +308,34 @@ local function get_episode_number(filename)
local episode
for _, pattern in pairs(ep_num_patterns) do
if episode ~= nil then break end
- _, _, episode = string.find(filename_reversed, pattern)
+ _, ep_end_position, episode = string.find(filename_reversed, pattern)
end
if not is_empty(episode) then
- return episode:reverse()
+ -- As the string (from where the end position is) was reversed,
+ -- subtracting the end_position from the length of the filename will get us the start position
+ return episode:reverse(), string.len(filename) - ep_end_position
else
- return ''
+ return '', nil
end
end
local function tag_format(filename)
- local episode = get_episode_number(filename)
-
- if config.tag_del_episode_num == true then
- filename = filename:gsub(episode, '')
- end
-
filename = remove_extension(filename)
filename = remove_common_resolutions(filename)
+ local episode, ep_start_position = get_episode_number(filename)
+
+ if config.tag_del_episode_num == true and ep_start_position ~= nil then
+ if config.tag_del_after_episode_num == true then
+ -- Removing everything (e.g. episode name) after the episode number including itself.
+ filename = filename:sub(0, ep_start_position)
+ else
+ -- Removing the first found instance of the episode number.
+ filename = filename:reverse():gsub(episode:reverse(), '', 1):reverse()
+ end
+ end
+
if config.tag_nuke_brackets == true then
filename = remove_text_in_brackets(filename)
end