diff --git a/Douyin.py b/Douyin.py index dd94670..93251d5 100644 --- a/Douyin.py +++ b/Douyin.py @@ -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, } ) diff --git a/test_douyin.py b/test_douyin.py index e1c5763..fc11d99 100644 --- a/test_douyin.py +++ b/test_douyin.py @@ -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(