From 8329e9b46cba8534d44960d2fc8a6d0e199c0299 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Thu, 6 Jan 2022 05:43:03 +0100 Subject: [PATCH] Make Invidious instance configurable --- config/options.go | 9 +++++++++ config/parser.go | 2 ++ miniflux.1 | 7 ++++++- reader/rewrite/rewrite_functions.go | 4 +++- reader/rewrite/rules.go | 1 - reader/sanitizer/sanitizer.go | 7 ++++++- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/config/options.go b/config/options.go index 6b319518..bd2bd6b5 100644 --- a/config/options.go +++ b/config/options.go @@ -68,6 +68,7 @@ const ( defaultMetricsRefreshInterval = 60 defaultMetricsAllowedNetworks = "127.0.0.1/8" defaultWatchdog = true + defaultInvidiousInstance = "yewtu.be" ) var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)" @@ -135,6 +136,7 @@ type Options struct { metricsRefreshInterval int metricsAllowedNetworks []string watchdog bool + invidiousInstance string } // NewOptions returns Options with default values. @@ -193,6 +195,7 @@ func NewOptions() *Options { metricsRefreshInterval: defaultMetricsRefreshInterval, metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks}, watchdog: defaultWatchdog, + invidiousInstance: defaultInvidiousInstance, } } @@ -482,6 +485,11 @@ func (o *Options) HasWatchdog() bool { return o.watchdog } +// InvidiousInstance returns the invidious instance used by miniflux +func (o *Options) InvidiousInstance() string { + return o.invidiousInstance +} + // SortedOptions returns options as a list of key value pairs, sorted by keys. func (o *Options) SortedOptions(redactSecret bool) []*Option { var keyValues = map[string]interface{}{ @@ -516,6 +524,7 @@ func (o *Options) SortedOptions(redactSecret bool) []*Option { "HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent, "HTTP_SERVICE": o.httpService, "KEY_FILE": o.certKeyFile, + "INVIDIOUS_INSTANCE": o.invidiousInstance, "LISTEN_ADDR": o.listenAddr, "LOG_DATE_TIME": o.logDateTime, "MAINTENANCE_MESSAGE": o.maintenanceMessage, diff --git a/config/parser.go b/config/parser.go index ea77b6a6..2d4f5727 100644 --- a/config/parser.go +++ b/config/parser.go @@ -195,6 +195,8 @@ func (p *Parser) parseLines(lines []string) (err error) { p.opts.fetchYouTubeWatchTime = parseBool(value, defaultFetchYouTubeWatchTime) case "WATCHDOG": p.opts.watchdog = parseBool(value, defaultWatchdog) + case "INVIDIOUS_INSTANCE": + p.opts.invidiousInstance = parseString(value, defaultInvidiousInstance) } } diff --git a/miniflux.1 b/miniflux.1 index eb7db1c2..f938a06e 100644 --- a/miniflux.1 +++ b/miniflux.1 @@ -1,5 +1,5 @@ .\" Manpage for miniflux. -.TH "MINIFLUX" "1" "May 23, 2021" "\ \&" "\ \&" +.TH "MINIFLUX" "1" "January 5, 2022" "\ \&" "\ \&" .SH NAME miniflux \- Minimalist and opinionated feed reader @@ -416,6 +416,11 @@ Default is "Miniflux is currently under maintenance"\&. Enable or disable Systemd watchdog\&. .br Enabled by default\&. +.TP +.B INVIDIOUS_INSTANCE +Set a custom invidious instance to use\&. +.br +Default is yewtu.be\&. .SH AUTHORS .P diff --git a/reader/rewrite/rewrite_functions.go b/reader/rewrite/rewrite_functions.go index 4ea9ce4e..c5f930fe 100644 --- a/reader/rewrite/rewrite_functions.go +++ b/reader/rewrite/rewrite_functions.go @@ -11,6 +11,8 @@ import ( "regexp" "strings" + "miniflux.app/config" + "github.com/PuerkitoBio/goquery" ) @@ -214,7 +216,7 @@ func addYoutubeVideoUsingInvidiousPlayer(entryURL, entryContent string) string { matches := youtubeRegex.FindStringSubmatch(entryURL) if len(matches) == 2 { - video := `` + video := `` return video + `
` + entryContent } return entryContent diff --git a/reader/rewrite/rules.go b/reader/rewrite/rules.go index 29fce0db..f2c6a5a1 100644 --- a/reader/rewrite/rules.go +++ b/reader/rewrite/rules.go @@ -16,7 +16,6 @@ var predefinedRules = map[string]string{ "framatube.org": "nl2br,convert_text_link", "happletea.com": "add_image_title", "imogenquest.net": "add_image_title", - "invidio.us": "add_invidious_video", "lukesurl.com": "add_image_title", "medium.com": "fix_medium_images", "mercworks.net": "add_image_title", diff --git a/reader/sanitizer/sanitizer.go b/reader/sanitizer/sanitizer.go index 89df6851..0af6c197 100644 --- a/reader/sanitizer/sanitizer.go +++ b/reader/sanitizer/sanitizer.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" + "miniflux.app/config" "miniflux.app/url" "golang.org/x/net/html" @@ -308,7 +309,6 @@ func isBlockedResource(src string) bool { func isValidIframeSource(baseURL, src string) bool { whitelist := []string{ - "https://invidio.us", "//www.youtube.com", "http://www.youtube.com", "https://www.youtube.com", @@ -334,6 +334,11 @@ func isValidIframeSource(baseURL, src string) bool { return true } + // allow iframe from custom invidious instance + if config.Opts != nil && config.Opts.InvidiousInstance() == url.Domain(src) { + return true + } + for _, prefix := range whitelist { if strings.HasPrefix(src, prefix) { return true