diff --git a/plugins/Web/config.py b/plugins/Web/config.py index faacfa8d3..f5610300c 100644 --- a/plugins/Web/config.py +++ b/plugins/Web/config.py @@ -95,4 +95,12 @@ conf.registerGlobalValue(Web.fetch, 'timeout', seconds the bot will wait for the site to respond, when using the 'fetch' command in this plugin. If 0, will use socket.defaulttimeout""")) +conf.registerGlobalValue(Web, 'useOembedRegistry', + registry.Boolean(False, _("""Determines whether the bot will use the + oembed.com providers registry."""))) + +conf.registerGlobalValue(Web, 'useOembedDiscovery', + registry.Boolean(False, _("""Determines whether the bot will use HTML + discovery to find oEmbed endpoints."""))) + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index c6ab208c4..a4b6bc9b0 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -287,29 +287,31 @@ class Web(callbacks.PluginRegexp): First tries the providers registry if enabled, then falls back to HTML discovery if needed and enabled. """ - providers = self._loadOEmbedProviders() - for provider in providers: - for pattern in provider.get('endpoints', []): - schemes = pattern.get('schemes', []) - endpoint = pattern.get('url', '') - for scheme in schemes: - regex = re.escape(scheme).replace(r'\*', '.*') - if re.match(regex, url): - return endpoint - try: - timeout = self.registryValue('timeout') - response = utils.web.getUrl(url, timeout=timeout) - text = response.decode('utf8', errors='replace') - match = re.search( - r']+?type="application/json\+oembed"[^>]+?href="([^"]+)"', - text, - re.IGNORECASE) - if match: - endpoint = match.group(1) - endpoint = endpoint.split('?')[0] - return endpoint - except Exception as e: - self.log.debug(f"Failed to discover oEmbed endpoint in HTML: {e}") + if self.registryValue('useOembedRegistry'): + providers = self._loadOEmbedProviders() + for provider in providers: + for pattern in provider.get('endpoints', []): + schemes = pattern.get('schemes', []) + endpoint = pattern.get('url', '') + for scheme in schemes: + regex = re.escape(scheme).replace(r'\*', '.*') + if re.match(regex, url): + return endpoint + if self.registryValue('useOembedDiscovery'): + try: + timeout = self.registryValue('timeout') + response = utils.web.getUrl(url, timeout=timeout) + text = response.decode('utf8', errors='replace') + match = re.search( + r']+?type="application/json\+oembed"[^>]+?href="([^"]+)"', + text, + re.IGNORECASE) + if match: + endpoint = match.group(1) + endpoint = endpoint.split('?')[0] + return endpoint + except Exception as e: + self.log.debug(f"Failed to discover oEmbed endpoint in HTML: {e}") return None def getOEmbedTitle(self, url):