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,
Client: client,
}
videoTitle := video.Title
videoAuthor := video.Author
videoTitle = strings.ReplaceAll(videoTitle, " ", "-")
videoTitle = strings.ReplaceAll(videoTitle, "&", "and")
videoTitle = strings.ReplaceAll(videoTitle, "?", "")
videoAuthor = strings.ReplaceAll(videoAuthor, " ", "-")
videoAuthor = strings.ReplaceAll(videoAuthor, "&", "and")
videoAuthor = strings.ReplaceAll(videoAuthor, "?", "")
videoTitle := Sanitize(video.Title)
videoAuthor := Sanitize(video.Author)
videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor)
err = os.MkdirAll(videoFileRoot, 0755)
@@ -84,3 +78,11 @@ func DownloadR(url string) error {
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
}