Skip to content

Commit

Permalink
feat: article -> note
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Dec 18, 2024
1 parent f1442aa commit 38d0f14
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bilibili_api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .video import get_cid_info_sync

from . import dynamic
from .note import Note, NoteType

API = get_api("article")

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 38d0f14

Please sign in to comment.