Add og:video support
This commit is contained in:
parent
3371eba487
commit
1330b8c3cd
14
redditbot.py
14
redditbot.py
|
@ -374,21 +374,21 @@ async def main():
|
||||||
pdesc = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:description' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('name') == 'description' and tag.attrs.get('content'))
|
pdesc = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:description' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('name') == 'description' and tag.attrs.get('content'))
|
||||||
if pdesc:
|
if pdesc:
|
||||||
pdesc = pdesc.attrs.get('content', pdesc.text).strip()
|
pdesc = pdesc.attrs.get('content', pdesc.text).strip()
|
||||||
pimg = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:image' and tag.attrs.get('content'))
|
pmedia = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:video' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:image' and tag.attrs.get('content'))
|
||||||
if pimg:
|
if pmedia:
|
||||||
pimg = pimg.attrs.get('content', '').strip()
|
pmedia = pmedia.attrs.get('content', '').strip()
|
||||||
tat = f'{text}\n\nURL: '
|
tat = f'{text}\n\nURL: '
|
||||||
if ptitle:
|
if ptitle:
|
||||||
tat += f'<a href="{url}">{html.escape(ptitle)}</a>'
|
tat += f'<a href="{url}">{html.escape(ptitle)}</a>'
|
||||||
else:
|
else:
|
||||||
tat += url
|
tat += url
|
||||||
files = []
|
files = []
|
||||||
if pimg:
|
if pmedia:
|
||||||
pimg = urlunparse(urlparse(pimg, 'https'))
|
pmedia = urlunparse(urlparse(pmedia, 'https'))
|
||||||
await _download_file(filename, pimg)
|
await _download_file(filename, pmedia)
|
||||||
files.append(filename)
|
files.append(filename)
|
||||||
if pdesc:
|
if pdesc:
|
||||||
caplength = 1023 if pimg else 4095
|
caplength = 1023 if pmedia else 4095
|
||||||
caplength -= len(client.parse_mode.parse(tat)[0])
|
caplength -= len(client.parse_mode.parse(tat)[0])
|
||||||
captext = pdesc[:caplength]
|
captext = pdesc[:caplength]
|
||||||
if len(captext) >= caplength:
|
if len(captext) >= caplength:
|
||||||
|
|
Loading…
Reference in New Issue