fix: hoyolab video post
All checks were successful
Docker Build / docker build and publish (push) Successful in 1m27s

This commit is contained in:
xtaodada 2024-07-16 20:46:16 +08:00
parent 8354f4bafb
commit 62fa646257
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 20 additions and 6 deletions

View File

@ -95,6 +95,12 @@ class HoYoPostVideo(BaseModel):
def is_youtube(self) -> bool: def is_youtube(self) -> bool:
return "www.youtube.com" in self.url return "www.youtube.com" in self.url
@property
def html(self) -> str:
if self.is_youtube:
return f'<iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="true" border="0" frameborder="0" framespacing="0" scrolling="no" src="{self.url}"></iframe>\n'
return f'<video controls src="{self.url}"></video>\n'
class HoYoPostMultiLang(BaseModel): class HoYoPostMultiLang(BaseModel):
lang_subject: dict lang_subject: dict

View File

@ -35,9 +35,9 @@
{ {
"id": "4", "id": "4",
"icon": "https://hyl-static-res-prod.hoyolab.com/communityweb/business/nxx_hoyoverse.png", "icon": "https://hyl-static-res-prod.hoyolab.com/communityweb/business/nxx_hoyoverse.png",
"bg": "https://upload-os-bbs.hoyolab.com/upload/2023/10/24/d97b3eb5763dba18bc137929ce53ba24_8118580296436267822.png", "bg": "https://upload-os-bbs.hoyolab.com/upload/2024/07/12/6884e4a2d1200dac51ac55391b377a74_8800404318031699849.png?x-oss-process=image/auto-orient,0/interlace,1/format,webp/quality,q_70",
"name": "未定事件簿", "name": "未定事件簿",
"bg_color": "#2E3857", "bg_color": "#1D1D1F",
"focus_channel_id": "0" "focus_channel_id": "0"
}, },
{ {

View File

@ -42,8 +42,8 @@ async def process_article_video(
json_data = json.loads(post_info.content) json_data = json.loads(post_info.content)
description = json_data.get("describe", "") description = json_data.get("describe", "")
article = "" article = ""
if post_info.video and post_info.video.is_youtube: if post_info.video:
article += f'<iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="true" border="0" frameborder="0" framespacing="0" scrolling="no" src="{post_info.video.url}"></iframe>\n' article += post_info.video.html
if description: if description:
article += f"<p>{description}</p>\n" article += f"<p>{description}</p>\n"
return template.render( return template.render(

View File

@ -42,7 +42,7 @@ class TestHoyolabArticle:
assert "The people of Liyue love drinking tea." in content assert "The people of Liyue love drinking tea." in content
@staticmethod @staticmethod
async def test_get_hoyo_video_article(): async def test_get_hoyo_youtube_video_article():
content = await process_article(21124034, "zh-cn") content = await process_article(21124034, "zh-cn")
assert content is not None assert content is not None
assert "《原神》「流光拾遗之旅」——仙闻篇·龙泉青瓷" in content assert "《原神》「流光拾遗之旅」——仙闻篇·龙泉青瓷" in content
@ -50,9 +50,17 @@ class TestHoyolabArticle:
assert "璃月人爱喝茶,用青色茶盏盛一碗茶汤,茶香似乎都变得更悠长。" in content assert "璃月人爱喝茶,用青色茶盏盛一碗茶汤,茶香似乎都变得更悠长。" in content
@staticmethod @staticmethod
async def test_get_hoyo_big_video_article(): async def test_get_hoyo_big_youtube_video_article():
content = await process_article(17958970, "zh-cn") content = await process_article(17958970, "zh-cn")
assert content is not None assert content is not None
assert "Spiral-Abyss-3.6 甘雨暴风雪 & 融甘视频 面板置放2和3楼" in content assert "Spiral-Abyss-3.6 甘雨暴风雪 & 融甘视频 面板置放2和3楼" in content
assert "0jVRnQHwQ_g" in content assert "0jVRnQHwQ_g" in content
assert "这次的都是用加HP%加充能和E技能伤害没和伤害直接挂钩的buff" in content assert "这次的都是用加HP%加充能和E技能伤害没和伤害直接挂钩的buff" in content
@staticmethod
async def test_get_hoyo_big_video_article():
content = await process_article(31107135, "zh-cn")
assert content is not None
assert "Voice Actor Reveal: Belle" in content
assert "141812841564491837440_1080p" in content
assert "Good luck, guys. Let's get started." in content