From 8e2211fd04ee51506a73a3b9ba0c96b8ccb8529d Mon Sep 17 00:00:00 2001 From: Rose Liverman Date: Tue, 4 Aug 2026 20:27:09 -0600 Subject: [PATCH] close #7 detect_type() added --- asymptome.lua | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/asymptome.lua b/asymptome.lua index ad090b7..f03abdf 100755 --- a/asymptome.lua +++ b/asymptome.lua @@ -165,6 +165,27 @@ local update_progress_prompt = function(book) -- saving is handled by a higher function on the stack end +local detect_type = function(input) + local author, series, genre + local i = input:find(" %(.-series.-%)") + if i then + series = input:sub(1, i - 1) + end + local i = input:find(" %(trilogy%)") + if i then + series = input:sub(1, i - 1) + end + local i = input:find(" %(.-author%)") + if i then + author = input:sub(1, i - 1) + end + local i = input:find(" %(genre%)") + if i then + genre = input:sub(1, i - 1) + end + return author, series, genre +end + local get_book = function(data, input) local title, author, series, genre local i, j = input:find(" by ") @@ -173,18 +194,7 @@ local get_book = function(data, input) author = input:sub(j + 1) debug("get_book() Title by Author detected:", title, author) else - local i = input:find(" (author)") - if i then - author = input:sub(1, i - 1) - end - local i = input:find(" (series)") - if i then - series = input:sub(1, i - 1) - end - local i = input:find(" (genre)") - if i then - genre = input:sub(1, i - 1) - end + author, series, genre = detect_type(input) if not (author or series or genre) then title = input @@ -257,22 +267,7 @@ local import_json = function(data, file_name) progress = 0, } - local i = title:find(" %(.-series.-%)") - if i then - book.series = title:sub(1, i - 1) - end - local i = title:find(" %(trilogy%)") - if i then - book.series = title:sub(1, i - 1) - end - local i = title:find(" %(.-author%)") - if i then - book.author = title:sub(1, i - 1) - end - local i = title:find(" %(genre%)") - if i then - book.genre = title:sub(1, i - 1) - end + book.author, book.series, book.genre = detect_type(title) if not (book.series or book.author or book.genre) then local i, j = title:find(" by ")