Skip to content

Commit

Permalink
chore: article & note
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Jan 30, 2024
1 parent 700224e commit 96a4448
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
11 changes: 5 additions & 6 deletions bilibili_api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
from yarl import URL
from bs4 import BeautifulSoup, element

from bilibili_api.utils.initial_state import get_initial_state
from .utils.initial_state import get_initial_state

from .note import Note, NoteType
from .utils.utils import get_api
from .utils.credential import Credential
from .utils.network import Api, get_session
from .exceptions.NetworkException import ApiException, NetworkException
from .video import get_cid_info_sync
from . import note

API = get_api("article")

Expand Down Expand Up @@ -204,10 +204,10 @@ def is_note(self) -> bool:
"""
return self.__type == ArticleType.NOTE

def turn_to_note(self) -> Note:
def turn_to_note(self) -> "note.Note":
assert self.__type == ArticleType.NOTE
return Note(
cvid=self.__cvid, note_type=NoteType.PUBLIC, credential=self.credential
return note.Note(
cvid=self.__cvid, note_type=note.NoteType.PUBLIC, credential=self.credential
)

def markdown(self) -> str:
Expand Down Expand Up @@ -883,7 +883,6 @@ def __init__(self, text: str):

def markdown(self):
txt = self.text
txt = txt.lstrip()
special_chars = ["\\", "*", "$", "<", ">", "|"]
for c in special_chars:
txt = txt.replace(c, "\\" + c)
Expand Down
10 changes: 10 additions & 0 deletions bilibili_api/data/api/dynamic.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@
},
"comment": "动态详细信息"
},
"detail_new": {
"url": "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail",
"method": "GET",
"verify": false,
"params": {
"timezone_offset": "int: 时区偏移量",
"id": "int: 动态 ID"
},
"comment": "动态详细信息"
},
"dynamic_page_UPs_info": {
"url": "https://api.bilibili.com/x/polymer/web-dynamic/v1/portal",
"method": "GET",
Expand Down
11 changes: 11 additions & 0 deletions bilibili_api/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ def get_dynamic_id(self) -> int:

async def get_info(self, features: str = "itemOpusStyle") -> dict:
"""
(不建议使用此旧版 API,请转到新版 get_info_opus)
获取动态信息
Args:
Expand All @@ -762,6 +764,15 @@ async def get_info(self, features: str = "itemOpusStyle") -> dict:
)
return data

async def get_info_opus(self) -> dict:
"""
新版获取动态信息
Returns:
dict: 调用 API 返回的结果
"""
pass

async def get_reposts(self, offset: str = "0") -> dict:
"""
获取动态转发列表
Expand Down
11 changes: 9 additions & 2 deletions bilibili_api/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import httpx
from yarl import URL

from bilibili_api.utils.initial_state import get_initial_state
from .utils.initial_state import get_initial_state

from .utils.utils import get_api
from .utils.picture import Picture
from .utils.credential import Credential
from .exceptions import ApiException, ArgsException
from .utils.network import Api, get_session
from .video import get_cid_info_sync
from . import article

API = get_api("note")
API_ARTICLE = get_api("article")
Expand Down Expand Up @@ -98,6 +99,10 @@ def get_aid(self) -> int:
def get_note_id(self) -> int:
return self.__note_id

def turn_to_article(self) -> "article.Article":
assert self.__type == NoteType.PUBLIC
return article.Article(cvid=self.get_cvid(), credential=self.credential)

async def get_info(self) -> dict:
"""
获取笔记信息
Expand Down Expand Up @@ -277,7 +282,9 @@ def parse_note(data: List[dict]):
if not isinstance(field["insert"], str):
if "tag" in field["insert"].keys():
node = VideoCardNode()
node.aid = get_cid_info_sync(field["insert"]["tag"]["cid"])["cid"]
node.aid = get_cid_info_sync(field["insert"]["tag"]["cid"])[
"cid"
]
self.__children.append(node)
elif "imageUpload" in field["insert"].keys():
node = ImageNode()
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ from bilibili_api import dynamic
| -------- | ------------- | ------------------- |
| features | str, optional | 默认 itemOpusStyle. |

**(不建议使用此旧版 API,请转到新版 get_info_opus)**

获取动态信息

**Returns:** dict: 调用 API 返回的结果
Expand Down
10 changes: 9 additions & 1 deletion docs/modules/note.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ from bilibili_api import note

笔记类型枚举

## class Video
## class Note

笔记类,各种对笔记的操作都在里面

Expand Down Expand Up @@ -96,6 +96,14 @@ from bilibili_api import note

---

#### def turn_to_article()

将笔记类转为专栏类。需要保证笔记是公开笔记。

**Returns:** Note: 专栏类

---

#### async def get_info()

获取笔记信息。
Expand Down

0 comments on commit 96a4448

Please sign in to comment.