From 3caa16ac3176e2a86bf26771d09cc8753da7c0ce Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Thu, 12 Dec 2024 03:30:59 +0000 Subject: [PATCH] refactor(processor): use URL parsing instead of a regex --- internal/reader/processor/nebula.go | 13 ++++++++----- internal/reader/processor/odysee.go | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/reader/processor/nebula.go b/internal/reader/processor/nebula.go index d0b0b6ef..cf8a70c0 100644 --- a/internal/reader/processor/nebula.go +++ b/internal/reader/processor/nebula.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" "log/slog" - "regexp" + "net/url" "strconv" "github.com/PuerkitoBio/goquery" @@ -17,14 +17,17 @@ import ( "miniflux.app/v2/internal/reader/fetcher" ) -var nebulaRegex = regexp.MustCompile(`^https://nebula\.tv`) - func shouldFetchNebulaWatchTime(entry *model.Entry) bool { if !config.Opts.FetchNebulaWatchTime() { return false } - matches := nebulaRegex.FindStringSubmatch(entry.URL) - return matches != nil + + u, err := url.Parse(entry.URL) + if err != nil { + return false + } + + return u.Hostname() == "nebula.tv" } func fetchNebulaWatchTime(websiteURL string) (int, error) { diff --git a/internal/reader/processor/odysee.go b/internal/reader/processor/odysee.go index 90733b2f..7a174b5a 100644 --- a/internal/reader/processor/odysee.go +++ b/internal/reader/processor/odysee.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" "log/slog" - "regexp" + "net/url" "strconv" "github.com/PuerkitoBio/goquery" @@ -17,14 +17,17 @@ import ( "miniflux.app/v2/internal/reader/fetcher" ) -var odyseeRegex = regexp.MustCompile(`^https://odysee\.com`) - func shouldFetchOdyseeWatchTime(entry *model.Entry) bool { if !config.Opts.FetchOdyseeWatchTime() { return false } - matches := odyseeRegex.FindStringSubmatch(entry.URL) - return matches != nil + + u, err := url.Parse(entry.URL) + if err != nil { + return false + } + + return u.Hostname() == "odysee.com" } func fetchOdyseeWatchTime(websiteURL string) (int, error) {