|
|
@@ -70,24 +70,15 @@ func (f *subscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string,
|
|
|
}
|
|
|
|
|
|
// Step 2) Check if the website URL is a YouTube channel.
|
|
|
- slog.Debug("Try to detect feeds from YouTube channel page", slog.String("website_url", websiteURL))
|
|
|
- if subscriptions, localizedError := f.findSubscriptionsFromYouTubeChannelPage(websiteURL); localizedError != nil {
|
|
|
+ slog.Debug("Try to detect feeds for a YouTube page", slog.String("website_url", websiteURL))
|
|
|
+ if subscriptions, localizedError := f.findSubscriptionsFromYouTube(websiteURL); localizedError != nil {
|
|
|
return nil, localizedError
|
|
|
} else if len(subscriptions) > 0 {
|
|
|
- slog.Debug("Subscriptions found from YouTube channel page", slog.String("website_url", websiteURL), slog.Any("subscriptions", subscriptions))
|
|
|
+ slog.Debug("Subscriptions found from YouTube page", slog.String("website_url", websiteURL), slog.Any("subscriptions", subscriptions))
|
|
|
return subscriptions, nil
|
|
|
}
|
|
|
|
|
|
- // Step 3) Check if the website URL is a YouTube playlist.
|
|
|
- slog.Debug("Try to detect feeds from YouTube playlist page", slog.String("website_url", websiteURL))
|
|
|
- if subscriptions, localizedError := f.findSubscriptionsFromYouTubePlaylistPage(websiteURL); localizedError != nil {
|
|
|
- return nil, localizedError
|
|
|
- } else if len(subscriptions) > 0 {
|
|
|
- slog.Debug("Subscriptions found from YouTube playlist page", slog.String("website_url", websiteURL), slog.Any("subscriptions", subscriptions))
|
|
|
- return subscriptions, nil
|
|
|
- }
|
|
|
-
|
|
|
- // Step 4) Parse web page to find feeds from HTML meta tags.
|
|
|
+ // Step 3) Parse web page to find feeds from HTML meta tags.
|
|
|
slog.Debug("Try to detect feeds from HTML meta tags",
|
|
|
slog.String("website_url", websiteURL),
|
|
|
slog.String("content_type", responseHandler.ContentType()),
|
|
|
@@ -99,7 +90,7 @@ func (f *subscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string,
|
|
|
return subscriptions, nil
|
|
|
}
|
|
|
|
|
|
- // Step 5) Check if the website URL can use RSS-Bridge.
|
|
|
+ // Step 4) Check if the website URL can use RSS-Bridge.
|
|
|
if rssBridgeURL != "" {
|
|
|
slog.Debug("Try to detect feeds with RSS-Bridge", slog.String("website_url", websiteURL))
|
|
|
if subscriptions, localizedError := f.findSubscriptionsFromRSSBridge(websiteURL, rssBridgeURL, rssBridgeToken); localizedError != nil {
|
|
|
@@ -110,7 +101,7 @@ func (f *subscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Step 6) Check if the website has a known feed URL.
|
|
|
+ // Step 5) Check if the website has a known feed URL.
|
|
|
slog.Debug("Try to detect feeds from well-known URLs", slog.String("website_url", websiteURL))
|
|
|
if subscriptions, localizedError := f.findSubscriptionsFromWellKnownURLs(websiteURL); localizedError != nil {
|
|
|
return nil, localizedError
|
|
|
@@ -282,40 +273,26 @@ func (f *subscriptionFinder) findSubscriptionsFromRSSBridge(websiteURL, rssBridg
|
|
|
return subscriptions, nil
|
|
|
}
|
|
|
|
|
|
-func (f *subscriptionFinder) findSubscriptionsFromYouTubeChannelPage(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
|
|
- decodedUrl, err := url.Parse(websiteURL)
|
|
|
+func (f *subscriptionFinder) findSubscriptionsFromYouTube(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
|
|
+ decodedURL, err := url.Parse(websiteURL)
|
|
|
if err != nil {
|
|
|
return nil, locale.NewLocalizedErrorWrapper(err, "error.invalid_site_url", err)
|
|
|
}
|
|
|
|
|
|
- if !strings.HasSuffix(decodedUrl.Host, "youtube.com") {
|
|
|
- slog.Debug("This website is not a YouTube page, the regex doesn't match", slog.String("website_url", websiteURL))
|
|
|
+ if !strings.HasSuffix(decodedURL.Host, "youtube.com") {
|
|
|
+ slog.Debug("YouTube feed discovery skipped: not a YouTube domain", slog.String("website_url", websiteURL))
|
|
|
return nil, nil
|
|
|
}
|
|
|
-
|
|
|
- if _, channelID, found := strings.Cut(decodedUrl.Path, "channel/"); found {
|
|
|
+ if _, channelID, found := strings.Cut(decodedURL.Path, "channel/"); found {
|
|
|
feedURL := "https://www.youtube.com/feeds/videos.xml?channel_id=" + channelID
|
|
|
- return Subscriptions{NewSubscription(websiteURL, feedURL, parser.FormatAtom)}, nil
|
|
|
+ return Subscriptions{NewSubscription(decodedURL.String(), feedURL, parser.FormatAtom)}, nil
|
|
|
}
|
|
|
|
|
|
- return nil, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (f *subscriptionFinder) findSubscriptionsFromYouTubePlaylistPage(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
|
|
- decodedUrl, err := url.Parse(websiteURL)
|
|
|
- if err != nil {
|
|
|
- return nil, locale.NewLocalizedErrorWrapper(err, "error.invalid_site_url", err)
|
|
|
- }
|
|
|
-
|
|
|
- if !strings.HasSuffix(decodedUrl.Host, "youtube.com") {
|
|
|
- slog.Debug("This website is not a YouTube page, the regex doesn't match", slog.String("website_url", websiteURL))
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
-
|
|
|
- if (strings.HasPrefix(decodedUrl.Path, "/watch") && decodedUrl.Query().Has("list")) || strings.HasPrefix(decodedUrl.Path, "/playlist") {
|
|
|
- playlistID := decodedUrl.Query().Get("list")
|
|
|
- feedURL := "https://www.youtube.com/feeds/videos.xml?playlist_id=" + playlistID
|
|
|
- return Subscriptions{NewSubscription(websiteURL, feedURL, parser.FormatAtom)}, nil
|
|
|
+ if strings.HasPrefix(decodedURL.Path, "/watch") || strings.HasPrefix(decodedURL.Path, "/playlist") {
|
|
|
+ if playlistID := decodedURL.Query().Get("list"); playlistID != "" {
|
|
|
+ feedURL := "https://www.youtube.com/feeds/videos.xml?playlist_id=" + playlistID
|
|
|
+ return Subscriptions{NewSubscription(decodedURL.String(), feedURL, parser.FormatAtom)}, nil
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return nil, nil
|