check if fullvod exists; store config in UserConfigDir
All checks were successful
/ build-linux-amd64 (push) Successful in 1m8s

This commit is contained in:
ari melody 2026-01-31 02:28:09 +00:00
parent c3dc6f095e
commit aa28ffedc8
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 58 additions and 13 deletions

47
main.go
View file

@ -28,19 +28,29 @@ var helpText string
const segmentExtension = "mkv"
func showHelp() {
execSplits := strings.Split(os.Args[0], "/")
execName := execSplits[len(execSplits) - 1]
fmt.Printf(helpText, execName)
fmt.Println(helpText)
os.Exit(0)
}
func main() {
// config
userConfigDir, err := os.UserConfigDir()
if err != nil {
log.Fatalf("Could not determine user configuration directory: %v", err)
os.Exit(1)
}
config.CONFIG_FILENAME = path.Join(userConfigDir, "vodular", "config.toml")
cfg, err := config.ReadConfig(config.CONFIG_FILENAME)
if err != nil {
log.Fatalf("Failed to read config: %v", err)
os.Exit(1)
}
if cfg == nil {
err = os.MkdirAll(path.Dir(config.CONFIG_FILENAME), 0750)
if err != nil {
log.Fatalf("Failed to create config directory: %v", err)
os.Exit(1)
}
err = config.GenerateConfig(config.CONFIG_FILENAME)
if err != nil {
log.Fatalf("Failed to generate config: %v", err)
@ -57,7 +67,6 @@ func main() {
// arguments
if len(os.Args) < 2 || os.Args[1] == "--help" || os.Args[1] == "-h" {
showHelp()
os.Exit(0)
}
var verbose bool = false
@ -76,7 +85,6 @@ func main() {
fallthrough
case "--help":
showHelp()
os.Exit(0)
case "-v":
fallthrough
@ -228,19 +236,34 @@ func main() {
os.Exit(1)
}
fmt.Printf(
"\n================================\n" +
"TITLE:\n%s\n\n" +
"DESCRIPTION:\n%s\n" +
"\n================================\n\n" +
"< TITLE >\n%s\n\n" +
"< DESCRIPTION >\n%s\n" +
"\n================================\n",
title, description,
)
}
// concatenate VOD segments into full VOD
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
if err != nil {
log.Fatalf("Failed to concatenate VOD segments: %v", err)
os.Exit(1)
fullVodExists := func () bool {
// check if full VOD already exists with expected duration
if fullVodProbe, err := scanner.ProbeSegment(video.Filename); err != nil {
var totalLength float64 = 0
for _, filename := range vodFiles {
probe, err := scanner.ProbeSegment(filename)
if err != nil { continue }
totalLength += probe.Format.Duration
}
return fullVodProbe.Format.Duration == totalLength
}
return false
}()
if !fullVodExists {
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
if err != nil {
log.Fatalf("Failed to concatenate VOD segments: %v", err)
os.Exit(1)
}
}
// youtube oauth flow