Add temp file

For trimming/fading
This commit is contained in:
Dan Jones 2023-09-05 22:09:55 -05:00
commit a41880dad5
3 changed files with 46 additions and 11 deletions

View file

@ -1,14 +1,18 @@
package app package app
import ( import (
"fmt"
"os"
p "path"
"codeberg.org/danjones000/strip-beats/files" "codeberg.org/danjones000/strip-beats/files"
"codeberg.org/danjones000/strip-beats/input/boolean" "codeberg.org/danjones000/strip-beats/input/boolean"
"codeberg.org/danjones000/strip-beats/media" "codeberg.org/danjones000/strip-beats/media"
"fmt" "github.com/rkoesters/xdg/trash"
p "path"
) )
var file *media.Probe var file *media.Probe
var tmpfile *media.Probe
func PickNewFile() media.Probe { func PickNewFile() media.Probe {
path := files.PickRandomFile() path := files.PickRandomFile()
@ -21,19 +25,19 @@ func SetFile(path string) media.Probe {
return f return f
} }
func SetTmpFile(path string) media.Probe {
f := media.ProbeFile(path)
tmpfile = &f
return f
}
func PickFileWithConf() media.Probe { func PickFileWithConf() media.Probe {
var path string var path string
var msg string var msg string
var base string
var dir string
good := false good := false
for !good { for !good {
path = files.PickRandomFile() path = files.PickRandomFile()
base = p.Base(path) msg = fmt.Sprintf("We've selected %s\nIs that ok?", getShortPath(path))
dir = p.Dir(path)
dir = p.Base(dir)
msg = fmt.Sprintf("We've selected %s%s%s\nIs that ok?", dir, "/", base)
good = boolean.Choose(msg) good = boolean.Choose(msg)
} }
@ -47,6 +51,34 @@ func GetFile() media.Probe {
return *file return *file
} }
func ForgetFile() { func GetTmpFile() media.Probe {
file = nil if tmpfile == nil {
return GetFile()
}
return *tmpfile
}
func BailOut() {
if tmpfile != nil {
os.Remove(tmpfile.Format.Path)
}
file = nil
tmpfile = nil
}
func Finish() {
if file != nil {
err := trash.Trash(file.Format.Path)
if err != nil {
panic(err)
}
}
BailOut()
}
func getShortPath(path string) string {
base := p.Base(path)
dir := p.Dir(path)
dir = p.Base(dir)
return fmt.Sprintf("%s/%s", dir, base)
} }

1
go.mod
View file

@ -9,6 +9,7 @@ require (
github.com/creack/pty v1.1.18 github.com/creack/pty v1.1.18
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c
github.com/rkoesters/xdg v0.0.1
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
github.com/u2takey/ffmpeg-go v0.5.0 github.com/u2takey/ffmpeg-go v0.5.0
golang.org/x/term v0.11.0 golang.org/x/term v0.11.0

2
go.sum
View file

@ -52,6 +52,8 @@ github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c/go.mod h1:nVwGv4MP47T0j
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rkoesters/xdg v0.0.1 h1:RmfYxghVvIsb4d51u5LtNOcwqY5r3P44u6o86qqvBMA=
github.com/rkoesters/xdg v0.0.1/go.mod h1:5DcbjvJkY00fIOKkaBnylbC/rmc1NNJP5dmUcnlcm7U=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=