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
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)
}