From fa0f1cb48c8a1a64e6578df23f6953f990c59340 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 5 Nov 2024 15:43:06 +0100 Subject: [PATCH] Sanitize video titles and author names --- downloader/download_downloadr.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/downloader/download_downloadr.go b/downloader/download_downloadr.go index 346d947..f982b5a 100644 --- a/downloader/download_downloadr.go +++ b/downloader/download_downloadr.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "strings" "github.com/gen2brain/beeep" "github.com/kkdai/youtube/v2" @@ -46,12 +47,21 @@ func DownloadR(url string) error { Client: client, } - videoFileRoot := filepath.Join(OUTPUT_DIR, video.Author) + 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, "?", "") + + videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor) err = os.MkdirAll(videoFileRoot, 0755) if err != nil { return fmt.Errorf("failed creating directory %s with %+v", videoFileRoot, err) } - videoFile := filepath.Join(video.Author, video.Title+".mp4") + videoFile := filepath.Join(videoAuthor, videoTitle+".mp4") err = downloader.DownloadComposite(context.Background(), videoFile, video, "hd", "mp4", "") if err != nil { return fmt.Errorf("failed downloading %s with %+v", url, err)