Skip to content

Commit

Permalink
refactor(processor): use URL parsing instead of a regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin authored Dec 12, 2024
1 parent 637fb85 commit 3caa16a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions internal/reader/processor/nebula.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"log/slog"
"regexp"
"net/url"
"strconv"

"github.com/PuerkitoBio/goquery"
Expand All @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions internal/reader/processor/odysee.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"log/slog"
"regexp"
"net/url"
"strconv"

"github.com/PuerkitoBio/goquery"
Expand All @@ -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) {
Expand Down

0 comments on commit 3caa16a

Please sign in to comment.