debugging
This commit is contained in:
parent
507e114908
commit
a69e593d70
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func HandleFile(path string) (b *strings.Builder) {
|
func HandleFile(path string) (b *strings.Builder) {
|
||||||
b = &strings.Builder{}
|
b = &strings.Builder{}
|
||||||
b.WriteString(color.MagentaString("\nfile found: %s\n", path))
|
b.WriteString(color.MagentaString("%s file found: %s\n", time.Now().Format("2006-01-02 15:04:05"), path))
|
||||||
|
|
||||||
for _, parser := range parsers.Parsers {
|
for _, parser := range parsers.Parsers {
|
||||||
parsedFile, ok := parser.FileParser(&parser, path)
|
parsedFile, ok := parser.FileParser(&parser, path)
|
||||||
@ -57,8 +57,9 @@ func HandleParsedFile(b *strings.Builder, parsedFile *model.ParsedFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority {
|
if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority {
|
||||||
|
// TODO remove old file when overwriting existing episode (might have other file extension)
|
||||||
if err := OrganizeAnimeEpisode(b, parsedFile); err != nil {
|
if err := OrganizeAnimeEpisode(b, parsedFile); err != nil {
|
||||||
b.WriteString(color.RedString("\terror: %s", err.Error()))
|
b.WriteString(color.RedString("\terror: %s\n", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ func OrganizeAnimeEpisode(b *strings.Builder, parsedFile *model.ParsedFile) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(newFile); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ func OrganizeAnimeEpisode(b *strings.Builder, parsedFile *model.ParsedFile) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(outputFile, inputFile)
|
written, err := io.Copy(outputFile, inputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -109,11 +110,11 @@ func OrganizeAnimeEpisode(b *strings.Builder, parsedFile *model.ParsedFile) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Remove(lockFile); err != nil {
|
if err = os.Remove(lockFile); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.WriteString(color.BlueString("\t done (took %s)\n", time.Since(start)))
|
b.WriteString(color.BlueString("\t done (copying %s took %s)\n", FormatBytes(written), time.Since(start).Truncate(100*time.Millisecond)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
23
utils.go
Normal file
23
utils.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.milar.in/milarin/gmath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FormatBytes[T gmath.Integer](bytes T) string {
|
||||||
|
value := float64(bytes)
|
||||||
|
|
||||||
|
if value >= 1000000000000 {
|
||||||
|
return fmt.Sprintf("%.02fT", value/1000000000000)
|
||||||
|
} else if value >= 1000000000 {
|
||||||
|
return fmt.Sprintf("%.02fG", value/1000000000)
|
||||||
|
} else if value >= 1000000 {
|
||||||
|
return fmt.Sprintf("%.02fM", value/1000000)
|
||||||
|
} else if value >= 1000 {
|
||||||
|
return fmt.Sprintf("%.02fK", value/1000)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%.02fB", value)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user