Compare commits

...

2 Commits

Author SHA1 Message Date
blank X ad17d5a4a5
Check if extension is .htm or .html, instead of if it starts with .htm 2021-04-29 16:33:29 +07:00
blank X 1330b8c3cd
Add og:video support 2021-04-29 16:32:53 +07:00
1 changed files with 8 additions and 8 deletions

View File

@ -365,7 +365,7 @@ async def main():
url = urlunparse(urlparse(url, 'https'))
await _download_file(filename, url)
ext = await _get_file_ext(filename)
if ext.startswith('.htm'):
if ext in ('.htm', '.html'):
with open(filename) as file:
soup = BeautifulSoup(file.read())
ptitle = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:title' and tag.attrs.get('content')) or soup.find('title')
@ -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'<a href="{url}">{html.escape(ptitle)}</a>'
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: