1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

refactor(processor): use URL parsing instead of a regex

This commit is contained in:
Julien Voisin 2024-12-12 03:30:59 +00:00 committed by GitHub
parent 637fb85de0
commit 3caa16ac31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View file

@ -7,7 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"log/slog" "log/slog"
"regexp" "net/url"
"strconv" "strconv"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
@ -17,14 +17,17 @@ import (
"miniflux.app/v2/internal/reader/fetcher" "miniflux.app/v2/internal/reader/fetcher"
) )
var nebulaRegex = regexp.MustCompile(`^https://nebula\.tv`)
func shouldFetchNebulaWatchTime(entry *model.Entry) bool { func shouldFetchNebulaWatchTime(entry *model.Entry) bool {
if !config.Opts.FetchNebulaWatchTime() { if !config.Opts.FetchNebulaWatchTime() {
return false 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) { func fetchNebulaWatchTime(websiteURL string) (int, error) {

View file

@ -7,7 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"log/slog" "log/slog"
"regexp" "net/url"
"strconv" "strconv"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
@ -17,14 +17,17 @@ import (
"miniflux.app/v2/internal/reader/fetcher" "miniflux.app/v2/internal/reader/fetcher"
) )
var odyseeRegex = regexp.MustCompile(`^https://odysee\.com`)
func shouldFetchOdyseeWatchTime(entry *model.Entry) bool { func shouldFetchOdyseeWatchTime(entry *model.Entry) bool {
if !config.Opts.FetchOdyseeWatchTime() { if !config.Opts.FetchOdyseeWatchTime() {
return false 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) { func fetchOdyseeWatchTime(websiteURL string) (int, error) {