From 7a394b0bf87427b792d3b28d1facd7226cb2405d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 6 Jul 2025 00:56:19 +0200 Subject: [PATCH] refactor(subscription): replace a regex with strings.CutPrefix --- internal/reader/subscription/finder.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/reader/subscription/finder.go b/internal/reader/subscription/finder.go index 24973ea3..3fbde0fa 100644 --- a/internal/reader/subscription/finder.go +++ b/internal/reader/subscription/finder.go @@ -9,7 +9,6 @@ import ( "io" "log/slog" "net/url" - "regexp" "strings" "miniflux.app/v2/internal/config" @@ -24,10 +23,6 @@ import ( "github.com/PuerkitoBio/goquery" ) -var ( - youtubeChannelRegex = regexp.MustCompile(`channel/(.*)$`) -) - type SubscriptionFinder struct { requestBuilder *fetcher.RequestBuilder feedDownloaded bool @@ -300,8 +295,8 @@ func (f *SubscriptionFinder) FindSubscriptionsFromYouTubeChannelPage(websiteURL return nil, nil } - if matches := youtubeChannelRegex.FindStringSubmatch(decodedUrl.Path); len(matches) == 2 { - feedURL := fmt.Sprintf(`https://www.youtube.com/feeds/videos.xml?channel_id=%s`, matches[1]) + if _, after, found := strings.Cut(decodedUrl.Path, "channel/"); found { + feedURL := "https://www.youtube.com/feeds/videos.xml?channel_id=" + after return Subscriptions{NewSubscription(websiteURL, feedURL, parser.FormatAtom)}, nil }