mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-26 04:51:06 -05:00
add oEmbed discovery
This commit is contained in:
parent
e7f79b5098
commit
eadac11ab6
@ -296,17 +296,30 @@ class Web(callbacks.PluginRegexp):
|
|||||||
regex = re.escape(scheme).replace(r'\*', '.*')
|
regex = re.escape(scheme).replace(r'\*', '.*')
|
||||||
if re.match(regex, url):
|
if re.match(regex, url):
|
||||||
return endpoint
|
return endpoint
|
||||||
|
try:
|
||||||
|
timeout = self.registryValue('timeout')
|
||||||
|
response = utils.web.getUrl(url, timeout=timeout)
|
||||||
|
text = response.decode('utf8', errors='replace')
|
||||||
|
match = re.search(
|
||||||
|
r'<link[^>]+?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
|
return None
|
||||||
|
|
||||||
def getOEmbedTitle(self, url):
|
def getOEmbedTitle(self, url):
|
||||||
"""
|
"""
|
||||||
Retrieves the oEmbed title using the providers JSON.
|
Retrieves the oEmbed title.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
oembed_endpoint = self._getOEmbedEndpoint(url)
|
oembed_endpoint = self._getOEmbedEndpoint(url)
|
||||||
if not oembed_endpoint:
|
if not oembed_endpoint:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
oembed_url = f"{oembed_endpoint}?format=json&url={url}"
|
oembed_url = f"{oembed_endpoint}?format=json&url={url}"
|
||||||
response = utils.web.getUrl(oembed_url)
|
response = utils.web.getUrl(oembed_url)
|
||||||
oembed_data = json.loads(response)
|
oembed_data = json.loads(response)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user