feat(cleaner): add directory for video name cleaning with CLI tool and registry entry
This commit is contained in:
3
cleaner/go.mod
Normal file
3
cleaner/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module tcleaner
|
||||||
|
|
||||||
|
go 1.23.6
|
7
cleaner/install_grader_context_menu.reg
Normal file
7
cleaner/install_grader_context_menu.reg
Normal file
@@ -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\""
|
56
cleaner/main.go
Normal file
56
cleaner/main.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user