From ec7649aee83893fbddda82dc98e9dd2552e22965 Mon Sep 17 00:00:00 2001 From: Stu Leak Date: Tue, 23 Dec 2025 21:06:49 -0500 Subject: [PATCH] Default author output path without dialogs --- author_module.go | 99 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/author_module.go b/author_module.go index b72bc00..fa0cecb 100644 --- a/author_module.go +++ b/author_module.go @@ -620,6 +620,9 @@ func authorSummary(state *appState) string { summary += fmt.Sprintf("Disc Size: %s\n", state.authorDiscSize) summary += fmt.Sprintf("Region: %s\n", state.authorRegion) summary += fmt.Sprintf("Aspect Ratio: %s\n", state.authorAspectRatio) + if outPath := authorDefaultOutputPath(state.authorOutputType, state.authorTitle, authorSummaryPaths(state)); outPath != "" { + summary += fmt.Sprintf("Output Path: %s\n", outPath) + } if state.authorTitle != "" { summary += fmt.Sprintf("DVD Title: %s\n", state.authorTitle) } @@ -696,6 +699,20 @@ func authorTotalDuration(state *appState) float64 { return 0 } +func authorSummaryPaths(state *appState) []string { + if len(state.authorClips) > 0 { + paths := make([]string, 0, len(state.authorClips)) + for _, clip := range state.authorClips { + paths = append(paths, clip.Path) + } + return paths + } + if state.authorFile != nil { + return []string{state.authorFile.Path} + } + return nil +} + func authorTargetBitrateKbps(discSize string, totalSeconds float64) int { if totalSeconds <= 0 { return 0 @@ -1046,28 +1063,12 @@ func (s *appState) promptAuthorOutput(paths []string, region, aspect, title stri outputType = "dvd" } + outputPath := authorDefaultOutputPath(outputType, title, paths) if outputType == "iso" { - dialog.ShowFileSave(func(writer fyne.URIWriteCloser, err error) { - if err != nil || writer == nil { - return - } - path := writer.URI().Path() - writer.Close() - if !strings.HasSuffix(strings.ToLower(path), ".iso") { - path += ".iso" - } - s.generateAuthoring(paths, region, aspect, title, path, true) - }, s.window) + s.generateAuthoring(paths, region, aspect, title, outputPath, true) return } - - dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) { - if err != nil || uri == nil { - return - } - discRoot := filepath.Join(uri.Path(), authorOutputFolderName(title, paths)) - s.generateAuthoring(paths, region, aspect, title, discRoot, false) - }, s.window) + s.generateAuthoring(paths, region, aspect, title, outputPath, false) } func authorWarnings(state *appState) []string { @@ -1167,6 +1168,66 @@ func authorOutputFolderName(title string, paths []string) string { return name } +func authorDefaultOutputDir(outputType string) string { + home, err := os.UserHomeDir() + if err != nil || home == "" { + home = "." + } + dir := filepath.Join(home, "Videos") + if strings.EqualFold(outputType, "iso") { + return filepath.Join(dir, "ISO_Convert") + } + return filepath.Join(dir, "DVD_Convert") +} + +func authorDefaultOutputPath(outputType, title string, paths []string) string { + outputType = strings.ToLower(strings.TrimSpace(outputType)) + if outputType == "" { + outputType = "dvd" + } + baseDir := authorDefaultOutputDir(outputType) + name := strings.TrimSpace(title) + if name == "" { + name = defaultAuthorTitle(paths) + } + name = sanitizeForPath(name) + if name == "" { + name = "dvd_output" + } + if outputType == "iso" { + return uniqueFilePath(filepath.Join(baseDir, name+".iso")) + } + return uniqueFolderPath(filepath.Join(baseDir, name)) +} + +func uniqueFolderPath(path string) string { + if _, err := os.Stat(path); os.IsNotExist(err) { + return path + } + for i := 1; i < 1000; i++ { + tryPath := fmt.Sprintf("%s-%d", path, i) + if _, err := os.Stat(tryPath); os.IsNotExist(err) { + return tryPath + } + } + return fmt.Sprintf("%s-%d", path, time.Now().Unix()) +} + +func uniqueFilePath(path string) string { + if _, err := os.Stat(path); os.IsNotExist(err) { + return path + } + ext := filepath.Ext(path) + base := strings.TrimSuffix(path, ext) + for i := 1; i < 1000; i++ { + tryPath := fmt.Sprintf("%s-%d%s", base, i, ext) + if _, err := os.Stat(tryPath); os.IsNotExist(err) { + return tryPath + } + } + return fmt.Sprintf("%s-%d%s", base, time.Now().Unix(), ext) +} + func (s *appState) generateAuthoring(paths []string, region, aspect, title, outputPath string, makeISO bool) { if err := s.addAuthorToQueue(paths, region, aspect, title, outputPath, makeISO, true); err != nil { dialog.ShowError(err, s.window)