From 1330b8c3cdc2fbe3e55b6be6a61a43e156619235 Mon Sep 17 00:00:00 2001 From: blank X Date: Thu, 29 Apr 2021 16:32:53 +0700 Subject: [PATCH] Add og:video support --- redditbot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/redditbot.py b/redditbot.py index be43b5e..cb5fac4 100644 --- a/redditbot.py +++ b/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')) if pdesc: 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')) - if pimg: - pimg = pimg.attrs.get('content', '').strip() + 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 pmedia: + pmedia = pmedia.attrs.get('content', '').strip() tat = f'{text}\n\nURL: ' if ptitle: tat += f'{html.escape(ptitle)}' else: tat += url files = [] - if pimg: - pimg = urlunparse(urlparse(pimg, 'https')) - await _download_file(filename, pimg) + if pmedia: + pmedia = urlunparse(urlparse(pmedia, 'https')) + await _download_file(filename, pmedia) files.append(filename) if pdesc: - caplength = 1023 if pimg else 4095 + caplength = 1023 if pmedia else 4095 caplength -= len(client.parse_mode.parse(tat)[0]) captext = pdesc[:caplength] if len(captext) >= caplength: