Skip to content

Commit

Permalink
always convert to .jpg file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Sep 8, 2019
1 parent ae0efd9 commit af3da97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ var colors = []string{

func logForJob(j *job) func(string) string {
return func(s string) string {
return j.color(fmt.Sprintf("%s %s : \n%s", time.Now().Format("15:04:05"), j.settings.source+j.fileName, s))
return j.color(fmt.Sprintf("%s %s :\n - %s", time.Now().Format("15:04:05"), j.settings.source+j.fileName, s))
}
}
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ func preventGrow(j *job) error {
return nil
}

j.logger.log(logForJob(j)(fmt.Sprintf("- grew form %dkb to %dkb", (originalInfo.Size() / 1024), (resultInfo.Size() / 1024))))
j.logger.log(logForJob(j)(fmt.Sprintf("grew form %dkb to %dkb", (originalInfo.Size() / 1024), (resultInfo.Size() / 1024))))

if !j.settings.dontGrow {
return nil
}

j.errored = true
j.logger.log(logForJob(j)("- deleting the oversized file"))
j.logger.log(logForJob(j)("deleting the oversized file"))

err = os.Remove(j.settings.output + j.fileName)
if err != nil {
Expand All @@ -244,7 +244,6 @@ func preventGrow(j *job) error {
}

func copy(j *job) error {

// must have errored
// not a killed
if !j.errored {
Expand Down Expand Up @@ -290,7 +289,7 @@ func copy(j *job) error {
return err
}

j.logger.log(logForJob(j)("- copied"))
j.logger.log(logForJob(j)("copied original"))

return nil
}
19 changes: 15 additions & 4 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"os/exec"
"path/filepath"
"strings"
)

type job struct {
Expand Down Expand Up @@ -38,15 +40,20 @@ func do(j *job) {
args = append(args, "--verbose")
}

outputFileName := j.fileName
outputFileName = strings.TrimSuffix(strings.TrimSuffix(outputFileName, filepath.Ext(outputFileName)), ".") + ".jpg"

args = append(args, j.settings.source+j.fileName)
args = append(args, j.settings.output+j.fileName)
args = append(args, j.settings.output+outputFileName)

j.fileName = outputFileName

cmd := exec.Command("guetzli", args...)

cmd.Stdout = &outb
cmd.Stderr = &errb

j.logger.log(logForJob(j)("- start"))
j.logger.log(logForJob(j)("start"))
err := cmd.Start()
if err != nil {
j.logger.log(errors.New(logForJob(j)(err.Error())))
Expand All @@ -68,7 +75,7 @@ func do(j *job) {
if err != nil {
j.logger.log(errors.New(logForJob(j)(err.Error())))
}
j.logger.log(logForJob(j)("- cancelled"))
j.logger.log(logForJob(j)("cancelled"))
j.done <- false
close(j.done)
break
Expand All @@ -79,7 +86,11 @@ func do(j *job) {
j.done <- false
close(j.done)
} else {
j.logger.log(logForJob(j)(outb.String()))
doneMsg := outb.String()
if doneMsg == "" {
doneMsg = "done"
}
j.logger.log(logForJob(j)(doneMsg))
j.done <- true
close(j.done)
}
Expand Down

0 comments on commit af3da97

Please sign in to comment.