✨ Add temp file
For trimming/fading
This commit is contained in:
parent
e0bc00d779
commit
a41880dad5
3 changed files with 46 additions and 11 deletions
|
|
@ -1,14 +1,18 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
p "path"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/files"
|
||||
"codeberg.org/danjones000/strip-beats/input/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
"fmt"
|
||||
p "path"
|
||||
"github.com/rkoesters/xdg/trash"
|
||||
)
|
||||
|
||||
var file *media.Probe
|
||||
var tmpfile *media.Probe
|
||||
|
||||
func PickNewFile() media.Probe {
|
||||
path := files.PickRandomFile()
|
||||
|
|
@ -21,19 +25,19 @@ func SetFile(path string) media.Probe {
|
|||
return f
|
||||
}
|
||||
|
||||
func SetTmpFile(path string) media.Probe {
|
||||
f := media.ProbeFile(path)
|
||||
tmpfile = &f
|
||||
return f
|
||||
}
|
||||
|
||||
func PickFileWithConf() media.Probe {
|
||||
var path string
|
||||
var msg string
|
||||
var base string
|
||||
var dir string
|
||||
good := false
|
||||
for !good {
|
||||
path = files.PickRandomFile()
|
||||
base = p.Base(path)
|
||||
dir = p.Dir(path)
|
||||
dir = p.Base(dir)
|
||||
|
||||
msg = fmt.Sprintf("We've selected %s%s%s\nIs that ok?", dir, "/", base)
|
||||
msg = fmt.Sprintf("We've selected %s\nIs that ok?", getShortPath(path))
|
||||
good = boolean.Choose(msg)
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +51,34 @@ func GetFile() media.Probe {
|
|||
return *file
|
||||
}
|
||||
|
||||
func ForgetFile() {
|
||||
file = nil
|
||||
func GetTmpFile() media.Probe {
|
||||
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
1
go.mod
|
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/creack/pty v1.1.18
|
||||
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
||||
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/u2takey/ffmpeg-go v0.5.0
|
||||
golang.org/x/term v0.11.0
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -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.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
||||
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/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue