feat: extract author info from aweme items
This commit is contained in:
parent
c56c54d35d
commit
96f96c2295
@ -199,11 +199,18 @@ def parse_aweme_items(body: Any) -> list[dict[str, str]]:
|
||||
continue
|
||||
|
||||
title = str(aweme.get("desc") or "").strip() or "untitled"
|
||||
|
||||
author = aweme.get("author") or {}
|
||||
author_name = str(author.get("nickname") or "").strip() or "unknown"
|
||||
author_id = str(author.get("uid") or "").strip() or "unknown"
|
||||
|
||||
items.append(
|
||||
{
|
||||
"title": title,
|
||||
"video_id": video_id,
|
||||
"video_url": choose_video_url([str(url) for url in url_list]),
|
||||
"author_name": author_name,
|
||||
"author_id": author_id,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -254,6 +254,30 @@ class DouyinModuleTests(unittest.TestCase):
|
||||
browser_port=None,
|
||||
)
|
||||
|
||||
def test_parse_aweme_items_extracts_author_info(self) -> None:
|
||||
module = importlib.import_module("Douyin")
|
||||
payload = {
|
||||
"aweme_list": [
|
||||
{
|
||||
"aweme_id": "7619989983668240802",
|
||||
"desc": "测试视频",
|
||||
"author": {
|
||||
"nickname": "测试博主",
|
||||
"uid": "123456789"
|
||||
},
|
||||
"video": {
|
||||
"play_addr": {
|
||||
"url_list": ["https://v26-web.douyinvod.com/example/video.mp4"]
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
items = module.parse_aweme_items(payload)
|
||||
self.assertEqual(len(items), 1)
|
||||
self.assertEqual(items[0]["author_name"], "测试博主")
|
||||
self.assertEqual(items[0]["author_id"], "123456789")
|
||||
|
||||
def test_build_video_page_url_uses_aweme_id(self) -> None:
|
||||
module = importlib.import_module("Douyin")
|
||||
self.assertEqual(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user