Skip to content

Commit

Permalink
🔥 Remove outdated Bilibili API endpoints and their tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Apr 20, 2024
1 parent 4c90d33 commit c58a626
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 234 deletions.
3 changes: 0 additions & 3 deletions hibiapi/api/bilibili/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
RankBangumiType,
RankContentType,
RankDurationType,
TimelineType,
VideoFormatType,
VideoQualityType,
Expand Down
114 changes: 4 additions & 110 deletions hibiapi/api/bilibili/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,64 +76,6 @@ class VideoFormatType(IntEnum):
DASH = 16


@enum_auto_doc
class RankBangumiType(str, Enum):
"""番剧排行榜类型"""

CN = "cn"
"""国产动画"""
GLOBAL = "global"
"""番剧"""


@enum_auto_doc
class RankContentType(IntEnum):
"""视频排行榜内容类型"""

FULL_SITE = 0
"""全站"""
DOUGA = 1
"""动画"""
GUOCHUANG = 168
"""国创相关"""
MUSIC = 3
"""音乐"""
DANCE = 129
"""舞蹈"""
GAME = 4
"""游戏"""
TECHNOLOGY = 36
"""科技"""
LIFE = 160
"""生活"""
KICHIKU = 119
"""鬼畜"""
FASHION = 155
"""时尚"""
INFORMATION = 165
"""广告"""
ENT = 5
"""娱乐"""
MOVIE = 23
"""电影"""
TV = 11
"""电视剧"""


@enum_auto_doc
class RankDurationType(IntEnum):
"""排行榜时间段类型"""

DAILY = 1
"""日排行"""
THREE_DAY = 3
"""三日排行"""
WEEKLY = 7
"""周排行"""
MONTHLY = 30
"""月排行"""


