mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Merge pull request #1097 from LambdaYH/main
更换bilibili_sub获取用户昵称用的API&尝试修了一下get_video()
This commit is contained in:
commit
a45a3002d5
@ -7,7 +7,7 @@ from asyncio.exceptions import TimeoutError
|
|||||||
from utils.utils import get_bot
|
from utils.utils import get_bot
|
||||||
from .model import BilibiliSub
|
from .model import BilibiliSub
|
||||||
from bilireq.live import get_room_info_by_id
|
from bilireq.live import get_room_info_by_id
|
||||||
from .utils import get_meta
|
from .utils import get_meta, get_user_card
|
||||||
from utils.message_builder import image
|
from utils.message_builder import image
|
||||||
from bilireq.user import get_user_info
|
from bilireq.user import get_user_info
|
||||||
from bilireq import dynamic
|
from bilireq import dynamic
|
||||||
@ -83,7 +83,7 @@ async def add_up_sub(uid: int, sub_user: str) -> str:
|
|||||||
async with db.transaction():
|
async with db.transaction():
|
||||||
try:
|
try:
|
||||||
"""bilibili_api.user库中User类的get_user_info改为bilireq.user库的get_user_info方法"""
|
"""bilibili_api.user库中User类的get_user_info改为bilireq.user库的get_user_info方法"""
|
||||||
user_info = await get_user_info(uid)
|
user_info = await get_user_card(uid)
|
||||||
except ResponseCodeError:
|
except ResponseCodeError:
|
||||||
return f"未找到UpId:{uid} 的信息,请检查Id是否正确"
|
return f"未找到UpId:{uid} 的信息,请检查Id是否正确"
|
||||||
uname = user_info["name"]
|
uname = user_info["name"]
|
||||||
@ -249,7 +249,7 @@ async def _get_up_status(id_: int) -> Optional[str]:
|
|||||||
"""
|
"""
|
||||||
_user = await BilibiliSub.get_sub(id_)
|
_user = await BilibiliSub.get_sub(id_)
|
||||||
"""bilibili_api.user库中User类的get_user_info改为bilireq.user库的get_user_info方法"""
|
"""bilibili_api.user库中User类的get_user_info改为bilireq.user库的get_user_info方法"""
|
||||||
user_info = await get_user_info(_user.uid)
|
user_info = await get_user_card(_user.uid)
|
||||||
uname = user_info["name"]
|
uname = user_info["name"]
|
||||||
"""bilibili_api.user库中User类的get_videos改为bilireq.user库的get_videos方法"""
|
"""bilibili_api.user库中User类的get_videos改为bilireq.user库的get_videos方法"""
|
||||||
video_info = await get_videos(_user.uid)
|
video_info = await get_videos(_user.uid)
|
||||||
|
|||||||
@ -1,14 +1,15 @@
|
|||||||
from utils.image_utils import BuildImage
|
from utils.image_utils import BuildImage
|
||||||
from configs.path_config import IMAGE_PATH
|
from configs.path_config import IMAGE_PATH
|
||||||
from utils.http_utils import AsyncHttpx
|
from utils.http_utils import AsyncHttpx, get_user_agent
|
||||||
# from bilibili_api import user
|
# from bilibili_api import user
|
||||||
from bilireq.user import get_user_info
|
from bilireq.user import get_user_info
|
||||||
|
from httpx import AsyncClient
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
|
||||||
BORDER_PATH = IMAGE_PATH / "border"
|
BORDER_PATH = IMAGE_PATH / "border"
|
||||||
BORDER_PATH.mkdir(parents=True, exist_ok=True)
|
BORDER_PATH.mkdir(parents=True, exist_ok=True)
|
||||||
|
BASE_URL = "https://api.bilibili.com"
|
||||||
|
|
||||||
async def get_pic(url: str) -> bytes:
|
async def get_pic(url: str) -> bytes:
|
||||||
"""
|
"""
|
||||||
@ -78,7 +79,6 @@ async def get_meta(media_id: int, auth=None, reqtype="both", **kwargs):
|
|||||||
"""
|
"""
|
||||||
from bilireq.utils import get
|
from bilireq.utils import get
|
||||||
|
|
||||||
BASE_URL = "https://api.bilibili.com"
|
|
||||||
url = f"{BASE_URL}/pgc/review/user"
|
url = f"{BASE_URL}/pgc/review/user"
|
||||||
params = {"media_id": media_id}
|
params = {"media_id": media_id}
|
||||||
raw_json = await get(url, raw=True, params=params, auth=auth, reqtype=reqtype, **kwargs)
|
raw_json = await get(url, raw=True, params=params, auth=auth, reqtype=reqtype, **kwargs)
|
||||||
@ -86,8 +86,7 @@ async def get_meta(media_id: int, auth=None, reqtype="both", **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
async def get_videos(
|
async def get_videos(
|
||||||
uid: int, tid: int = 0, pn: int = 1, keyword: str = "", order: str = "pubdate",
|
uid: int, tid: int = 0, pn: int = 1, keyword: str = "", order: str = "pubdate"
|
||||||
*, auth=None, reqtype="both", **kwargs
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
获取用户投该视频信息
|
获取用户投该视频信息
|
||||||
@ -100,15 +99,45 @@ async def get_videos(
|
|||||||
:param keyword: 搜索关键词
|
:param keyword: 搜索关键词
|
||||||
:param order: 排序方式,可以为 “pubdate(上传日期从新到旧), stow(收藏从多到少), click(播放量从多到少)”
|
:param order: 排序方式,可以为 “pubdate(上传日期从新到旧), stow(收藏从多到少), click(播放量从多到少)”
|
||||||
"""
|
"""
|
||||||
from bilireq.utils import get
|
from bilireq.utils import ResponseCodeError
|
||||||
BASE_URL = "https://api.bilibili.com"
|
|
||||||
url = f"{BASE_URL}/x/space/arc/search"
|
url = f"{BASE_URL}/x/space/arc/search"
|
||||||
params = {
|
headers = get_user_agent()
|
||||||
"mid": uid,
|
headers["Referer"] = f"https://space.bilibili.com/{uid}/video"
|
||||||
"ps": 30,
|
async with AsyncClient() as client:
|
||||||
"tid": tid,
|
r = await client.head(
|
||||||
"pn": pn,
|
"https://space.bilibili.com",
|
||||||
"keyword": keyword,
|
headers=headers,
|
||||||
"order": order
|
)
|
||||||
}
|
params = {
|
||||||
return await get(url, params=params, auth=auth, reqtype=reqtype, **kwargs)
|
"mid": uid,
|
||||||
|
"ps": 30,
|
||||||
|
"tid": tid,
|
||||||
|
"pn": pn,
|
||||||
|
"keyword": keyword,
|
||||||
|
"order": order,
|
||||||
|
}
|
||||||
|
raw_json = (
|
||||||
|
await client.get(url, params=params, headers=headers, cookies=r.cookies)
|
||||||
|
).json()
|
||||||
|
if raw_json["code"] != 0:
|
||||||
|
raise ResponseCodeError(
|
||||||
|
code=raw_json["code"],
|
||||||
|
msg=raw_json["message"],
|
||||||
|
data=raw_json.get("data", None),
|
||||||
|
)
|
||||||
|
return raw_json["data"]
|
||||||
|
|
||||||
|
async def get_user_card(mid, photo: bool = False, auth=None, reqtype="both", **kwargs):
|
||||||
|
from bilireq.utils import get
|
||||||
|
|
||||||
|
url = f"{BASE_URL}/x/web-interface/card"
|
||||||
|
return (
|
||||||
|
await get(
|
||||||
|
url,
|
||||||
|
params={"mid": mid, "photo": photo},
|
||||||
|
auth=auth,
|
||||||
|
reqtype=reqtype,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
)["card"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user