From 07b9fb4053c539b2bf224316992db5869535fccb Mon Sep 17 00:00:00 2001 From: Logan G Date: Tue, 31 Dec 2024 21:53:15 -0700 Subject: [PATCH] Added filter rules --- config-sample.toml | 32 ++++++++++++++++++++++++++++++++ config.toml | 21 --------------------- ytva.go | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 config-sample.toml delete mode 100644 config.toml diff --git a/config-sample.toml b/config-sample.toml new file mode 100644 index 0000000..e0ff4cd --- /dev/null +++ b/config-sample.toml @@ -0,0 +1,32 @@ +TempDir = "/tmp/" + +[Group.LinuxYouTubers] +URL = [ "https://www.youtube.com/@DistroTube", "https://www.youtube.com/@MentalOutlaw" ] +OutputDir = "videos/%Channel%/%Playlist%/" +FileName = "%Timestamp% - %Title%.mkv" +CFormat = "matroska" +VideoFormat = "bestvideo[height<=720]" +AudioFormat = "bestaudio" +NumVideos = 5 +SizeLimit = 200000000 + +[Group.Odysee] +URL = [ "https://odysee.com/@DistroTube:2", "https://odysee.com/@AlphaNerd:8" ] +OutputDir = "videos2/%Channel%/" +FileName = "%Timestamp% - %Title%.mp4" +CFormat = "mp4" +VideoFormat = "best[height<=720]" +NumVideos = 5 +SizeLimit = 200000000 + +[Group.Music] +URL = [ "https://www.youtube.com/@NoCopyrightSounds", "https://www.youtube.com/@incompetech_kmac" ] +OutputDir = "music/%Channel%/" +FileName = "%Title%.webm" +CFormat = "webm" +AudioFormat = "bestaudio" +NumVideos = 5 +SizeLimit = 10000000 +Filters = [ + {Name = "No Shorts", Input = "%Playlist%", Pattern = ".*- Shorts$", AllowDeny = false} +] diff --git a/config.toml b/config.toml deleted file mode 100644 index b7b3307..0000000 --- a/config.toml +++ /dev/null @@ -1,21 +0,0 @@ -TempDir = "/tmp/" - -[Group.PCBuilders] -URL = [ "https://www.youtube.com/@BudgetBuildsOfficial", "https://www.youtube.com/@RandomGaminginHD" ] -OutputDir = "videos/%Channel%/%Playlist%/" -FileName = "%Timestamp% - %Title%.mkv" -CFormat = "matroska" -VideoFormat = "bestvideo[height<=720]" -AudioFormat = "bestaudio" -NumVideos = 2 -SizeLimit = 4294967296 - -[Group.Odysee] -URL = [ "https://odysee.com/@AlphaNerd:8", "https://odysee.com/@rossmanngroup:a" ] -OutputDir = "videos2/%Channel%/" -FileName = "%Timestamp% - %Title%.mkv" -CFormat = "mp4" -VideoFormat = "best[height<=720]" -AudioFormat = "" -NumVideos = 2 -SizeLimit = 4294967296 diff --git a/ytva.go b/ytva.go index 073877b..9a56df3 100644 --- a/ytva.go +++ b/ytva.go @@ -7,6 +7,7 @@ import ( "os" //"io" //"reflect" + "regexp" //"google.golang.org/api/option" //"google.golang.org/api/youtube/v3" @@ -47,6 +48,12 @@ type GroupConfig struct { AudioFormat string NumVideos uint SizeLimit float64 + Filters []struct { + Name string + Input string + Pattern string + AllowDeny bool + } } var MainConfig _config @@ -116,15 +123,35 @@ func main() { log.Infof("Channel Name: %s", channel.Info.Channel) + video: for _, v := range channel.Info.Entries { log.Debugf("-------------------------------------") log.Debugf("Title: %s", v.Title) + log.Debugf("AltTitle: %s", v.AltTitle) log.Debugf("URL: %s", v.WebpageURL) + log.Debugf("URL: %s", v.URL) log.Debugf("Playlist: %s", v.Playlist) log.Debugf("PublishedAt: %s", v.UploadDate) log.Debugf("IsLive: %t", v.IsLive) //log.Debugf("Description: %s\n", item.Snippet.Description) + if len(group.Filters) > 0 { + for _, filter := range group.Filters { + testStr := fillPlaceholders(filter.Input, v) + + matched, err := regexp.MatchString(filter.Pattern, testStr) + if err != nil { + log.Error(err) + continue + } + + if (matched && !filter.AllowDeny) || (!matched && filter.AllowDeny) { + log.Infof("Skipping \"%s\" due to filter rule \"%s\".", v.Title, filter.Name) + continue video + } + } + } + dirPath := fillPlaceholders(group.OutputDir, v) fileName := fillPlaceholders(group.FileName, v) path := dirPath+"/"+fileName