Skip to content

Commit

Permalink
🔥 Remove comments API for Bilibili
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Apr 23, 2024
1 parent 4a53355 commit 5195fbe
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 131 deletions.
9 changes: 1 addition & 8 deletions hibiapi/api/bilibili/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# flake8:noqa:F401
from .base import (
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
TimelineType,
VideoFormatType,
VideoQualityType,
)
from .base import BaseBilibiliEndpoint, TimelineType, VideoFormatType, VideoQualityType
from .v2 import BilibiliEndpointV2, SearchType
from .v3 import BilibiliEndpointV3
52 changes: 0 additions & 52 deletions hibiapi/api/bilibili/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,6 @@ class TimelineType(str, Enum):
"""番剧"""


@enum_auto_doc
class CommentSortType(IntEnum):
"""评论排序类型"""

LIKES = 2
"""按点赞"""
HOT = 1
"""按热评"""
TIME = 0
"""按时间"""


@enum_auto_doc
class CommentType(IntEnum):
"""评论来源类型"""

VIDEO = 1
"""视频"""
ARTICLE = 12
"""文章"""
DYNAMIC_PICTURE = 11
"""含图片的动态"""
DYNAMIC_TEXT = 17
"""不含图片的动态"""
AUDIO = 14
"""音乐"""
AUDIO_LIST = 19
"""歌单"""


@enum_auto_doc
class VideoQualityType(IntEnum):
"""视频质量类型"""
Expand Down Expand Up @@ -283,28 +253,6 @@ async def season_recommend(self, *, season_id: int):
},
)

async def comments(
self,
*,
type: CommentType,
oid: int,
sort: CommentSortType = CommentSortType.TIME,
page: int = 1,
pagesize: int = 20,
):
return await self.request(
"x/v2/reply",
"api",
sign=False,
params={
"type": type,
"oid": oid,
"sort": sort,
"pn": page,
"ps": pagesize,
},
)

async def timeline(self, *, type: TimelineType = TimelineType.GLOBAL):
return await self.request(
"web_api/timeline_{type}",
Expand Down
29 changes: 0 additions & 29 deletions hibiapi/api/bilibili/api/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from hibiapi.api.bilibili.api.base import (
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
TimelineType,
VideoFormatType,
VideoQualityType,
Expand Down Expand Up @@ -78,33 +76,6 @@ async def source(self, *, episode_id: int):
async def seasonrecommend(self, *, season_id: int): # NOTE: not same with origin
return await self.base.season_recommend(season_id=season_id)

@process_keyerror
async def comments(
self,
*,
aid: Optional[int] = None,
season_id: Optional[int] = None,
index: Optional[int] = None,
sort: CommentSortType = CommentSortType.TIME,
page: int = 1,
pagesize: int = 20,
): # NOTE: not same with origin
if season_id is not None:
assert index is not None, "parameter 'index' is required"
season_info = await self.base.season_info(season_id=season_id)
oid = season_info["result"]["episodes"][index - 1]["av_id"]
elif aid is not None:
oid = aid
else:
raise ClientSideException
return await self.base.comments(
oid=oid,
sort=sort,
type=CommentType.VIDEO,
page=page,
pagesize=pagesize,
)

async def search(
self,
*,
Expand Down
19 changes: 0 additions & 19 deletions hibiapi/api/bilibili/api/v3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from hibiapi.api.bilibili.api.base import (
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
TimelineType,
VideoFormatType,
VideoQualityType,
Expand Down Expand Up @@ -79,20 +77,3 @@ async def search_recommend(self, *, limit: int = 50):

async def search_suggestion(self, *, keyword: str):
return await self.base.search_suggest(keyword=keyword)

async def comments(
self,
*,
id: int,
type: CommentType = CommentType.VIDEO,
sort: CommentSortType = CommentSortType.TIME,
page: int = 1,
size: int = 20,
):
return await self.base.comments(
oid=id,
type=type,
sort=sort,
page=page,
pagesize=size,
)
17 changes: 0 additions & 17 deletions test/test_bilibili_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ def test_seasonrecommend(client: TestClient):
assert response.json()["code"] == 0


def test_comments(client: TestClient):
response = client.get("comments", params={"aid": 810872})
assert response.status_code == 200
assert response.json()["code"] == 0


def test_season_comments(client: TestClient):
response = client.get("comments", params={"season_id": 425, "index": 1})
print(response.text)
if response.status_code == 200:
assert response.json()["code"] == 0
elif response.status_code == 400:
pytest.skip("Your region does not support getting comments from bangumi")
else:
raise AssertionError(f"{response.status_code=} is not expected")


def test_search(client: TestClient):
response = client.get("search", params={"keyword": "railgun"})
assert response.status_code == 200
Expand Down
6 changes: 0 additions & 6 deletions test/test_bilibili_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,3 @@ def test_search_suggestion(client: TestClient):
response = client.get("search_suggestion", params={"keyword": "paperclip"})
assert response.status_code == 200
assert response.json()["code"] == 0


def test_comments(client: TestClient):
response = client.get("comments", params={"id": 810872})
assert response.status_code == 200
assert response.json()["code"] == 0

0 comments on commit 5195fbe

Please sign in to comment.