diff --git a/downloader/download_downloadr.go b/downloader/download_downloadr.go index 29e2bcf..c44f796 100644 --- a/downloader/download_downloadr.go +++ b/downloader/download_downloadr.go @@ -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 +}