Add support for Invidious
- Embed Invidious player for invidio.us feeds - Add new rewrite rule to use Invidious player for Youtube feeds
This commit is contained in:
parent
e494d6e381
commit
592151bdb6
4 changed files with 27 additions and 1 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
var (
|
||||
youtubeRegex = regexp.MustCompile(`youtube\.com/watch\?v=(.*)`)
|
||||
invidioRegex = regexp.MustCompile(`invidio\.us\/watch\?v=(.*)`)
|
||||
imgRegex = regexp.MustCompile(`<img [^>]+>`)
|
||||
textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])`)
|
||||
)
|
||||
|
@ -148,6 +149,26 @@ func addYoutubeVideo(entryURL, entryContent string) string {
|
|||
return entryContent
|
||||
}
|
||||
|
||||
func addYoutubeVideoUsingInvidiousPlayer(entryURL, entryContent string) string {
|
||||
matches := youtubeRegex.FindStringSubmatch(entryURL)
|
||||
|
||||
if len(matches) == 2 {
|
||||
video := `<iframe width="650" height="350" frameborder="0" src="https://invidio.us/embed/` + matches[1] + `" allowfullscreen></iframe>`
|
||||
return video + `<br>` + entryContent
|
||||
}
|
||||
return entryContent
|
||||
}
|
||||
|
||||
func addInvidiousVideo(entryURL, entryContent string) string {
|
||||
matches := invidioRegex.FindStringSubmatch(entryURL)
|
||||
fmt.Println(matches)
|
||||
if len(matches) == 2 {
|
||||
video := `<iframe width="650" height="350" frameborder="0" src="https://invidio.us/embed/` + matches[1] + `" allowfullscreen></iframe>`
|
||||
return video + `<br>` + entryContent
|
||||
}
|
||||
return entryContent
|
||||
}
|
||||
|
||||
func addPDFLink(entryURL, entryContent string) string {
|
||||
if strings.HasSuffix(entryURL, ".pdf") {
|
||||
return fmt.Sprintf(`<a href="%s">PDF</a><br>%s`, entryURL, entryContent)
|
||||
|
|
|
@ -33,6 +33,10 @@ func Rewriter(entryURL, entryContent, customRewriteRules string) string {
|
|||
entryContent = addDynamicImage(entryURL, entryContent)
|
||||
case "add_youtube_video":
|
||||
entryContent = addYoutubeVideo(entryURL, entryContent)
|
||||
case "add_invidious_video":
|
||||
entryContent = addInvidiousVideo(entryURL, entryContent)
|
||||
case "add_youtube_video_using_invidious_player":
|
||||
entryContent = addYoutubeVideoUsingInvidiousPlayer(entryURL, entryContent)
|
||||
case "add_pdf_download_link":
|
||||
entryContent = addPDFLink(entryURL, entryContent)
|
||||
case "nl2br":
|
||||
|
@ -47,7 +51,6 @@ func Rewriter(entryURL, entryContent, customRewriteRules string) string {
|
|||
|
||||
func getPredefinedRewriteRules(entryURL string) string {
|
||||
urlDomain := url.Domain(entryURL)
|
||||
|
||||
for domain, rules := range predefinedRules {
|
||||
if strings.Contains(urlDomain, domain) {
|
||||
return rules
|
||||
|
|
|
@ -27,6 +27,7 @@ var predefinedRules = map[string]string{
|
|||
"thedoghousediaries.com": "add_image_title",
|
||||
"treelobsters.com": "add_image_title",
|
||||
"youtube.com": "add_youtube_video",
|
||||
"invidio.us": "add_invidious_video",
|
||||
"xkcd.com": "add_image_title",
|
||||
"framatube.org": "nl2br,convert_text_link",
|
||||
}
|
||||
|
|
|
@ -292,6 +292,7 @@ func isBlacklistedResource(src string) bool {
|
|||
|
||||
func isValidIframeSource(src string) bool {
|
||||
whitelist := []string{
|
||||
"https://invidio.us",
|
||||
"//www.youtube.com",
|
||||
"http://www.youtube.com",
|
||||
"https://www.youtube.com",
|
||||
|
|
Loading…
Reference in a new issue