Add workaround to find YouTube channel feeds
YouTube doesn't expose RSS links anymore for new-style URLs.
This commit is contained in:
parent
943e7a7317
commit
7380c64141
2 changed files with 36 additions and 1 deletions
|
@ -5,7 +5,9 @@
|
||||||
package subscription // import "miniflux.app/reader/subscription"
|
package subscription // import "miniflux.app/reader/subscription"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"miniflux.app/errors"
|
"miniflux.app/errors"
|
||||||
|
@ -18,11 +20,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errUnreadableDoc = "Unable to analyze this page: %v"
|
errUnreadableDoc = "Unable to analyze this page: %v"
|
||||||
|
youtubeChannelRegex = regexp.MustCompile(`youtube\.com/channel/(.*)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// FindSubscriptions downloads and try to find one or more subscriptions from an URL.
|
// FindSubscriptions downloads and try to find one or more subscriptions from an URL.
|
||||||
func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscriptions, *errors.LocalizedError) {
|
func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscriptions, *errors.LocalizedError) {
|
||||||
|
websiteURL = findYoutubeChannelFeed(websiteURL)
|
||||||
|
|
||||||
request := client.New(websiteURL)
|
request := client.New(websiteURL)
|
||||||
request.WithCredentials(username, password)
|
request.WithCredentials(username, password)
|
||||||
request.WithUserAgent(userAgent)
|
request.WithUserAgent(userAgent)
|
||||||
|
@ -91,6 +96,15 @@ func parseDocument(websiteURL string, data io.Reader) (Subscriptions, *errors.Lo
|
||||||
return subscriptions, nil
|
return subscriptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findYoutubeChannelFeed(websiteURL string) string {
|
||||||
|
matches := youtubeChannelRegex.FindStringSubmatch(websiteURL)
|
||||||
|
|
||||||
|
if len(matches) == 2 {
|
||||||
|
return fmt.Sprintf(`https://www.youtube.com/feeds/videos.xml?channel_id=%s`, matches[1])
|
||||||
|
}
|
||||||
|
return websiteURL
|
||||||
|
}
|
||||||
|
|
||||||
func tryWellKnownUrls(websiteURL, userAgent, username, password string) (Subscriptions, *errors.LocalizedError) {
|
func tryWellKnownUrls(websiteURL, userAgent, username, password string) (Subscriptions, *errors.LocalizedError) {
|
||||||
var subscriptions Subscriptions
|
var subscriptions Subscriptions
|
||||||
knownURLs := map[string]string{
|
knownURLs := map[string]string{
|
||||||
|
|
21
reader/subscription/finder_test.go
Normal file
21
reader/subscription/finder_test.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright 2020 Frédéric Guillot. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Apache 2.0
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package subscription
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFindYoutubeChannelFeed(t *testing.T) {
|
||||||
|
scenarios := map[string]string{
|
||||||
|
"https://www.youtube.com/channel/UC-Qj80avWItNRjkZ41rzHyw": "https://www.youtube.com/feeds/videos.xml?channel_id=UC-Qj80avWItNRjkZ41rzHyw",
|
||||||
|
"http://example.org/feed": "http://example.org/feed",
|
||||||
|
}
|
||||||
|
|
||||||
|
for websiteURL, expectedFeedURL := range scenarios {
|
||||||
|
result := findYoutubeChannelFeed(websiteURL)
|
||||||
|
if result != expectedFeedURL {
|
||||||
|
t.Errorf(`Unexpected Feed, got %s, instead of %s`, result, expectedFeedURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue