From b75edb213667d8d85e1a1b2bc93b7fa302648464 Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Tue, 18 Feb 2025 22:56:08 +0100 Subject: [PATCH] Support Roman Numeral Parsing, added Volume Name to cbz filename --- main.go | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 97c6f6b..bfd67c1 100644 --- a/main.go +++ b/main.go @@ -367,7 +367,7 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc for ch := chapterList.Front(); ch != nil; ch = ch.Next() { chap := ch.Value.(Chapter) - zipPath := basePath + "Chapter " + chap.chDisplay + ".cbz" + zipPath := basePath + volume.Info.Title + " Chapter " + chap.chDisplay + ".cbz" if _, err = os.Stat(zipPath); err != nil { err := os.Remove(zipPath) @@ -440,6 +440,7 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc newZip.Close() newZipFile.Close() } + epub.Close() os.Remove(file) } @@ -828,11 +829,15 @@ func GenerateMangaChapterList(navigation FileWrapper) *list.List { r, _ := regexp.Compile(regex) num := r.FindStringSubmatch(label)[1] parse, _ := strconv.ParseInt(num, 10, 8) - if parse == 0 { - fmt.Printf("Unlikely Chapter Number Detected (0): %s/n", label) + if int8(parse) == 0 { + fmt.Printf("Unlikely Chapter Number Detected (0): %s/n", num) + fmt.Println("Attempting Roman Numerals") + lastMainChapter = int8(romanToInt(num)) + } else { + lastMainChapter = int8(parse) } - lastMainChapter = int8(parse) subChapter = int8(0) + } else { if lastMainChapter == -1 { subChapter -= 1 @@ -856,3 +861,28 @@ func GenerateMangaChapterList(navigation FileWrapper) *list.List { return FinalizeChapters(chapters, pageList) } + +func romanToInt(s string) int { + + know := map[string]int{ + "I": 1, + "V": 5, + "X": 10, + "L": 50, + "C": 100, + "D": 500, + "M": 1000, + } + lengthOfString := len(s) + lastElement := s[len(s)-1 : lengthOfString] + var result int + result = know[lastElement] + for i := len(s) - 1; i > 0; i-- { + if know[s[i:i+1]] <= know[s[i-1:i]] { + result += know[s[i-1:i]] + } else { + result -= know[s[i-1:i]] + } + } + return result +}