mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 12:38:50 +02:00
fix(cbz): make pages be the first in the cbz by only be number
This commit is contained in:
@@ -30,10 +30,10 @@ func WriteChapterToCBZ(chapter *manga.Chapter, outputFilePath string) error {
|
|||||||
var fileName string
|
var fileName string
|
||||||
if page.IsSplitted {
|
if page.IsSplitted {
|
||||||
// Use the format page%03d-%02d for split pages
|
// Use the format page%03d-%02d for split pages
|
||||||
fileName = fmt.Sprintf("page_%04d-%02d%s", page.Index, page.SplitPartIndex, page.Extension)
|
fileName = fmt.Sprintf("%04d-%02d%s", page.Index, page.SplitPartIndex, page.Extension)
|
||||||
} else {
|
} else {
|
||||||
// Use the format page%03d for non-split pages
|
// Use the format page%03d for non-split pages
|
||||||
fileName = fmt.Sprintf("page_%04d%s", page.Index, page.Extension)
|
fileName = fmt.Sprintf("%04d%s", page.Index, page.Extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new file in the ZIP archive
|
// Create a new file in the ZIP archive
|
||||||
|
@@ -31,7 +31,7 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
IsConverted: true,
|
IsConverted: true,
|
||||||
ConvertedTime: time.Now(),
|
ConvertedTime: time.Now(),
|
||||||
},
|
},
|
||||||
expectedFiles: []string{"page_0000.jpg", "ComicInfo.xml", "Converted.txt"},
|
expectedFiles: []string{"0000.jpg", "ComicInfo.xml", "Converted.txt"},
|
||||||
},
|
},
|
||||||
//test case where there is only one page and no
|
//test case where there is only one page and no
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedFiles: []string{"page_0000.jpg"},
|
expectedFiles: []string{"0000.jpg"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Multiple pages with ComicInfo",
|
name: "Multiple pages with ComicInfo",
|
||||||
@@ -64,7 +64,7 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ComicInfoXml: "<Series>Boundless Necromancer</Series>",
|
ComicInfoXml: "<Series>Boundless Necromancer</Series>",
|
||||||
},
|
},
|
||||||
expectedFiles: []string{"page_0000.jpg", "page_0001.jpg", "ComicInfo.xml"},
|
expectedFiles: []string{"0000.jpg", "0001.jpg", "ComicInfo.xml"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Split page",
|
name: "Split page",
|
||||||
@@ -79,7 +79,7 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedFiles: []string{"page_0000-01.jpg"},
|
expectedFiles: []string{"0000-01.jpg"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,17 +17,16 @@ import (
|
|||||||
// MockConverter is a mock implementation of the Converter interface
|
// MockConverter is a mock implementation of the Converter interface
|
||||||
type MockConverter struct{}
|
type MockConverter struct{}
|
||||||
|
|
||||||
func (m *MockConverter) Format() constant.ConversionFormat {
|
func (m *MockConverter) ConvertChapter(chapter *manga.Chapter, quality uint8, split bool, progress func(message string, current uint32, total uint32)) (*manga.Chapter, error) {
|
||||||
return constant.WebP
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockConverter) ConvertChapter(chapter *manga.Chapter, quality uint8, progress func(string)) (*manga.Chapter, error) {
|
|
||||||
// Simulate conversion by setting the IsConverted flag
|
|
||||||
chapter.IsConverted = true
|
chapter.IsConverted = true
|
||||||
chapter.ConvertedTime = time.Now()
|
chapter.ConvertedTime = time.Now()
|
||||||
return chapter, nil
|
return chapter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockConverter) Format() constant.ConversionFormat {
|
||||||
|
return constant.WebP
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MockConverter) PrepareConverter() error {
|
func (m *MockConverter) PrepareConverter() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -79,6 +78,7 @@ func TestConvertCbzCommand(t *testing.T) {
|
|||||||
cmd.Flags().Uint8P("quality", "q", 85, "Quality for conversion (0-100)")
|
cmd.Flags().Uint8P("quality", "q", 85, "Quality for conversion (0-100)")
|
||||||
cmd.Flags().IntP("parallelism", "n", 2, "Number of chapters to convert in parallel")
|
cmd.Flags().IntP("parallelism", "n", 2, "Number of chapters to convert in parallel")
|
||||||
cmd.Flags().BoolP("override", "o", false, "Override the original CBZ files")
|
cmd.Flags().BoolP("override", "o", false, "Override the original CBZ files")
|
||||||
|
cmd.Flags().BoolP("split", "s", false, "Split long pages into smaller chunks")
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
err = ConvertCbzCommand(cmd, []string{tempDir})
|
err = ConvertCbzCommand(cmd, []string{tempDir})
|
||||||
|
Reference in New Issue
Block a user