Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miniflux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
miniflux
Commits
fc75b0cd
Commit
fc75b0cd
authored
4 years ago
by
Frédéric Guillot
Browse files
Options
Downloads
Patches
Plain Diff
Add workaround to get YouTube feed from video page
parent
7380c641
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reader/subscription/finder.go
+28
-2
28 additions, 2 deletions
reader/subscription/finder.go
with
28 additions
and
2 deletions
reader/subscription/finder.go
+
28
−
2
View file @
fc75b0cd
...
@@ -22,11 +22,13 @@ import (
...
@@ -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
...
@@ -48,14 +50,15 @@ func FindSubscriptions(websiteURL, userAgent, username, password string) (Subscr
return
subscriptions
,
nil
return
subscriptions
,
nil
}
}
subscriptions
,
err
:=
parse
Document
(
response
.
EffectiveURL
,
strings
.
NewReader
(
body
))
subscriptions
,
err
:=
parse
WebPage
(
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
parse
Document
(
websiteURL
string
,
data
io
.
Reader
)
(
Subscriptions
,
*
errors
.
LocalizedError
)
{
func
parse
WebPage
(
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 {
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment