mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Add workaround to get YouTube feed from video page
This commit is contained in:
parent
7380c64141
commit
fc75b0cd8e
1 changed files with 28 additions and 2 deletions
|
@ -22,11 +22,13 @@ import (
|
||||||
var (
|
var (
|
||||||
errUnreadableDoc = "Unable to analyze this page: %v"
|
errUnreadableDoc = "Unable to analyze this page: %v"
|
||||||
youtubeChannelRegex = regexp.MustCompile(`youtube\.com/channel/(.*)`)
|
youtubeChannelRegex = regexp.MustCompile(`youtube\.com/channel/(.*)`)
|
||||||
|
youtubeVideoRegex = regexp.MustCompile(`youtube\.com/watch\?v=(.*)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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)
|
websiteURL = findYoutubeChannelFeed(websiteURL)
|
||||||
|
websiteURL = parseYoutubeVideoPage(websiteURL)
|
||||||
|
|
||||||
request := client.New(websiteURL)
|
request := client.New(websiteURL)
|
||||||
request.WithCredentials(username, password)
|
request.WithCredentials(username, password)
|
||||||
|
@ -48,14 +50,15 @@ func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscr
|
||||||
return subscriptions, nil
|
return subscriptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriptions, err := parseDocument(response.EffectiveURL, strings.NewReader(body))
|
subscriptions, err := parseWebPage(response.EffectiveURL, strings.NewReader(body))
|
||||||
if err != nil || subscriptions != nil {
|
if err != nil || subscriptions != nil {
|
||||||
return subscriptions, err
|
return subscriptions, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tryWellKnownUrls(websiteURL, userAgent, username, password)
|
return tryWellKnownUrls(websiteURL, userAgent, username, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDocument(websiteURL string, data io.Reader) (Subscriptions, *errors.LocalizedError) {
|
func parseWebPage(websiteURL string, data io.Reader) (Subscriptions, *errors.LocalizedError) {
|
||||||
var subscriptions Subscriptions
|
var subscriptions Subscriptions
|
||||||
queries := map[string]string{
|
queries := map[string]string{
|
||||||
"link[type='application/rss+xml']": "rss",
|
"link[type='application/rss+xml']": "rss",
|
||||||
|
@ -105,6 +108,29 @@ func findYoutubeChannelFeed(websiteURL string) string {
|
||||||
return websiteURL
|
return websiteURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseYoutubeVideoPage(websiteURL string) string {
|
||||||
|
if !youtubeVideoRegex.MatchString(websiteURL) {
|
||||||
|
return websiteURL
|
||||||
|
}
|
||||||
|
|
||||||
|
request := client.New(websiteURL)
|
||||||
|
response, browserErr := browser.Exec(request)
|
||||||
|
if browserErr != nil {
|
||||||
|
return websiteURL
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, docErr := goquery.NewDocumentFromReader(response.Body)
|
||||||
|
if docErr != nil {
|
||||||
|
return websiteURL
|
||||||
|
}
|
||||||
|
|
||||||
|
if channelID, exists := doc.Find(`meta[itemprop="channelId"]`).First().Attr("content"); exists {
|
||||||
|
return fmt.Sprintf(`https://www.youtube.com/feeds/videos.xml?channel_id=%s`, channelID)
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue