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