Sanitize video titles and author names
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user