Refactor sanitization

This commit is contained in:
2024-11-05 15:59:08 +01:00
parent 0ad8722bf9
commit 8ab4b4c280

View File

@@ -51,15 +51,9 @@ func DownloadR(url string) error {
OutputDir: OUTPUT_DIR, OutputDir: OUTPUT_DIR,
Client: client, Client: client,
} }
videoTitle := video.Title
videoAuthor := video.Author videoTitle := Sanitize(video.Title)
videoTitle = strings.ReplaceAll(videoTitle, " ", "-") videoAuthor := Sanitize(video.Author)
videoTitle = strings.ReplaceAll(videoTitle, "&", "and")
videoTitle = strings.ReplaceAll(videoTitle, "?", "")
videoAuthor = strings.ReplaceAll(videoAuthor, " ", "-")
videoAuthor = strings.ReplaceAll(videoAuthor, "&", "and")
videoAuthor = strings.ReplaceAll(videoAuthor, "?", "")
videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor) videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor)
err = os.MkdirAll(videoFileRoot, 0755) err = os.MkdirAll(videoFileRoot, 0755)
@@ -84,3 +78,11 @@ func DownloadR(url string) error {
return nil return nil
} }
func Sanitize(s string) string {
s = strings.ReplaceAll(s, "&", "and")
s = strings.ReplaceAll(s, "?", "")
s = strings.ReplaceAll(s, ":", "")
s = strings.ReplaceAll(s, ";", "")
s = strings.ReplaceAll(s, ",", "")
return s
}