From eadac11ab6cdc4db95983d6b34db51c8d6f9ba2e Mon Sep 17 00:00:00 2001 From: lodriguez Date: Sat, 1 Feb 2025 15:12:54 +0100 Subject: [PATCH] add oEmbed discovery --- plugins/Web/plugin.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index d46cf1165..c6ab208c4 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -296,17 +296,30 @@ class Web(callbacks.PluginRegexp): 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}") return None def getOEmbedTitle(self, url): """ - Retrieves the oEmbed title using the providers JSON. + Retrieves the oEmbed title. """ try: oembed_endpoint = self._getOEmbedEndpoint(url) if not oembed_endpoint: return None - oembed_url = f"{oembed_endpoint}?format=json&url={url}" response = utils.web.getUrl(oembed_url) oembed_data = json.loads(response)