class BaseBilibiliEndpoint(BaseEndpoint):
def _sign(self, base: str, endpoint: str, params: Dict[str, Any]) -> URL:
params.update(
Expand Down Expand Up @@ -165,8 +107,7 @@ async def request(
*,
sign: bool = True,
params: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
...
) -> Dict[str, Any]: ...

@overload
async def request(
Expand All @@ -176,8 +117,7 @@ async def request(
*,
sign: bool = True,
params: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
...
) -> Dict[str, Any]: ...

@dont_route
@catch_network_error
Expand Down Expand Up @@ -317,8 +257,8 @@ async def event_list(

async def season_info(self, *, season_id: int):
return await self.request(
"api/season_v5",
"bgm",
"pgc/view/web/season",
"api",
params={
"season_id": season_id,
},
Expand Down Expand Up @@ -365,49 +305,6 @@ async def comments(
},
)

async def rank_list_bangumi(
self,
*,
site: RankBangumiType = RankBangumiType.GLOBAL,
duration: RankDurationType = RankDurationType.THREE_DAY,
):
return await self.request(
"jsonp/season_rank_list/{site}/{duration}.ver",
"bgm",
sign=False,
params={
"duration": duration,
"site": site,
},
)

async def rank_list(
self,
content: RankContentType = RankContentType.FULL_SITE,
duration: RankDurationType = RankDurationType.THREE_DAY,
new: bool = True,
):
return await self.request(
"index/rank/all-{new_post}{duration}-{content}.json",
"main",
sign=False,
params={
"new_post": "" if new else "0",
"duration": duration,
"content": content,
},
)

async def type_dynamic(self):
return await self.request(
"typedynamic/index",
"api",
sign=False,
params={
"type": "json",
},
)

async def timeline(self, *, type: TimelineType = TimelineType.GLOBAL):
return await self.request(
"web_api/timeline_{type}",
Expand All @@ -418,9 +315,6 @@ async def timeline(self, *, type: TimelineType = TimelineType.GLOBAL):
},
)

async def recommend(self):
return await self.request("index/recommend.json", "main", sign=False)

async def suggest(self, *, keyword: str): # NOTE: this endpoint is not used
return await self.request(
"main/suggest",
Expand Down
30 changes: 1 addition & 29 deletions hibiapi/api/bilibili/api/v2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from enum import Enum
from functools import wraps
from typing import Callable, Coroutine, Optional, TypeVar, Union
from typing import Callable, Coroutine, Optional, TypeVar

from hibiapi.api.bilibili.api.base import (
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
RankBangumiType,
RankContentType,
RankDurationType,
TimelineType,
VideoFormatType,
VideoQualityType,
Expand Down Expand Up @@ -127,31 +124,6 @@ async def search(
pagesize=pagesize,
)

async def rank(
self,
*,
content: Union[RankContentType, RankBangumiType] = RankContentType.FULL_SITE,
duration: RankDurationType = RankDurationType.THREE_DAY,
new: bool = True,
):
if isinstance(content, int):
return await self.base.rank_list(
content=content,
duration=duration,
new=new,
)
else:
return await self.base.rank_list_bangumi(
site=content,
duration=duration,
)

async def typedynamic(self):
return await self.base.type_dynamic()

async def recommend(self):
return await self.base.recommend()

async def timeline(
self, *, type: TimelineType = TimelineType.GLOBAL
): # NOTE: not same with origin
Expand Down
31 changes: 0 additions & 31 deletions hibiapi/api/bilibili/api/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
BaseBilibiliEndpoint,
CommentSortType,
CommentType,
RankBangumiType,
RankContentType,
RankDurationType,
TimelineType,
VideoFormatType,
VideoQualityType,
Expand Down Expand Up @@ -36,23 +33,6 @@ async def video_address(
type=type,
)

async def video_recommend(self):
return await self.base.recommend()

async def video_dynamic(self):
return await self.base.type_dynamic()

async def video_ranking(
self,
*,
type: RankContentType = RankContentType.FULL_SITE,
duration: RankDurationType = RankDurationType.THREE_DAY,
):
return await self.base.rank_list(
content=type,
duration=duration,
)

async def user_info(self, *, uid: int, page: int = 1, size: int = 10):
return await self.base.space(
vmid=uid,
Expand Down Expand Up @@ -87,17 +67,6 @@ async def season_episode(self, *, episode_id: int):
async def season_timeline(self, *, type: TimelineType = TimelineType.GLOBAL):
return await self.base.timeline(type=type)

async def season_ranking(
self,
*,
type: RankBangumiType = RankBangumiType.GLOBAL,
duration: RankDurationType = RankDurationType.THREE_DAY,
):
return await self.base.rank_list_bangumi(
site=type,
duration=duration,
)

async def search(self, *, keyword: str, page: int = 1, size: int = 20):
return await self.base.search(
keyword=keyword,
Expand Down
39 changes: 2 additions & 37 deletions test/test_bilibili_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_paged_playurl(client: TestClient):

def test_seasoninfo(client: TestClient):
response = client.get("seasoninfo", params={"season_id": 425})
print(response.text)
assert response.status_code == 200
assert response.json()["code"] == 0

Expand All @@ -48,6 +49,7 @@ def test_comments(client: TestClient):

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:
Expand Down Expand Up @@ -82,35 +84,6 @@ def test_search_hot(client: TestClient):
assert response.json()["code"] == 0


def test_rank(client: TestClient):
from hibiapi.api.bilibili import RankContentType

for content in RankContentType.__members__.values():
response = client.get("rank", params={"content": content.value})
assert response.status_code == 200
assert response.json()["rank"]


def test_rank_bangumi(client: TestClient):
from hibiapi.api.bilibili import RankBangumiType

response = client.get("rank", params={"content": RankBangumiType.CN.value})
assert response.status_code == 200
assert response.json()["code"] == 0


def test_typedynamic(client: TestClient):
response = client.get("typedynamic")
assert response.status_code == 200
assert response.json()["code"] == 0


def test_recommend(client: TestClient):
response = client.get("recommend")
assert response.status_code == 200
assert response.json()["list"]


def test_timeline(client: TestClient):
from hibiapi.api.bilibili import TimelineType

Expand All @@ -135,11 +108,3 @@ def test_archive(client: TestClient):
def test_favlist(client: TestClient):
# TODO:add test case
pass


def test_rank_redirect(client: TestClient):
response = client.get("/bilibili/rank")

assert response.status_code == 200
assert response.history
assert response.history[0].status_code == 301
24 changes: 0 additions & 24 deletions test/test_bilibili_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,6 @@ def test_video_address(client: TestClient):
pytest.xfail(reason=response.text)


def test_video_recommend(client: TestClient):
response = client.get("video_recommend")
assert response.status_code == 200
assert response.json()["list"]


def test_video_dynamic(client: TestClient):
response = client.get("video_dynamic")
assert response.status_code == 200
assert response.json()["code"] == 0


def test_video_ranking(client: TestClient):
response = client.get("video_ranking")
assert response.status_code == 200
assert response.json()["rank"]


def test_user_info(client: TestClient):
response = client.get("user_info", params={"uid": 2})
assert response.status_code == 200
Expand Down Expand Up @@ -91,12 +73,6 @@ def test_season_timeline(client: TestClient):
assert response.json()["code"] == 0


def test_season_ranking(client: TestClient):
response = client.get("season_ranking")
assert response.status_code == 200
assert response.json()["code"] == 0


def test_search(client: TestClient):
response = client.get("search", params={"keyword": "railgun"})
assert response.status_code == 200
Expand Down

0 comments on commit c58a626

Please sign in to comment.