Skip to content

Commit b3d8ddc

Browse files
committed
Check if in a browser instead of if in OBS specifically to support other streaming software
1 parent 272363e commit b3d8ddc

File tree

11 files changed

+1060
-85
lines changed

11 files changed

+1060
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ desktop.ini
2323
# Build and distribution files
2424
dist/
2525
build/
26+
test/
2627

2728
# Logs
2829
*.log

internal/config/config.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Package config provides configuration management for the OBS Random Videos application.
2+
// It handles parsing command-line flags and maintaining application settings.
3+
package config
4+
5+
import (
6+
"flag"
7+
"os"
8+
)
9+
10+
// Config holds the application configuration
11+
type Config struct {
12+
// OutputFileName is the name of the generated HTML file
13+
OutputFileName string
14+
// Version is the application version
15+
Version string
16+
// MaxFileSize is the maximum file size to consider (in bytes, 0 = no limit)
17+
MaxFileSize int64
18+
// ConcurrentScans is the number of concurrent goroutines for directory scanning
19+
ConcurrentScans int
20+
// Directory is the directory to scan for media files
21+
Directory string
22+
// Recursive determines if subdirectories should be scanned
23+
Recursive bool
24+
// Verbose enables verbose output
25+
Verbose bool
26+
// AutoSanitize determines if file names should be automatically sanitized
27+
AutoSanitize bool
28+
}
29+
30+
// Default returns a Config with default values
31+
func Default(version string) *Config {
32+
return &Config{
33+
OutputFileName: "obs-random-videos.html",
34+
Version: version,
35+
MaxFileSize: 0, // No limit by default
36+
ConcurrentScans: 4,
37+
Directory: ".",
38+
Recursive: true,
39+
Verbose: false,
40+
AutoSanitize: false,
41+
}
42+
}
43+
44+
// ParseFlags parses command line flags and returns a Config
45+
func ParseFlags(version string) *Config {
46+
cfg := Default(version)
47+
48+
flag.StringVar(&cfg.Directory, "dir", cfg.Directory, "Directory to scan for media files")
49+
flag.StringVar(&cfg.OutputFileName, "output", cfg.OutputFileName, "Output HTML filename")
50+
flag.BoolVar(&cfg.Recursive, "recursive", cfg.Recursive, "Scan subdirectories")
51+
flag.BoolVar(&cfg.Verbose, "verbose", cfg.Verbose, "Verbose output")
52+
flag.BoolVar(&cfg.AutoSanitize, "sanitize", cfg.AutoSanitize, "Automatically sanitize problematic file names")
53+
flag.Int64Var(&cfg.MaxFileSize, "max-size", cfg.MaxFileSize, "Maximum file size in bytes (0 = no limit)")
54+
flag.IntVar(&cfg.ConcurrentScans, "concurrent", cfg.ConcurrentScans, "Number of concurrent file scanners")
55+
56+
// Check for DEBUG environment variable
57+
if os.Getenv("DEBUG") != "" {
58+
cfg.Verbose = true
59+
}
60+
61+
flag.Parse()
62+
63+
return cfg
64+
}

internal/config/config_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestDefault(t *testing.T) {
8+
version := "1.0.0"
9+
cfg := Default(version)
10+
11+
if cfg.Version != version {
12+
t.Errorf("Version = %v, want %v", cfg.Version, version)
13+
}
14+
15+
if cfg.OutputFileName != "obs-random-videos.html" {
16+
t.Errorf("OutputFileName = %v, want 'obs-random-videos.html'", cfg.OutputFileName)
17+
}
18+
19+
if cfg.ConcurrentScans != 4 {
20+
t.Errorf("ConcurrentScans = %v, want 4", cfg.ConcurrentScans)
21+
}
22+
23+
if cfg.Recursive != true {
24+
t.Errorf("Recursive = %v, want true", cfg.Recursive)
25+
}
26+
27+
if cfg.Verbose != false {
28+
t.Errorf("Verbose = %v, want false", cfg.Verbose)
29+
}
30+
31+
if cfg.AutoSanitize != false {
32+
t.Errorf("AutoSanitize = %v, want false", cfg.AutoSanitize)
33+
}
34+
}
35+
36+
func TestConfigFields(t *testing.T) {
37+
cfg := &Config{
38+
OutputFileName: "test.html",
39+
Version: "2.0.0",
40+
MaxFileSize: 1024,
41+
ConcurrentScans: 8,
42+
Directory: "/test/dir",
43+
Recursive: false,
44+
Verbose: true,
45+
AutoSanitize: true,
46+
}
47+
48+
if cfg.OutputFileName != "test.html" {
49+
t.Errorf("OutputFileName = %v, want 'test.html'", cfg.OutputFileName)
50+
}
51+
52+
if cfg.MaxFileSize != 1024 {
53+
t.Errorf("MaxFileSize = %v, want 1024", cfg.MaxFileSize)
54+
}
55+
56+
if cfg.ConcurrentScans != 8 {
57+
t.Errorf("ConcurrentScans = %v, want 8", cfg.ConcurrentScans)
58+
}
59+
}

0 commit comments

Comments
 (0)