feat: initial GUI prototype
This commit is contained in:
commit
ec7fd07ee8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
videotools.log
|
||||
30
README.md
Normal file
30
README.md
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# VideoTools Prototype
|
||||
|
||||
## Requirements
|
||||
- Go 1.21+
|
||||
- Fyne 2.x (pulled automatically via `go mod tidy`)
|
||||
- FFmpeg (not yet invoked, but required for future transcoding)
|
||||
|
||||
## Running
|
||||
Launch the GUI:
|
||||
```bash
|
||||
go run .
|
||||
```
|
||||
|
||||
Run a module via CLI:
|
||||
```bash
|
||||
go run . convert input.avi output.mp4
|
||||
go run . combine file1.mov file2.wav / final.mp4
|
||||
go run . logs
|
||||
```
|
||||
|
||||
Add `-debug` or `VIDEOTOOLS_DEBUG=1` for verbose stderr logs.
|
||||
|
||||
## Logs
|
||||
- All actions log to `videotools.log` (override with `VIDEOTOOLS_LOG_FILE=/path/to/log`).
|
||||
- CLI command `videotools logs` (or `go run . logs`) prints the last 200 lines.
|
||||
- Each entry is tagged (e.g. `[UI]`, `[CLI]`, `[FFMPEG]`) so issues are easy to trace.
|
||||
|
||||
## Notes
|
||||
- GUI requires a running display server (X11/Wayland). In headless shells it will log `[UI] DISPLAY environment variable is empty`.
|
||||
- Module handlers are placeholders; hook them to actual FFmpeg calls next.
|
||||
40
go.mod
Normal file
40
go.mod
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
module github.com/user/videotools
|
||||
|
||||
go 1.25.1
|
||||
|
||||
require fyne.io/fyne/v2 v2.7.1
|
||||
|
||||
require (
|
||||
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58 // indirect
|
||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fredbi/uri v1.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/fyne-io/gl-js v0.2.0 // indirect
|
||||
github.com/fyne-io/glfw-js v0.3.0 // indirect
|
||||
github.com/fyne-io/image v0.1.1 // indirect
|
||||
github.com/fyne-io/oksvg v0.2.0 // indirect
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
|
||||
github.com/go-text/render v0.2.0 // indirect
|
||||
github.com/go-text/typesetting v0.2.1 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
|
||||
github.com/hack-pad/safejs v0.1.0 // indirect
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade // indirect
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rymdport/portal v0.4.2 // indirect
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
|
||||
github.com/stretchr/testify v1.11.1 // indirect
|
||||
github.com/yuin/goldmark v1.7.8 // indirect
|
||||
golang.org/x/image v0.24.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
80
go.sum
Normal file
80
go.sum
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
fyne.io/fyne/v2 v2.7.1 h1:ja7rNHWWEooha4XBIZNnPP8tVFwmTfwMJdpZmLxm2Zc=
|
||||
fyne.io/fyne/v2 v2.7.1/go.mod h1:xClVlrhxl7D+LT+BWYmcrW4Nf+dJTvkhnPgji7spAwE=
|
||||
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58 h1:eA5/u2XRd8OUkoMqEv3IBlFYSruNlXD8bRHDiqm0VNI=
|
||||
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
|
||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
|
||||
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
|
||||
github.com/fredbi/uri v1.1.1 h1:xZHJC08GZNIUhbP5ImTHnt5Ya0T8FI2VAwI/37kh2Ko=
|
||||
github.com/fredbi/uri v1.1.1/go.mod h1:4+DZQ5zBjEwQCDmXW5JdIjz0PUA+yJbvtBv+u+adr5o=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/fyne-io/gl-js v0.2.0 h1:+EXMLVEa18EfkXBVKhifYB6OGs3HwKO3lUElA0LlAjs=
|
||||
github.com/fyne-io/gl-js v0.2.0/go.mod h1:ZcepK8vmOYLu96JoxbCKJy2ybr+g1pTnaBDdl7c3ajI=
|
||||
github.com/fyne-io/glfw-js v0.3.0 h1:d8k2+Y7l+zy2pc7wlGRyPfTgZoqDf3AI4G+2zOWhWUk=
|
||||
github.com/fyne-io/glfw-js v0.3.0/go.mod h1:Ri6te7rdZtBgBpxLW19uBpp3Dl6K9K/bRaYdJ22G8Jk=
|
||||
github.com/fyne-io/image v0.1.1 h1:WH0z4H7qfvNUw5l4p3bC1q70sa5+YWVt6HCj7y4VNyA=
|
||||
github.com/fyne-io/image v0.1.1/go.mod h1:xrfYBh6yspc+KjkgdZU/ifUC9sPA5Iv7WYUBzQKK7JM=
|
||||
github.com/fyne-io/oksvg v0.2.0 h1:mxcGU2dx6nwjJsSA9PCYZDuoAcsZ/OuJlvg/Q9Njfo8=
|
||||
github.com/fyne-io/oksvg v0.2.0/go.mod h1:dJ9oEkPiWhnTFNCmRgEze+YNprJF7YRbpjgpWS4kzoI=
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA=
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc=
|
||||
github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU=
|
||||
github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8=
|
||||
github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 h1:DTqeJJYc1usa45Q5r52t01KhvlSN02+Oq+tQbSBI91A=
|
||||
github.com/hack-pad/go-indexeddb v0.3.2/go.mod h1:QvfTevpDVlkfomY498LhstjwbPW6QC4VC/lxYb0Kom0=
|
||||
github.com/hack-pad/safejs v0.1.0 h1:qPS6vjreAqh2amUqj4WNG1zIw7qlRQJ9K10eDKMCnE8=
|
||||
github.com/hack-pad/safejs v0.1.0/go.mod h1:HdS+bKF1NrE72VoXZeWzxFOVQVUSqZJAG0xNCnb+Tio=
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade h1:FmusiCI1wHw+XQbvL9M+1r/C3SPqKrmBaIOYwVfQoDE=
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade/go.mod h1:ZDXo8KHryOWSIqnsb/CiDq7hQUYryCgdVnxbj8tDG7o=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1 h1:IxtPxYsR9Gp60cGXjfuR/llTqV8aYMsC472zD0D1vHk=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1/go.mod h1:DrhgsSDZxoAfvVrBVLXoxZn/pN5TXqaDbq7ju94viiQ=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA=
|
||||
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rymdport/portal v0.4.2 h1:7jKRSemwlTyVHHrTGgQg7gmNPJs88xkbKcIL3NlcmSU=
|
||||
github.com/rymdport/portal v0.4.2/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=
|
||||
golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
396
main.go
Normal file
396
main.go
Normal file
|
|
@ -0,0 +1,396 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
)
|
||||
|
||||
// Module describes a high level tool surface that gets a tile on the menu.
|
||||
type Module struct {
|
||||
ID string
|
||||
Label string
|
||||
Color color.Color
|
||||
Handle func(files []string)
|
||||
}
|
||||
|
||||
var (
|
||||
debugFlag = flag.Bool("debug", false, "enable verbose logging (env: VIDEOTOOLS_DEBUG=1)")
|
||||
|
||||
backgroundColor = mustHex("#0B0F1A")
|
||||
gridColor = mustHex("#171C2A")
|
||||
textColor = mustHex("#E1EEFF")
|
||||
queueColor = mustHex("#5961FF")
|
||||
|
||||
modules = []Module{
|
||||
{"convert", "Convert", mustHex("#5E2AE2"), handleConvert},
|
||||
{"merge", "Merge", mustHex("#3852F3"), handleMerge},
|
||||
{"trim", "Trim", mustHex("#1B87F4"), handleTrim},
|
||||
{"filters", "Filters", mustHex("#1FC4D0"), handleFilters},
|
||||
{"upscale", "Upscale", mustHex("#3FD777"), handleUpscale},
|
||||
{"audio", "Audio", mustHex("#9CE33D"), handleAudio},
|
||||
{"thumb", "Thumb", mustHex("#F0C33E"), handleThumb},
|
||||
{"inspect", "Inspect", mustHex("#F69A3F"), handleInspect},
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
logFilePath string
|
||||
logFile *os.File
|
||||
logHistory []string
|
||||
debugEnabled bool
|
||||
debugLogger = log.New(os.Stderr, "[videotools] ", log.LstdFlags|log.Lmicroseconds)
|
||||
)
|
||||
|
||||
const logHistoryMax = 500
|
||||
|
||||
type logCategory string
|
||||
|
||||
const (
|
||||
logCatUI logCategory = "[UI]"
|
||||
logCatCLI logCategory = "[CLI]"
|
||||
logCatFFMPEG logCategory = "[FFMPEG]"
|
||||
logCatSystem logCategory = "[SYS]"
|
||||
logCatModule logCategory = "[MODULE]"
|
||||
)
|
||||
|
||||
func main() {
|
||||
initLogging()
|
||||
defer closeLogs()
|
||||
|
||||
flag.Parse()
|
||||
setDebug(*debugFlag || os.Getenv("VIDEOTOOLS_DEBUG") != "")
|
||||
debugLog(logCatSystem, "starting VideoTools prototype at %s", time.Now().Format(time.RFC3339))
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) > 0 {
|
||||
if err := runCLI(args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "videotools:", err)
|
||||
fmt.Fprintln(os.Stderr)
|
||||
printUsage()
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if display := os.Getenv("DISPLAY"); display == "" {
|
||||
debugLog(logCatUI, "DISPLAY environment variable is empty; GUI may not be visible in headless mode")
|
||||
} else {
|
||||
debugLog(logCatUI, "DISPLAY=%s", display)
|
||||
}
|
||||
runGUI()
|
||||
}
|
||||
|
||||
func runGUI() {
|
||||
a := app.New()
|
||||
debugLog(logCatUI, "created fyne app: %#v", a)
|
||||
w := a.NewWindow("VideoTools")
|
||||
w.Resize(fyne.NewSize(920, 540))
|
||||
debugLog(logCatUI, "window initialized (size 920x540)")
|
||||
|
||||
menu := buildMainMenu()
|
||||
bg := canvas.NewRectangle(backgroundColor)
|
||||
bg.SetMinSize(fyne.NewSize(920, 540))
|
||||
w.SetContent(container.NewMax(bg, menu))
|
||||
debugLog(logCatUI, "main menu rendered with %d modules", len(modules))
|
||||
|
||||
w.ShowAndRun()
|
||||
}
|
||||
|
||||
func runCLI(args []string) error {
|
||||
cmd := strings.ToLower(args[0])
|
||||
cmdArgs := args[1:]
|
||||
debugLog(logCatCLI, "command=%s args=%v", cmd, cmdArgs)
|
||||
|
||||
switch cmd {
|
||||
case "convert":
|
||||
return runConvertCLI(cmdArgs)
|
||||
case "combine", "merge":
|
||||
return runCombineCLI(cmdArgs)
|
||||
case "trim":
|
||||
handleTrim(cmdArgs)
|
||||
case "filters":
|
||||
handleFilters(cmdArgs)
|
||||
case "upscale":
|
||||
handleUpscale(cmdArgs)
|
||||
case "audio":
|
||||
handleAudio(cmdArgs)
|
||||
case "thumb":
|
||||
handleThumb(cmdArgs)
|
||||
case "inspect":
|
||||
handleInspect(cmdArgs)
|
||||
case "logs":
|
||||
return runLogsCLI()
|
||||
case "help":
|
||||
printUsage()
|
||||
default:
|
||||
return fmt.Errorf("unknown command %q", cmd)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runConvertCLI(args []string) error {
|
||||
if len(args) < 2 {
|
||||
return fmt.Errorf("convert requires input and output files (e.g. videotools convert input.avi output.mp4)")
|
||||
}
|
||||
in, out := args[0], args[1]
|
||||
debugLog(logCatFFMPEG, "convert input=%s output=%s", in, out)
|
||||
handleConvert([]string{in, out})
|
||||
return nil
|
||||
}
|
||||
|
||||
func runCombineCLI(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("combine requires input files and an output (e.g. videotools combine clip1.mov clip2.wav / final.mp4)")
|
||||
}
|
||||
inputs, outputs, err := splitIOArgs(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(inputs) == 0 || len(outputs) == 0 {
|
||||
return fmt.Errorf("combine expects one or more inputs, '/', then an output file")
|
||||
}
|
||||
debugLog(logCatFFMPEG, "combine inputs=%v output=%v", inputs, outputs)
|
||||
// For now feed inputs followed by outputs to the merge handler.
|
||||
handleMerge(append(inputs, outputs...))
|
||||
return nil
|
||||
}
|
||||
|
||||
func splitIOArgs(args []string) (inputs []string, outputs []string, err error) {
|
||||
sep := -1
|
||||
for i, a := range args {
|
||||
if a == "/" {
|
||||
sep = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if sep == -1 {
|
||||
return nil, nil, fmt.Errorf("missing '/' separator between inputs and outputs")
|
||||
}
|
||||
inputs = append(inputs, args[:sep]...)
|
||||
outputs = append(outputs, args[sep+1:]...)
|
||||
return inputs, outputs, nil
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Println("Usage:")
|
||||
fmt.Println(" videotools convert <input> <output>")
|
||||
fmt.Println(" videotools combine <in1> <in2> ... / <output>")
|
||||
fmt.Println(" videotools trim <args>")
|
||||
fmt.Println(" videotools filters <args>")
|
||||
fmt.Println(" videotools upscale <args>")
|
||||
fmt.Println(" videotools audio <args>")
|
||||
fmt.Println(" videotools thumb <args>")
|
||||
fmt.Println(" videotools inspect <args>")
|
||||
fmt.Println(" videotools logs # tail recent log lines")
|
||||
fmt.Println(" videotools # launch GUI")
|
||||
fmt.Println()
|
||||
fmt.Println("Set VIDEOTOOLS_DEBUG=1 or pass -debug for verbose logs.")
|
||||
fmt.Println("Logs are written to", logFilePath, "or set VIDEOTOOLS_LOG_FILE to override.")
|
||||
}
|
||||
|
||||
func runLogsCLI() error {
|
||||
path := logFilePath
|
||||
if path == "" {
|
||||
return fmt.Errorf("log file unavailable")
|
||||
}
|
||||
debugLog(logCatCLI, "reading logs from %s", path)
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
const maxLines = 200
|
||||
var lines []string
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(lines) > maxLines {
|
||||
lines = lines[len(lines)-maxLines:]
|
||||
}
|
||||
fmt.Printf("--- showing last %d log lines from %s ---\n", len(lines), path)
|
||||
for _, line := range lines {
|
||||
fmt.Println(line)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildMainMenu() fyne.CanvasObject {
|
||||
title := canvas.NewText("VIDEOTOOLS", mustHex("#4CE870"))
|
||||
title.TextStyle = fyne.TextStyle{Monospace: true, Bold: true}
|
||||
title.TextSize = 28
|
||||
|
||||
queueTile := buildQueueTile(0, 0)
|
||||
|
||||
header := container.New(layout.NewHBoxLayout(),
|
||||
title,
|
||||
layout.NewSpacer(),
|
||||
queueTile,
|
||||
)
|
||||
|
||||
var tileObjects []fyne.CanvasObject
|
||||
for _, mod := range modules {
|
||||
tileObjects = append(tileObjects, buildModuleTile(mod))
|
||||
}
|
||||
|
||||
grid := container.NewGridWithColumns(3, tileObjects...)
|
||||
|
||||
padding := canvas.NewRectangle(color.Transparent)
|
||||
padding.SetMinSize(fyne.NewSize(0, 14))
|
||||
|
||||
body := container.New(layout.NewVBoxLayout(),
|
||||
header,
|
||||
padding,
|
||||
grid,
|
||||
)
|
||||
|
||||
return container.NewPadded(body)
|
||||
}
|
||||
|
||||
func buildModuleTile(mod Module) fyne.CanvasObject {
|
||||
debugLog(logCatUI, "building tile %s color=%v", mod.ID, mod.Color)
|
||||
rect := canvas.NewRectangle(mod.Color)
|
||||
rect.CornerRadius = 8
|
||||
rect.StrokeColor = gridColor
|
||||
rect.StrokeWidth = 1
|
||||
rect.SetMinSize(fyne.NewSize(220, 110))
|
||||
|
||||
label := canvas.NewText(strings.ToUpper(mod.Label), textColor)
|
||||
label.Alignment = fyne.TextAlignCenter
|
||||
label.TextStyle = fyne.TextStyle{Monospace: true, Bold: true}
|
||||
label.TextSize = 20
|
||||
|
||||
tile := container.NewMax(rect, container.NewCenter(label))
|
||||
return container.NewPadded(tile)
|
||||
}
|
||||
|
||||
func buildQueueTile(done, total int) fyne.CanvasObject {
|
||||
rect := canvas.NewRectangle(queueColor)
|
||||
rect.CornerRadius = 8
|
||||
rect.SetMinSize(fyne.NewSize(160, 60))
|
||||
|
||||
text := canvas.NewText(fmt.Sprintf("QUEUE: %d/%d", done, total), textColor)
|
||||
text.Alignment = fyne.TextAlignCenter
|
||||
text.TextStyle = fyne.TextStyle{Monospace: true, Bold: true}
|
||||
text.TextSize = 18
|
||||
|
||||
return container.NewMax(rect, container.NewCenter(text))
|
||||
}
|
||||
|
||||
func mustHex(h string) color.NRGBA {
|
||||
c, err := parseHexColor(h)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "invalid color %q: %v\n", h, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func parseHexColor(s string) (color.NRGBA, error) {
|
||||
s = strings.TrimPrefix(s, "#")
|
||||
if len(s) != 6 {
|
||||
return color.NRGBA{}, fmt.Errorf("want 6 digits, got %q", s)
|
||||
}
|
||||
var r, g, b uint8
|
||||
if _, err := fmt.Sscanf(s, "%02x%02x%02x", &r, &g, &b); err != nil {
|
||||
return color.NRGBA{}, err
|
||||
}
|
||||
return color.NRGBA{R: r, G: g, B: b, A: 0xff}, nil
|
||||
}
|
||||
|
||||
// Placeholder handlers keep the prototype compiling while we wire modules.
|
||||
func handleConvert(files []string) {
|
||||
debugLog(logCatFFMPEG, "convert handler invoked with %v", files)
|
||||
fmt.Println("convert", files)
|
||||
}
|
||||
|
||||
func handleMerge(files []string) {
|
||||
debugLog(logCatFFMPEG, "merge handler invoked with %v", files)
|
||||
fmt.Println("merge", files)
|
||||
}
|
||||
|
||||
func handleTrim(files []string) {
|
||||
debugLog(logCatModule, "trim handler invoked with %v", files)
|
||||
fmt.Println("trim", files)
|
||||
}
|
||||
|
||||
func handleFilters(files []string) {
|
||||
debugLog(logCatModule, "filters handler invoked with %v", files)
|
||||
fmt.Println("filters", files)
|
||||
}
|
||||
|
||||
func handleUpscale(files []string) {
|
||||
debugLog(logCatModule, "upscale handler invoked with %v", files)
|
||||
fmt.Println("upscale", files)
|
||||
}
|
||||
|
||||
func handleAudio(files []string) {
|
||||
debugLog(logCatModule, "audio handler invoked with %v", files)
|
||||
fmt.Println("audio", files)
|
||||
}
|
||||
|
||||
func handleThumb(files []string) {
|
||||
debugLog(logCatModule, "thumb handler invoked with %v", files)
|
||||
fmt.Println("thumb", files)
|
||||
}
|
||||
|
||||
func handleInspect(files []string) {
|
||||
debugLog(logCatModule, "inspect handler invoked with %v", files)
|
||||
fmt.Println("inspect", files)
|
||||
}
|
||||
|
||||
func initLogging() {
|
||||
logFilePath = os.Getenv("VIDEOTOOLS_LOG_FILE")
|
||||
if logFilePath == "" {
|
||||
logFilePath = "videotools.log"
|
||||
}
|
||||
f, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "videotools: cannot open log file %s: %v\n", logFilePath, err)
|
||||
return
|
||||
}
|
||||
logFile = f
|
||||
}
|
||||
|
||||
func closeLogs() {
|
||||
if logFile != nil {
|
||||
logFile.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func setDebug(on bool) {
|
||||
debugEnabled = on
|
||||
debugLog(logCatSystem, "debug logging toggled -> %v (VIDEOTOOLS_DEBUG=%s)", on, os.Getenv("VIDEOTOOLS_DEBUG"))
|
||||
}
|
||||
|
||||
func debugLog(cat logCategory, format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf("%s %s", cat, fmt.Sprintf(format, args...))
|
||||
timestamp := time.Now().Format(time.RFC3339Nano)
|
||||
if logFile != nil {
|
||||
fmt.Fprintf(logFile, "%s %s\n", timestamp, msg)
|
||||
}
|
||||
logHistory = append(logHistory, fmt.Sprintf("%s %s", timestamp, msg))
|
||||
if len(logHistory) > logHistoryMax {
|
||||
logHistory = logHistory[len(logHistory)-logHistoryMax:]
|
||||
}
|
||||
if debugEnabled {
|
||||
debugLogger.Printf("%s %s", timestamp, msg)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user