Browse Source

Make Invidious instance configurable

Romain de Laage 4 years ago
parent
commit
8329e9b46c

+ 9 - 0
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,

+ 2 - 0
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)
 		}
 	}
 

+ 6 - 1
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

+ 3 - 1
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 := `<iframe width="650" height="350" frameborder="0" src="https://invidio.us/embed/` + matches[1] + `" allowfullscreen></iframe>`
+		video := `<iframe width="650" height="350" frameborder="0" src="https://` + config.Opts.InvidiousInstance() + `/embed/` + matches[1] + `" allowfullscreen></iframe>`
 		return video + `<br>` + entryContent
 	}
 	return entryContent

+ 0 - 1
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",

+ 6 - 1
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