mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-01-12 00:26:26 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5357ece2b7 | ||
|
|
dbef43d376 | ||
|
|
7c63ea49c0 | ||
|
|
8a067939af | ||
|
|
9e61ff4634 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
|||||||
- name: Analyse test results
|
- name: Analyse test results
|
||||||
run: go-junit-report < test-results.txt > report.xml
|
run: go-junit-report < test-results.txt > report.xml
|
||||||
- name: Upload test result artifact
|
- name: Upload test result artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
path: test-results.txt
|
path: test-results.txt
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ LABEL authors="Belphemur"
|
|||||||
ENV USER=abc
|
ENV USER=abc
|
||||||
ENV CONFIG_FOLDER=/config
|
ENV CONFIG_FOLDER=/config
|
||||||
ENV PUID=99
|
ENV PUID=99
|
||||||
RUN mkdir -p "${CONFIG_FOLDER}" && adduser \
|
RUN adduser \
|
||||||
--disabled-password \
|
--disabled-password \
|
||||||
--gecos "" \
|
--gecos "" \
|
||||||
--home "$(pwd)" \
|
--home "$(pwd)" \
|
||||||
--ingroup "users" \
|
--ingroup "users" \
|
||||||
--no-create-home \
|
|
||||||
--uid "${PUID}" \
|
--uid "${PUID}" \
|
||||||
|
--home "${CONFIG_FOLDER}" \
|
||||||
"${USER}" && \
|
"${USER}" && \
|
||||||
chown ${PUID}:${GUID} "${CONFIG_FOLDER}"
|
chown ${PUID}:${GUID} "${CONFIG_FOLDER}"
|
||||||
|
|
||||||
@@ -17,5 +17,6 @@ COPY CBZOptimizer /usr/local/bin/CBZOptimizer
|
|||||||
|
|
||||||
RUN apk add --no-cache inotify-tools bash-completion && chmod +x /usr/local/bin/CBZOptimizer && /usr/local/bin/CBZOptimizer completion bash > /etc/bash_completion.d/CBZOptimizer
|
RUN apk add --no-cache inotify-tools bash-completion && chmod +x /usr/local/bin/CBZOptimizer && /usr/local/bin/CBZOptimizer completion bash > /etc/bash_completion.d/CBZOptimizer
|
||||||
|
|
||||||
|
VOLUME ${CONFIG_FOLDER}
|
||||||
USER ${USER}
|
USER ${USER}
|
||||||
ENTRYPOINT ["/usr/local/bin/CBZOptimizer"]
|
ENTRYPOINT ["/usr/local/bin/CBZOptimizer"]
|
||||||
@@ -18,7 +18,6 @@ func WriteChapterToCBZ(chapter *manga.Chapter, outputFilePath string) error {
|
|||||||
|
|
||||||
// Create a new ZIP writer
|
// Create a new ZIP writer
|
||||||
zipWriter := zip.NewWriter(zipFile)
|
zipWriter := zip.NewWriter(zipFile)
|
||||||
err = zipWriter.SetComment("Created by CBZOptimizer")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -71,18 +70,11 @@ func WriteChapterToCBZ(chapter *manga.Chapter, outputFilePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if chapter.IsConverted {
|
if chapter.IsConverted {
|
||||||
convertedWriter, err := zipWriter.CreateHeader(&zip.FileHeader{
|
|
||||||
Name: "Converted.txt",
|
|
||||||
Method: zip.Deflate,
|
|
||||||
Modified: time.Now(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create Converted.txt in .cbz: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = convertedWriter.Write([]byte(fmt.Sprintf("%s\nThis chapter has been converted by CBZOptimizer.", chapter.ConvertedTime)))
|
convertedString := fmt.Sprintf("%s\nThis chapter has been converted by CBZOptimizer.", chapter.ConvertedTime)
|
||||||
|
err = zipWriter.SetComment(convertedString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write Converted.txt contents: %w", err)
|
return fmt.Errorf("failed to write comment: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cbz
|
|||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/belphemur/CBZOptimizer/manga"
|
"github.com/belphemur/CBZOptimizer/manga"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -10,11 +11,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteChapterToCBZ(t *testing.T) {
|
func TestWriteChapterToCBZ(t *testing.T) {
|
||||||
|
currentTime := time.Now()
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
chapter *manga.Chapter
|
chapter *manga.Chapter
|
||||||
expectedFiles []string
|
expectedFiles []string
|
||||||
|
expectedComment string
|
||||||
}{
|
}{
|
||||||
//test case where there is only one page and ComicInfo and the chapter is converted
|
//test case where there is only one page and ComicInfo and the chapter is converted
|
||||||
{
|
{
|
||||||
@@ -29,9 +33,10 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ComicInfoXml: "<Series>Boundless Necromancer</Series>",
|
ComicInfoXml: "<Series>Boundless Necromancer</Series>",
|
||||||
IsConverted: true,
|
IsConverted: true,
|
||||||
ConvertedTime: time.Now(),
|
ConvertedTime: currentTime,
|
||||||
},
|
},
|
||||||
expectedFiles: []string{"0000.jpg", "ComicInfo.xml", "Converted.txt"},
|
expectedFiles: []string{"0000.jpg", "ComicInfo.xml"},
|
||||||
|
expectedComment: fmt.Sprintf("%s\nThis chapter has been converted by CBZOptimizer.", currentTime),
|
||||||
},
|
},
|
||||||
//test case where there is only one page and no
|
//test case where there is only one page and no
|
||||||
{
|
{
|
||||||
@@ -125,6 +130,10 @@ func TestWriteChapterToCBZ(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tc.expectedComment != "" && r.Comment != tc.expectedComment {
|
||||||
|
t.Errorf("Expected comment %s, but found %s", tc.expectedComment, r.Comment)
|
||||||
|
}
|
||||||
|
|
||||||
// Check if there are no unexpected files
|
// Check if there are no unexpected files
|
||||||
if len(filesInArchive) != len(tc.expectedFiles) {
|
if len(filesInArchive) != len(tc.expectedFiles) {
|
||||||
t.Errorf("Expected %d files, but found %d", len(tc.expectedFiles), len(filesInArchive))
|
t.Errorf("Expected %d files, but found %d", len(tc.expectedFiles), len(filesInArchive))
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ func LoadChapter(filePath string) (*manga.Chapter, error) {
|
|||||||
chapter := &manga.Chapter{
|
chapter := &manga.Chapter{
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
}
|
}
|
||||||
|
// Check for comment
|
||||||
|
if r.Comment != "" {
|
||||||
|
scanner := bufio.NewScanner(strings.NewReader(r.Comment))
|
||||||
|
if scanner.Scan() {
|
||||||
|
convertedTime := scanner.Text()
|
||||||
|
chapter.ConvertedTime, err = dateparse.ParseAny(convertedTime)
|
||||||
|
if err == nil {
|
||||||
|
chapter.IsConverted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
if f.FileInfo().IsDir() {
|
if f.FileInfo().IsDir() {
|
||||||
@@ -45,7 +56,7 @@ func LoadChapter(filePath string) (*manga.Chapter, error) {
|
|||||||
return nil, fmt.Errorf("failed to read ComicInfo.xml content: %w", err)
|
return nil, fmt.Errorf("failed to read ComicInfo.xml content: %w", err)
|
||||||
}
|
}
|
||||||
chapter.ComicInfoXml = string(xmlContent)
|
chapter.ComicInfoXml = string(xmlContent)
|
||||||
} else if ext == ".txt" && strings.ToLower(filepath.Base(f.Name)) == "converted.txt" {
|
} else if !chapter.IsConverted && ext == ".txt" && strings.ToLower(filepath.Base(f.Name)) == "converted.txt" {
|
||||||
textContent, err := io.ReadAll(rc)
|
textContent, err := io.ReadAll(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rc.Close()
|
rc.Close()
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func WatchCommand(_ *cobra.Command, args []string) error {
|
|||||||
case inotifywaitgo.CLOSE_WRITE, inotifywaitgo.MOVE:
|
case inotifywaitgo.CLOSE_WRITE, inotifywaitgo.MOVE:
|
||||||
err := utils.Optimize(&utils.OptimizeOptions{
|
err := utils.Optimize(&utils.OptimizeOptions{
|
||||||
ChapterConverter: chapterConverter,
|
ChapterConverter: chapterConverter,
|
||||||
Path: path,
|
Path: event.Filename,
|
||||||
Quality: quality,
|
Quality: quality,
|
||||||
Override: override,
|
Override: override,
|
||||||
Split: split,
|
Split: split,
|
||||||
|
|||||||
Reference in New Issue
Block a user