feat: support author prefix in output filename
This commit is contained in:
parent
96f96c2295
commit
5ba771f882
14
Douyin.py
14
Douyin.py
@ -138,9 +138,19 @@ def choose_video_url(url_list: list[str]) -> str:
|
|||||||
raise ValueError("url_list 为空,无法选择视频地址。")
|
raise ValueError("url_list 为空,无法选择视频地址。")
|
||||||
|
|
||||||
|
|
||||||
def build_output_path(title: str, video_id: str, output_dir: Path = Path("video")) -> Path:
|
def build_output_path(
|
||||||
|
title: str,
|
||||||
|
video_id: str,
|
||||||
|
output_dir: Path = Path("video"),
|
||||||
|
author_name: str | None = None,
|
||||||
|
) -> Path:
|
||||||
safe_title = sanitize_filename(title, fallback="untitled")
|
safe_title = sanitize_filename(title, fallback="untitled")
|
||||||
return output_dir / f"{safe_title}-{video_id}.mp4"
|
if author_name:
|
||||||
|
safe_author = sanitize_filename(author_name, fallback="unknown")
|
||||||
|
filename = f"[{safe_author}]{safe_title}-{video_id}.mp4"
|
||||||
|
else:
|
||||||
|
filename = f"{safe_title}-{video_id}.mp4"
|
||||||
|
return output_dir / filename
|
||||||
|
|
||||||
|
|
||||||
def build_browser_address(browser_port: int | None) -> str | None:
|
def build_browser_address(browser_port: int | None) -> str | None:
|
||||||
|
|||||||
@ -82,6 +82,15 @@ class DouyinModuleTests(unittest.TestCase):
|
|||||||
output_path = module.build_output_path("测试标题", "123456")
|
output_path = module.build_output_path("测试标题", "123456")
|
||||||
self.assertEqual(output_path.as_posix(), "video/测试标题-123456.mp4")
|
self.assertEqual(output_path.as_posix(), "video/测试标题-123456.mp4")
|
||||||
|
|
||||||
|
def test_build_output_path_with_author_uses_bracket_format(self) -> None:
|
||||||
|
module = importlib.import_module("Douyin")
|
||||||
|
output_path = module.build_output_path(
|
||||||
|
title="测试标题",
|
||||||
|
video_id="123456",
|
||||||
|
author_name="测试博主"
|
||||||
|
)
|
||||||
|
self.assertEqual(output_path.as_posix(), "video/[测试博主]测试标题-123456.mp4")
|
||||||
|
|
||||||
def test_extract_aweme_payload_uses_dict_body(self) -> None:
|
def test_extract_aweme_payload_uses_dict_body(self) -> None:
|
||||||
module = importlib.import_module("Douyin")
|
module = importlib.import_module("Douyin")
|
||||||
response = FakeResponse({"aweme_list": []}, "")
|
response = FakeResponse({"aweme_list": []}, "")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user