Refactor sanitization
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user