This commit is contained in:
milarin 2023-01-15 14:08:45 +01:00
parent fdf31e22e4
commit a4f5b7887b
2 changed files with 59 additions and 39 deletions

View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"fmt" "errors"
"io"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -67,56 +69,52 @@ func OrganizeAnimeEpisode(b *strings.Builder, parsedFile *model.ParsedFile) erro
oldFile := filepath.Join(DownloadPath, parsedFile.File) oldFile := filepath.Join(DownloadPath, parsedFile.File)
newFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), filepath.Ext(parsedFile.File)) newFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), filepath.Ext(parsedFile.File))
//lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock") lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock")
b.WriteString(color.BlueString("\tmove file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile)) b.WriteString(color.BlueString("\tmove file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile))
// if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil { if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil {
// return err return err
// } }
// if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil { if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil {
// return err return err
// } }
// if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) { if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) {
// return err return err
// } }
// inputFile, err := os.Open(oldFile) inputFile, err := os.Open(oldFile)
// if err != nil { if err != nil {
// return err return err
// } }
// defer inputFile.Close() defer inputFile.Close()
// outputFile, err := os.Create(newFile) outputFile, err := os.Create(newFile)
// if err != nil { if err != nil {
// return err return err
// } }
// defer outputFile.Close() defer outputFile.Close()
// if err := os.Chown(newFile, Uid, Gid); err != nil { if err := os.Chown(newFile, Uid, Gid); err != nil {
// 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
// } }
// if err = os.Remove(oldFile); err != nil { if err = os.Remove(oldFile); err != nil {
// return err return err
// } }
// if err = os.Remove(lockFile); err != nil { if err = os.Remove(lockFile); err != nil {
// return err return err
// } }
time.Sleep(1 * time.Second) b.WriteString(color.BlueString("\t done (copying %s took %s)\n", FormatBytes(written), time.Since(start).Truncate(100*time.Millisecond)))
n, err := b.WriteString(color.BlueString("\t done (took %s)\n", time.Since(start).Truncate(100*time.Millisecond)))
fmt.Println("ASD", n, err)
return nil return nil
} }

22
utils.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"git.milar.in/milarin/gmath"
)
func FormatBytes[T gmath.Integer](bytes T) string {
value := float64(bytes)
if value/1000000000000 >= 1000000000000 {
return fmt.Sprint("%.02fT", value/1000000000000)
} else if value/1000000000 >= 1000000000 {
return fmt.Sprint("%.02fG", value/1000000000)
} else if value/1000000 >= 1000000 {
return fmt.Sprint("%.02fM", value/1000000)
} else if value/1000 >= 1000 {
return fmt.Sprint("%.02fK", value/1000)
} else {
return fmt.Sprint("%.02fB", value)
}
}