accept args as PARENT_OF_DIRS DURATION_INTERVAL_FOR_MOVEMENT
parent
9a09eb7c10
commit
42e858cc33
|
|
@ -32,6 +32,11 @@ func Run(ctx context.Context, args []string) error {
|
|||
return fmt.Errorf("failed to lsd %s: %w", args[0], err)
|
||||
}
|
||||
|
||||
movementInterval, err := time.ParseDuration(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cam := range cams {
|
||||
files, err := lsf(cam)
|
||||
if err != nil {
|
||||
|
|
@ -58,7 +63,7 @@ func Run(ctx context.Context, args []string) error {
|
|||
seriesFiles = append(seriesFiles, file)
|
||||
}
|
||||
}
|
||||
if seriesHasMovement, err := seriesHasMovement(ctx, seriesFiles); err != nil {
|
||||
if seriesHasMovement, err := seriesHasMovement(ctx, seriesFiles, movementInterval); err != nil {
|
||||
return err
|
||||
} else if seriesHasMovement {
|
||||
for _, seriesFile := range seriesFiles {
|
||||
|
|
@ -82,7 +87,7 @@ func Run(ctx context.Context, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func seriesHasMovement(ctx context.Context, files []string) (bool, error) {
|
||||
func seriesHasMovement(ctx context.Context, files []string, movementInterval time.Duration) (bool, error) {
|
||||
if len(files) < 1 {
|
||||
return false, nil
|
||||
}
|
||||
|
|
@ -101,7 +106,7 @@ func seriesHasMovement(ctx context.Context, files []string) (bool, error) {
|
|||
}
|
||||
gTime := gStat.ModTime()
|
||||
|
||||
if gTime.Sub(fTime) < time.Second {
|
||||
if gTime.Sub(fTime) < movementInterval {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func TestRun(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := Run(context.Background(), []string{path.Dir(d)}); err != nil {
|
||||
if err := Run(context.Background(), []string{path.Dir(d), "1s"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue