mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-01-11 08:14:43 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72c6776793 | ||
|
|
e0b6d7fcef | ||
|
|
9305c8fa76 | ||
|
|
9cc45e75cf | ||
|
|
f451b660be | ||
|
|
c8fe726a96 |
@@ -36,7 +36,7 @@ builds:
|
||||
# trims path
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X meta.Version={{.Version}} -X meta.Commit={{.Commit}} -X meta.Date={{ .CommitDate }}
|
||||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
# config the checksum filename
|
||||
|
||||
@@ -15,7 +15,7 @@ RUN mkdir -p "${CONFIG_FOLDER}" && adduser \
|
||||
|
||||
COPY CBZOptimizer /usr/local/bin/CBZOptimizer
|
||||
|
||||
RUN apk add --no-cache inotify-tools && chmod +x /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
|
||||
|
||||
USER ${USER}
|
||||
ENTRYPOINT ["/usr/local/bin/CBZOptimizer"]
|
||||
@@ -49,7 +49,7 @@ func ConvertCbzCommand(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
quality, err := cmd.Flags().GetUint8("quality")
|
||||
if err != nil {
|
||||
if err != nil || quality <= 0 || quality > 100 {
|
||||
return fmt.Errorf("invalid quality value")
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ var rootCmd = &cobra.Command{
|
||||
Short: "Convert CBZ files using a specified converter",
|
||||
}
|
||||
|
||||
func SetVersionInfo(version, commit, date string) {
|
||||
rootCmd.Version = fmt.Sprintf("%s (Built on %s from Git SHA %s)", version, date, commit)
|
||||
}
|
||||
|
||||
func getPath() string {
|
||||
return filepath.Join(map[string]string{
|
||||
"windows": filepath.Join(os.Getenv("APPDATA")),
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/belphemur/CBZOptimizer/meta"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
command := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version of the application",
|
||||
Long: "Print the version of the application",
|
||||
Run: VersionCommand,
|
||||
}
|
||||
AddCommand(command)
|
||||
}
|
||||
|
||||
func VersionCommand(_ *cobra.Command, _ []string) {
|
||||
fmt.Printf("CBZOptimizer %s [%s] built [%s]\n", meta.Version, meta.Commit, meta.Date)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func WatchCommand(_ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
quality := uint8(viper.GetUint16("quality"))
|
||||
if quality <= 0 {
|
||||
if quality <= 0 || quality > 100 {
|
||||
return fmt.Errorf("invalid quality value")
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type Converter interface {
|
||||
// Format of the converter
|
||||
Format() (format constant.ConversionFormat)
|
||||
ConvertChapter(chapter *manga.Chapter, quality uint8, progress func(string)) (*manga.Chapter, error)
|
||||
ConvertChapter(chapter *manga.Chapter, quality uint8, progress func(message string, current uint32, total uint32)) (*manga.Chapter, error)
|
||||
PrepareConverter() error
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func (converter *Converter) PrepareConverter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (converter *Converter) ConvertChapter(chapter *packer2.Chapter, quality uint8, progress func(string)) (*packer2.Chapter, error) {
|
||||
func (converter *Converter) ConvertChapter(chapter *packer2.Chapter, quality uint8, progress func(message string, current uint32, total uint32)) (*packer2.Chapter, error) {
|
||||
err := converter.PrepareConverter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,7 +93,7 @@ func (converter *Converter) ConvertChapter(chapter *packer2.Chapter, quality uin
|
||||
}
|
||||
pagesMutex.Lock()
|
||||
pages = append(pages, convertedPage.Page)
|
||||
progress(fmt.Sprintf("Converted %d/%d pages to %s format", len(pages), totalPages, converter.Format()))
|
||||
progress(fmt.Sprintf("Converted %d/%d pages to %s format", len(pages), totalPages, converter.Format()), uint32(len(pages)), totalPages)
|
||||
pagesMutex.Unlock()
|
||||
<-guard
|
||||
}(page)
|
||||
|
||||
7
main.go
7
main.go
@@ -4,6 +4,13 @@ import (
|
||||
"github.com/belphemur/CBZOptimizer/cmd"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "none"
|
||||
date = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.SetVersionInfo(version, commit, date)
|
||||
cmd.Execute()
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@ func Optimize(chapterConverter converter.Converter, path string, quality uint8,
|
||||
}
|
||||
|
||||
// Convert the chapter
|
||||
convertedChapter, err := chapterConverter.ConvertChapter(chapter, quality, func(msg string) {
|
||||
log.Printf("[%s]%s", path, msg)
|
||||
convertedChapter, err := chapterConverter.ConvertChapter(chapter, quality, func(msg string, current uint32, total uint32) {
|
||||
if current%10 == 0 || current == total {
|
||||
log.Printf("[%s] Converting: %d/%d", chapter.FilePath, current, total)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to convert chapter: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user