🐛 Fix bilibili dyn

This commit is contained in:
xtaodada 2023-08-25 22:10:13 +08:00
parent 224bf15b72
commit 29a66ca0d3
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 11 additions and 13 deletions

View File

@ -421,15 +421,10 @@ async def get_dynamic_screenshot_pc(dynamic_id):
# 动态被删除或者进审核了 # 动态被删除或者进审核了
if page.url == "https://www.bilibili.com/404": if page.url == "https://www.bilibili.com/404":
return None return None
card = await page.query_selector(".card") card = await page.query_selector(".bili-dyn-item__main")
assert card assert card
clip = await card.bounding_box() clip = await card.bounding_box()
assert clip assert clip
bar = await page.query_selector(".bili-dyn-action__icon")
assert bar
bar_bound = await bar.bounding_box()
assert bar_bound
clip["height"] = bar_bound["y"] - clip["y"]
return await page.screenshot(clip=clip, full_page=True) return await page.screenshot(clip=clip, full_page=True)
except Exception: except Exception:
print(f"截取动态时发生错误:{url}") print(f"截取动态时发生错误:{url}")

View File

@ -91,7 +91,7 @@ class ImageUtil:
self.height = height self.height = height
else: else:
self.mark_image = Image.open(background).resize( self.mark_image = Image.open(background).resize(
(self.width, self.height), Image.ANTIALIAS (self.width, self.height), Image.Resampling.LANCZOS
) )
if is_alpha: if is_alpha:
array = self.mark_image.load() array = self.mark_image.load()

View File

@ -15,7 +15,7 @@ def process_pic(content) -> BytesIO:
draw = ImageDraw.Draw(bk_img) draw = ImageDraw.Draw(bk_img)
current_h, pad = 300, 10 current_h, pad = 300, 10
for line in para: for line in para:
w, h = draw.textsize(line, font=font) _, _, w, h = font.getbbox(line)
draw.text(((MAX_W - w) / 2, current_h), line, font=font) draw.text(((MAX_W - w) / 2, current_h), line, font=font)
current_h += h + pad current_h += h + pad
draw.text((320, 400), "——鲁迅", font=font2, fill=(255, 255, 255)) draw.text((320, 400), "——鲁迅", font=font2, fill=(255, 255, 255))

View File

@ -1,3 +1,4 @@
import aiofiles
from io import BytesIO from io import BytesIO
from os import sep, makedirs from os import sep, makedirs
from os.path import exists from os.path import exists
@ -27,8 +28,8 @@ async def friend_say(client: Client, message: Message):
user_name = message.reply_to_message.from_user.first_name user_name = message.reply_to_message.from_user.first_name
# Create image # Create image
if avatar: if avatar:
with open(avatar, "rb") as fh: async with aiofiles.open(avatar, "rb") as fh:
buf = BytesIO(fh.read()) buf = BytesIO(await fh.read())
ava = ImageUtil(100, 100, background=buf) ava = ImageUtil(100, 100, background=buf)
else: else:
ava = ImageUtil(100, 100, color=(0, 0, 0)) ava = ImageUtil(100, 100, color=(0, 0, 0))

View File

@ -77,6 +77,8 @@ async def ip_command(_: Client, message: Message):
if rep_text == "" and text == "": if rep_text == "" and text == "":
await msg.edit("没有找到要查询的 ip/域名 ...") await msg.edit("没有找到要查询的 ip/域名 ...")
elif rep_text != "" and text != "": elif rep_text != "" and text != "":
await msg.edit(f"{rep_text}\n================\n{text}") await msg.edit(
f"{rep_text}\n================\n{text}", disable_web_page_preview=True
)
else: else:
await msg.edit(f"{rep_text}{text}") await msg.edit(f"{rep_text}{text}", disable_web_page_preview=True)

View File

@ -84,7 +84,7 @@ async def process_user(message: Message, username: str):
) )
@Client.on_message(filters.incoming & filters.text & filters.regex(r"twitter.com/")) # @Client.on_message(filters.incoming & filters.text & filters.regex(r"twitter.com/"))
async def twitter_share(_: Client, message: Message): async def twitter_share(_: Client, message: Message):
if not message.text: if not message.text:
return return