diff --git a/cmd/download.go b/cmd/download.go index 21a919a..6b03b0f 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -320,9 +320,7 @@ func downloadProcess( pageIndex := i + 1 - insideFilename := fmt.Sprintf("vol%s_ch%s_%d.%s", - chapter.Volume(), - strings.ReplaceAll(chapter.Number(), ".", "_"), + insideFilename := fmt.Sprintf("%d.%s", pageIndex, imgExt) if pageIndex < 10 { diff --git a/filekit/cbz.go b/filekit/cbz.go index 028e922..29c9340 100644 --- a/filekit/cbz.go +++ b/filekit/cbz.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "fmt" "io" "os" "path/filepath" @@ -14,8 +15,9 @@ import ( ) type cbzArchive struct { - buf *bytes.Buffer - writer *zip.Writer + buf *bytes.Buffer + writer *zip.Writer + pageCounter int } // fileName without extension @@ -25,8 +27,9 @@ func newCBZArchive() (*cbzArchive, error) { zipWriter := zip.NewWriter(buf) c := cbzArchive{ - buf: buf, - writer: zipWriter, + buf: buf, + writer: zipWriter, + pageCounter: 1, } return &c, nil @@ -80,6 +83,7 @@ func (c *cbzArchive) WriteOnDiskAndClose(outputDir, outputFileName string, } func (c *cbzArchive) AddFile(fileName string, src []byte) error { + fileName = fmt.Sprintf("%d_%s", c.pageCounter, fileName) buf := bytes.NewBuffer(src) w, err := c.writer.Create(fileName) if err != nil { @@ -88,5 +92,6 @@ func (c *cbzArchive) AddFile(fileName string, src []byte) error { if _, err := io.Copy(w, buf); err != nil { return err } + c.pageCounter++ return nil }