feat(cleaner): add directory for video name cleaning with CLI tool and registry entry

This commit is contained in:
2025-09-08 08:40:13 +02:00
parent 1a05963c31
commit f9272e76eb
3 changed files with 66 additions and 0 deletions

56
cleaner/main.go Normal file
View File

@@ -0,0 +1,56 @@
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
)
func main() {
flag.Parse()
if flag.NArg() == 0 {
fmt.Println("Usage: cleaner <files>")
os.Exit(1)
}
// regex to match " - 2025-07-08 01h31m45s - "
re := regexp.MustCompile(` - (\d{4}-\d{2}-\d{2} \d{2}h\d{2}m\d{2}s) - `)
for _, file := range flag.Args() {
info, err := os.Stat(file)
if err != nil {
fmt.Printf("ERROR: %v\n", err)
continue
}
if info.IsDir() {
fmt.Printf("SKIP (directory): %s\n", file)
continue
}
name := filepath.Base(file)
match := re.FindStringSubmatch(name)
if match == nil {
fmt.Printf("SKIP (no date pattern): %s\n", name)
continue
}
newName := match[1] + filepath.Ext(name)
if name == newName {
fmt.Printf("SKIP (already named): %s\n", name)
continue
}
if _, err := os.Stat(newName); err == nil {
fmt.Printf("SKIP (target exists): %s -> %s\n", name, newName)
continue
}
err = os.Rename(name, newName)
if err != nil {
fmt.Printf("ERROR renaming %s: %v\n", name, err)
} else {
fmt.Printf("RENAMED: %s -> %s\n", name, newName)
}
continue
}
}