diff --git a/reader/rewrite/rewrite_functions.go b/reader/rewrite/rewrite_functions.go index 8f83aa95..cda21976 100644 --- a/reader/rewrite/rewrite_functions.go +++ b/reader/rewrite/rewrite_functions.go @@ -16,6 +16,7 @@ import ( var ( youtubeRegex = regexp.MustCompile(`youtube\.com/watch\?v=(.*)`) + invidioRegex = regexp.MustCompile(`invidio\.us\/watch\?v=(.*)`) imgRegex = regexp.MustCompile(`]+>`) 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 := `` + return video + `
` + entryContent + } + return entryContent +} + +func addInvidiousVideo(entryURL, entryContent string) string { + matches := invidioRegex.FindStringSubmatch(entryURL) + fmt.Println(matches) + if len(matches) == 2 { + video := `` + return video + `
` + entryContent + } + return entryContent +} + func addPDFLink(entryURL, entryContent string) string { if strings.HasSuffix(entryURL, ".pdf") { return fmt.Sprintf(`PDF
%s`, entryURL, entryContent) diff --git a/reader/rewrite/rewriter.go b/reader/rewrite/rewriter.go index f894ce83..a34b0adf 100644 --- a/reader/rewrite/rewriter.go +++ b/reader/rewrite/rewriter.go @@ -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 diff --git a/reader/rewrite/rules.go b/reader/rewrite/rules.go index c5d92fa4..fb644a48 100644 --- a/reader/rewrite/rules.go +++ b/reader/rewrite/rules.go @@ -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", } diff --git a/reader/sanitizer/sanitizer.go b/reader/sanitizer/sanitizer.go index 0092bedb..18b8a84a 100644 --- a/reader/sanitizer/sanitizer.go +++ b/reader/sanitizer/sanitizer.go @@ -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",