From fb157d6b773b110e35ab5a36a005b39a7e870f9b Mon Sep 17 00:00:00 2001
From: Neshura <neshura@neshweb.net>
Date: Tue, 18 Feb 2025 22:34:23 +0100
Subject: [PATCH 1/3] Add further metadata fields to the ComicInfo generation

---
 main.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index 1e3e21a..5b27b30 100644
--- a/main.go
+++ b/main.go
@@ -421,7 +421,7 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc
 					}
 				}
 
-				comicInfo, err := GenerateChapterMetadata(volume, serie, len(chap.pages), language)
+				comicInfo, err := GenerateChapterMetadata(volume, serie, len(chap.pages), language, chap.chDisplay)
 				if err != nil {
 					fmt.Println(err)
 				}
@@ -536,7 +536,7 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc
 	}
 }
 
-func GenerateChapterMetadata(volume jnc.VolumeAugmented, serie jnc.SerieAugmented, pageCount int, language string) ([]byte, error) {
+func GenerateChapterMetadata(volume jnc.VolumeAugmented, serie jnc.SerieAugmented, pageCount int, language string, chapterNumber string) ([]byte, error) {
 	comicInfo := ComicInfo{
 		XMLName: "ComicInfo",
 		XMLNS:   "http://www.w3.org/2001/XMLSchema-instance",
@@ -547,7 +547,9 @@ func GenerateChapterMetadata(volume jnc.VolumeAugmented, serie jnc.SerieAugmente
 	sInfo := serie.Info
 
 	comicInfo.Series = sInfo.Title
-	comicInfo.Number = vInfo.Number
+	comicInfo.Title = vInfo.Title
+	comicInfo.Number = chapterNumber
+	comicInfo.Volume = vInfo.Number
 
 	comicInfo.Count = -1 // TODO somehow fetch actual completion status
 
@@ -595,7 +597,9 @@ type ComicInfo struct {
 	XMLNS       string `xml:"xmlns,attr"`
 	XSI         string `xml:"xsi,attr"`
 	Series      string `xml:"Series"`
-	Number      int    `xml:"Number"`
+	Title       string `xml:"Title"`
+	Volume      int    `xml:"Volume"`
+	Number      string `xml:"Number"`
 	Count       int    `xml:"Count"`
 	Summary     string `xml:"Summary"`
 	Year        int    `xml:"Year"`

From 8c97c93b34954ca227e7c7f704dc7105ae6c1f4f Mon Sep 17 00:00:00 2001
From: Neshura <neshura@neshweb.net>
Date: Tue, 18 Feb 2025 22:36:48 +0100
Subject: [PATCH 2/3] Bugfix: epub file was removed before processing of
 chapters was done

---
 main.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go
index 5b27b30..923c4e1 100644
--- a/main.go
+++ b/main.go
@@ -434,8 +434,8 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc
 				epub.Close()
 				newZip.Close()
 				newZipFile.Close()
-				os.Remove(file)
 			}
+			os.Remove(file)
 		}
 	case "novel":
 		{
@@ -822,6 +822,9 @@ 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)
+			}
 			lastMainChapter = int8(parse)
 			subChapter = int8(0)
 		} else {

From cfaec3a4fda29953311ce1ca726693a4eea2dddf Mon Sep 17 00:00:00 2001
From: Neshura <neshura@neshweb.net>
Date: Tue, 18 Feb 2025 22:37:57 +0100
Subject: [PATCH 3/3] Bugfix: clean zip file before overwriting

---
 main.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/main.go b/main.go
index 923c4e1..ebd3549 100644
--- a/main.go
+++ b/main.go
@@ -369,6 +369,12 @@ func DownloadAndProcessEpub(jnovel jnc.Api, serie jnc.SerieAugmented, volume jnc
 
 				zipPath := basePath + "Chapter " + chap.chDisplay + ".cbz"
 
+				if _, err = os.Stat(zipPath); err != nil {
+					err := os.Remove(zipPath)
+					if err != nil {
+						return
+					}
+				}
 				newZipFile, err := os.Create(zipPath)
 				if err != nil {
 					panic(err)