mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
feat: remove YouTube video page subscription finder because meta[itemprop="channelId"]
no longer exists
This commit is contained in:
parent
79ea9e28b5
commit
cb97d4a1a8
2 changed files with 0 additions and 64 deletions
|
@ -29,7 +29,6 @@ type youtubeKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
youtubeIDKindChannel youtubeKind = "channel"
|
youtubeIDKindChannel youtubeKind = "channel"
|
||||||
youtubeIDKindVideo youtubeKind = "video"
|
|
||||||
youtubeIDKindPlaylist youtubeKind = "playlist"
|
youtubeIDKindPlaylist youtubeKind = "playlist"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -102,12 +101,6 @@ func (f *SubscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string)
|
||||||
if localizedError != nil {
|
if localizedError != nil {
|
||||||
return nil, localizedError
|
return nil, localizedError
|
||||||
}
|
}
|
||||||
case youtubeIDKindVideo:
|
|
||||||
slog.Debug("Try to detect feeds from YouTube video page", slog.String("website_url", websiteURL))
|
|
||||||
subscriptions, localizedError = f.FindSubscriptionsFromYouTubeVideoPage(websiteURL)
|
|
||||||
if localizedError != nil {
|
|
||||||
return nil, localizedError
|
|
||||||
}
|
|
||||||
case youtubeIDKindPlaylist:
|
case youtubeIDKindPlaylist:
|
||||||
slog.Debug("Try to detect feeds from YouTube playlist page", slog.String("website_url", websiteURL))
|
slog.Debug("Try to detect feeds from YouTube playlist page", slog.String("website_url", websiteURL))
|
||||||
subscriptions, localizedError = f.FindSubscriptionsFromYouTubePlaylistPage(websiteURL)
|
subscriptions, localizedError = f.FindSubscriptionsFromYouTubePlaylistPage(websiteURL)
|
||||||
|
@ -319,37 +312,6 @@ func (f *SubscriptionFinder) FindSubscriptionsFromYouTubeChannelPage(websiteURL
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SubscriptionFinder) FindSubscriptionsFromYouTubeVideoPage(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
|
||||||
kind, _, err := youtubeURLIDExtractor(websiteURL)
|
|
||||||
if err != nil {
|
|
||||||
slog.Debug("Could not parse url", slog.String("website_url", websiteURL))
|
|
||||||
}
|
|
||||||
|
|
||||||
if kind != youtubeIDKindVideo {
|
|
||||||
slog.Debug("This website is not a YouTube video page, the regex doesn't match", slog.String("website_url", websiteURL))
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
responseHandler := fetcher.NewResponseHandler(f.requestBuilder.ExecuteRequest(websiteURL))
|
|
||||||
defer responseHandler.Close()
|
|
||||||
|
|
||||||
if localizedError := responseHandler.LocalizedError(); localizedError != nil {
|
|
||||||
return nil, localizedError
|
|
||||||
}
|
|
||||||
|
|
||||||
doc, docErr := goquery.NewDocumentFromReader(responseHandler.Body(config.Opts.HTTPClientMaxBodySize()))
|
|
||||||
if docErr != nil {
|
|
||||||
return nil, locale.NewLocalizedErrorWrapper(docErr, "error.unable_to_parse_html_document", docErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if channelID, exists := doc.Find(`meta[itemprop="channelId"]`).First().Attr("content"); exists {
|
|
||||||
feedURL := fmt.Sprintf(`https://www.youtube.com/feeds/videos.xml?channel_id=%s`, channelID)
|
|
||||||
return Subscriptions{NewSubscription(websiteURL, feedURL, parser.FormatAtom)}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *SubscriptionFinder) FindSubscriptionsFromYouTubePlaylistPage(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
func (f *SubscriptionFinder) FindSubscriptionsFromYouTubePlaylistPage(websiteURL string) (Subscriptions, *locale.LocalizedErrorWrapper) {
|
||||||
kind, id, _ := youtubeURLIDExtractor(websiteURL)
|
kind, id, _ := youtubeURLIDExtractor(websiteURL)
|
||||||
|
|
||||||
|
@ -385,10 +347,6 @@ func youtubeURLIDExtractor(websiteURL string) (idKind youtubeKind, id string, er
|
||||||
idKind = youtubeIDKindPlaylist
|
idKind = youtubeIDKindPlaylist
|
||||||
id = decodedUrl.Query().Get("list")
|
id = decodedUrl.Query().Get("list")
|
||||||
return
|
return
|
||||||
case strings.HasPrefix(decodedUrl.Path, "/watch"):
|
|
||||||
idKind = youtubeIDKindVideo
|
|
||||||
id = decodedUrl.Query().Get("v")
|
|
||||||
return
|
|
||||||
case strings.HasPrefix(decodedUrl.Path, "/playlist"):
|
case strings.HasPrefix(decodedUrl.Path, "/playlist"):
|
||||||
idKind = youtubeIDKindPlaylist
|
idKind = youtubeIDKindPlaylist
|
||||||
id = decodedUrl.Query().Get("list")
|
id = decodedUrl.Query().Get("list")
|
||||||
|
|
|
@ -32,13 +32,6 @@ func TestFindYoutubePlaylistFeed(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestItDoesNotConsiderPlaylistWatchPageAsVideoWatchPage(t *testing.T) {
|
|
||||||
_, localizedError := NewSubscriptionFinder(nil).FindSubscriptionsFromYouTubeVideoPage("https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM")
|
|
||||||
if localizedError != nil {
|
|
||||||
t.Fatalf(`Should not consider a playlist watch page as a video watch page`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestYoutubeIdExtractor(t *testing.T) {
|
func TestYoutubeIdExtractor(t *testing.T) {
|
||||||
type testResult struct {
|
type testResult struct {
|
||||||
ID string
|
ID string
|
||||||
|
@ -46,21 +39,6 @@ func TestYoutubeIdExtractor(t *testing.T) {
|
||||||
error error
|
error error
|
||||||
}
|
}
|
||||||
urls := map[string]testResult{
|
urls := map[string]testResult{
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ": {
|
|
||||||
ID: "dQw4w9WgXcQ",
|
|
||||||
Kind: youtubeIDKindVideo,
|
|
||||||
error: nil,
|
|
||||||
},
|
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1": {
|
|
||||||
ID: "dQw4w9WgXcQ",
|
|
||||||
Kind: youtubeIDKindVideo,
|
|
||||||
error: nil,
|
|
||||||
},
|
|
||||||
"https://www.youtube.com/watch?t=1&v=dQw4w9WgXcQ": {
|
|
||||||
ID: "dQw4w9WgXcQ",
|
|
||||||
Kind: youtubeIDKindVideo,
|
|
||||||
error: nil,
|
|
||||||
},
|
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM": {
|
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM": {
|
||||||
ID: "PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM",
|
ID: "PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM",
|
||||||
Kind: youtubeIDKindPlaylist,
|
Kind: youtubeIDKindPlaylist,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue