diff --git a/cleaner/go.mod b/cleaner/go.mod new file mode 100644 index 0000000..5081a81 --- /dev/null +++ b/cleaner/go.mod @@ -0,0 +1,3 @@ +module tcleaner + +go 1.23.6 diff --git a/cleaner/install_grader_context_menu.reg b/cleaner/install_grader_context_menu.reg new file mode 100644 index 0000000..84815d4 --- /dev/null +++ b/cleaner/install_grader_context_menu.reg @@ -0,0 +1,7 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CURRENT_USER\Software\Classes\*\shell\Clean video name] +@="Clean video name" + +[HKEY_CURRENT_USER\Software\Classes\*\shell\Clean video name\command] +@="C:\\Users\\administrator\\go\\bin\\tcleaner.exe \"%1\"" \ No newline at end of file diff --git a/cleaner/main.go b/cleaner/main.go new file mode 100644 index 0000000..4f1985e --- /dev/null +++ b/cleaner/main.go @@ -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 ") + 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 + } +}