Compare commits

...

2 Commits

Author SHA1 Message Date
07c20f4582 Close video file that exists when checking 2024-11-05 16:03:38 +01:00
9b38ea7068 Betterify sanitization 2024-11-05 16:03:32 +01:00

View File

@@ -6,6 +6,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"github.com/gen2brain/beeep" "github.com/gen2brain/beeep"
@@ -62,8 +63,9 @@ func DownloadR(url string) error {
} }
fullVideoPath := filepath.Join(OUTPUT_DIR, videoAuthor, videoTitle+".mp4") fullVideoPath := filepath.Join(OUTPUT_DIR, videoAuthor, videoTitle+".mp4")
_, err = os.Open(fullVideoPath) videoFileHandle, err := os.Open(fullVideoPath)
if err == nil { if err == nil {
videoFileHandle.Close()
log.Printf("File %s already exists, skipping download", fullVideoPath) log.Printf("File %s already exists, skipping download", fullVideoPath)
return nil return nil
} }
@@ -78,11 +80,10 @@ func DownloadR(url string) error {
return nil return nil
} }
var re = regexp.MustCompile(`[#!$%&/()";:?;,]`)
func Sanitize(s string) string { func Sanitize(s string) string {
s = strings.ReplaceAll(s, "&", "and") s = strings.ReplaceAll(s, "&", "and")
s = strings.ReplaceAll(s, "?", "") s = re.ReplaceAllString(s, "")
s = strings.ReplaceAll(s, ":", "")
s = strings.ReplaceAll(s, ";", "")
s = strings.ReplaceAll(s, ",", "")
return s return s
} }