From 38d0f14601046f38413631fe57baff0365bcc3bc Mon Sep 17 00:00:00 2001 From: Nemo2011 Date: Wed, 18 Dec 2024 22:00:18 +0800 Subject: [PATCH] feat: article -> note --- bilibili_api/article.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bilibili_api/article.py b/bilibili_api/article.py index 940a0d88..b066a5c1 100644 --- a/bilibili_api/article.py +++ b/bilibili_api/article.py @@ -26,6 +26,7 @@ from .video import get_cid_info_sync from . import dynamic +from .note import Note, NoteType API = get_api("article") @@ -177,6 +178,33 @@ async def turn_to_dynamic(self) -> "dynamic.Dynamic": credential=self.credential, ) + async def is_note(self) -> bool: + """ + 判断专栏是否为笔记 + + Returns: + bool: 是否为笔记 + """ + return (await self.get_all())["readInfo"]["category"]["id"] in [41, 42] + + async def turn_to_note(self) -> "Note": + """ + 将专栏转为笔记(需保证专栏是笔记,过程中会有核验,共产生一次请求) + + 如果希望避免核验专栏是否是笔记,可以手动转换以避免请求。 + + ``` python + n = note.Note(cvid=ar.get_cvid(), note_type=note.NoteType.PUBLIC) + ``` + + Returns: + Note: 笔记实例 + """ + raise_for_statement(await self.is_note(), "此专栏不是笔记,无法转换。") + return Note( + cvid=self.get_cvid(), note_type=NoteType.PUBLIC, credential=self.credential + ) + def get_cvid(self) -> int: """ 获取 cvid