Skip to content

Commit

Permalink
Merge pull request #58 from Nubuki-all/yt_thumbnail_fix
Browse files Browse the repository at this point in the history
Fixes thumbnail generation for YouTube links
  • Loading branch information
krypton-byte authored Dec 22, 2024
2 parents 8fc19dd + 01126b0 commit d0e153e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions neonize/aioze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
from .events import Event
from ..utils.log import log
from concurrent.futures import ThreadPoolExecutor
from linkpreview import link_preview as fallback_link_preview

loop = get_event_loop()

Expand Down Expand Up @@ -471,6 +472,8 @@ async def _generate_link_preview(self, text: str) -> ExtendedTextMessage | None:
valid_links = list(filter(validate_link, links))
if valid_links:
preview = await link_preview(valid_links[0])
if not preview:
preview = fallback_link_preview(valid_links[0])
preview_type = (
ExtendedTextMessage.PreviewType.VIDEO
if re.match(youtube_url_pattern, valid_links[0])
Expand Down
5 changes: 3 additions & 2 deletions neonize/aioze/preview/compose.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Literal, Optional, TypeVar, overload
from httpx import URL
from httpx import URL, HTTPStatusError
from linkpreview import Link, LinkPreview
from linkpreview.exceptions import InvalidMimeTypeError
from .grabber import LinkGrabber
Expand All @@ -19,6 +19,7 @@ async def link_preview(
content, url = await grabber.get_content(url)
except InvalidMimeTypeError:
content = ""

except HTTPStatusError:
return
link = Link(url, content)
return LinkPreview(link, parser=parser)

0 comments on commit d0e153e

Please sign in to comment.