Skip to content

Commit

Permalink
Merge pull request #360 from Nemo2011/dev
Browse files Browse the repository at this point in the history
release 15.5.1
  • Loading branch information
z0z0r4 authored Jun 24, 2023
2 parents 8cb83ea + 6c200d1 commit 86f6882
Show file tree
Hide file tree
Showing 46 changed files with 785 additions and 477 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ scratch/
!tests/*.py
# Virtual environments
venv/
.venv/
virtualenv/
# IDE
.idea/
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOGS/v15.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 15.5.1 2023/6/24

- fix: credential 刷新异步问题 (https://github.com/Nemo2011/bilibili-api/issues/351) (https://github.com/Nemo2011/bilibili-api/issues/358)
- feat: user.get_self_history_new (https://github.com/Nemo2011/bilibili-api/pull/360/commits/01a80daeb468de8e815ea9cd356a7caaf129329a)
- fix: interactive_video (https://github.com/Nemo2011/bilibili-api/pull/360/commits/)6e1de7f16011b3c6434a087a5bb7641e556fcf91

# 15.5.0 2023/6/18

- feat: 新增 Api 信息类等 by @Drelf2018 in https://github.com/Nemo2011/bilibili-api/pull/320
Expand Down
17 changes: 14 additions & 3 deletions bilibili_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@
from .credential import Credential
from .utils.aid_bvid_transformer import aid2bvid, bvid2aid
from .utils.danmaku import Danmaku, DmFontSize, DmMode, SpecialDanmaku
from .utils.network_httpx import HEADERS, Api, check_valid, enc_wbi, get_mixin_key, get_nav, get_session, request, retry, set_session
from .utils.network_httpx import (
HEADERS,
Api,
check_valid,
enc_wbi,
get_mixin_key,
get_nav,
get_session,
request,
retry,
set_session,
)
from .utils.parse_link import ResourceType, parse_link
from .utils.picture import Picture
from .utils.short import get_real_url
from .utils.sync import sync

BILIBILI_API_VERSION = "15.5.0"
BILIBILI_API_VERSION = "15.5.1"

# 如果系统为 Windows,则修改默认策略,以解决代理报错问题
if "windows" in platform.system().lower():
Expand Down Expand Up @@ -155,5 +166,5 @@
"video_tag",
"video_uploader",
"video_zone",
"vote"
"vote",
]
2 changes: 1 addition & 1 deletion bilibili_api/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def get_homepage_albums_list(
page_num (int) : 第几页. Defaults to 1.
page_size (int) : 每一页的数据大小. Defaults to 45.
credential (Optional[Credential]): 凭据类. Defaults to None.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion bilibili_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def get_loading_images_special(
height (str, optional) : 屏幕高度
width (str, optional) : 屏幕宽度
credential (Credential | None, optional): 凭据. Defaults to None.
Returns:
Expand Down
13 changes: 8 additions & 5 deletions bilibili_api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def json(self) -> dict:
async def fetch_content(self) -> None:
"""
获取并解析专栏内容
该返回不会返回任何值,调用该方法后请再调用 `self.markdown()` 或 `self.json()` 来获取你需要的值。
"""

Expand Down Expand Up @@ -615,10 +615,13 @@ async def get_all(self) -> dict:
dict: 调用 API 返回的结果
"""
sess = get_session()
resp = await sess.get(f"https://www.bilibili.com/read/cv{self.__cvid}",
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62",
"cookie": "opus-goback=1"}
)
resp = await sess.get(
f"https://www.bilibili.com/read/cv{self.__cvid}",
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62",
"cookie": "opus-goback=1",
},
)
if resp.status_code == 200:
html = resp.text

Expand Down
2 changes: 1 addition & 1 deletion bilibili_api/article_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def get_category_recommend_articles(
order (ArticleOrder): 排序方式. Defaults to ArticleOrder.DEFAULT.
page_num (int) : 页码. Defaults to 1.
page_size (int) : 每一页数据大小. Defaults to 20.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion bilibili_api/ass.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def make_ass_file_subtitle(
out: Optional[str] = "test.ass",
lan_name: Optional[str] = "中文(自动生成)",
lan_code: Optional[str] = "ai-zh",
credential: Credential = Credential()
credential: Credential = Credential(),
) -> None:
"""
生成视频字幕文件
Expand Down
2 changes: 1 addition & 1 deletion bilibili_api/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def get_hot_song_list(
Args:
pn(int, optional) : 页数. Defaults to 1
credential (Credential | None, optional): 凭据. Defaults to None
Returns:
Expand Down
23 changes: 16 additions & 7 deletions bilibili_api/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def make_time_filter(
Args:
start (datetime, str, int): 开始时间. 如果是 None 则不设置开头.
end (datetime, str, int): 结束时间. 如果是 None 则不设置结尾.
include_start (bool): 是否包含开始时间. 默认为 True.
Expand Down Expand Up @@ -876,7 +876,7 @@ def __init__(
finish_status (Index_Filter.Finish_Status): 是否完结
copyright (Index_Filter.Copyright): 版权
payment (Index_Filter.Payment): 付费门槛
year (str): 年份,调用 Index_Filter.make_time_filter() 传入年份 (int, str) 获取
Expand Down Expand Up @@ -929,7 +929,7 @@ async def get_index_info(
sort (BANGUMI_INDEX.SORT, optional): 排序方式. Defaults to DESC.
pn (int, optional): 页数. Defaults to 1.
ps (int, optional): 每页数量. Defaults to 20.
Returns:
Expand Down Expand Up @@ -1178,7 +1178,10 @@ async def get_episodes(self) -> List["Episode"]:
return []
first_epid = episode_list["main_section"]["episodes"][0]["id"]
credential = self.credential if self.credential else Credential()
bangumi_meta = await get_initial_state(url=f"https://www.bilibili.com/bangumi/play/ep{first_epid}", credential=credential)
bangumi_meta = await get_initial_state(
url=f"https://www.bilibili.com/bangumi/play/ep{first_epid}",
credential=credential,
)
bangumi_meta["media_id"] = self.get_media_id()

episodes = []
Expand Down Expand Up @@ -1282,15 +1285,18 @@ def __init__(self, epid: int, credential: Union[Credential, None] = None):
"""
Args:
epid (int) : 番剧 epid
credential (Credential, optional): 凭据. Defaults to None.
"""
global episode_data_cache
self.credential = credential if credential else Credential()
self.__epid = epid

if not epid in episode_data_cache.keys():
content = get_initial_state_sync(url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}", credential=self.credential)
content = get_initial_state_sync(
url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}",
credential=self.credential,
)
else:
content = episode_data_cache[epid]["bangumi_meta"]

Expand Down Expand Up @@ -1345,7 +1351,10 @@ async def get_episode_info(self) -> dict:
Returns:
HTML 中的数据
"""
return await get_initial_state(url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}", credential=self.credential)
return await get_initial_state(
url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}",
credential=self.credential,
)

async def get_bangumi_from_episode(self) -> "Bangumi":
"""
Expand Down
54 changes: 34 additions & 20 deletions bilibili_api/black_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class BlackFrom(Enum):
ADMIN = 1
ALL = None


class JuryVoteOpinion(Enum):
"""
仲裁投票类型枚举,选择对应案件类型的观点
Expand All @@ -141,6 +142,7 @@ class JuryVoteOpinion(Enum):
- ENV_BAD: 评论环境差
- ENV_UNKNOW: 无法判断评论环境
"""

SUITABLE = 1
AVERAGE = 2
UNSUITABLE = 3
Expand All @@ -150,6 +152,7 @@ class JuryVoteOpinion(Enum):
ENV_BAD = 13
ENV_UNKNOW = 14


API = get_api("black-room")


Expand Down Expand Up @@ -225,6 +228,7 @@ async def get_id(self) -> int:
async def set_id(self, id_) -> None:
self.__init__(id_, self.credential)


class JuryCase:
def __init__(self, case_id: str, credential: Credential):
"""
Expand All @@ -248,7 +252,7 @@ async def get_details(self) -> dict:
return await request(
"GET", api["url"], params=params, credential=self.credential
)

async def get_opinions(self, pn: int = 1, ps: int = 20) -> dict:
"""
获取案件的观点列表
Expand All @@ -267,35 +271,40 @@ async def get_opinions(self, pn: int = 1, ps: int = 20) -> dict:
"GET", api["url"], params=params, credential=self.credential
)


async def vote(self, opinion: JuryVoteOpinion, is_insider: bool, is_anonymous: bool, reason: Optional[str] = None) -> dict:
async def vote(
self,
opinion: JuryVoteOpinion,
is_insider: bool,
is_anonymous: bool,
reason: Optional[str] = None,
) -> dict:
"""
进行仲裁投票
Args:
opinion (JuryVoteOpinion): 投票选项类型
is_insider (bool): 是否观看此类视频
is_anonymous (bool): 是否匿名投票
reason (str, optional): 投票理由. Defaults to None.
Returns:
dict: 调用 API 返回的结果
"""
api = API["jury"]["vote"]
data = {"case_id": self.case_id,
"vote": opinion.value,
"insiders": 1 if is_insider else 0,
"anonymous": 1 if is_anonymous else 0,
"csrf": self.credential.bili_jct,
}
data = {
"case_id": self.case_id,
"vote": opinion.value,
"insiders": 1 if is_insider else 0,
"anonymous": 1 if is_anonymous else 0,
"csrf": self.credential.bili_jct,
}
if reason:
data["content"] = reason
return await request(
"POST", api["url"], data=data, credential=self.credential
)
return await request("POST", api["url"], data=data, credential=self.credential)


async def get_next_jury_case(credential: Credential) -> JuryCase:
"""
Expand All @@ -309,17 +318,22 @@ async def get_next_jury_case(credential: Credential) -> JuryCase:
"""
credential.raise_for_no_sessdata()
api = API["jury"]["next_case"]
return JuryCase((await request("GET", api["url"], credential=credential))["case_id"], credential)
return JuryCase(
(await request("GET", api["url"], credential=credential))["case_id"], credential
)

async def get_jury_case_list(credential: Credential, pn: int = 1, ps: int = 20) -> List[JuryCase]:

async def get_jury_case_list(
credential: Credential, pn: int = 1, ps: int = 20
) -> List[JuryCase]:
"""
获取仲裁案件列表
Args:
credential (Credential): 凭据类
pn (int, optional): 页数. Defaults to 1.
ps (int, optional): 每页数量. Defaults to 20.
Returns:
Expand All @@ -328,4 +342,4 @@ async def get_jury_case_list(credential: Credential, pn: int = 1, ps: int = 20)
api = API["jury"]["case_list"]
params = {"pn": pn, "ps": ps}
info = await request("GET", api["url"], params=params, credential=credential)
return [JuryCase(case["case_id"], credential) for case in info["list"]]
return [JuryCase(case["case_id"], credential) for case in info["list"]]
20 changes: 10 additions & 10 deletions bilibili_api/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def get_channel_category_detail(
Args:
category_id (int): 频道分类的 id。
offset (str): 偏移值(下面的数据的第一个频道 ID,为该请求结果中的 offset 键对应的值),类似单向链表. Defaults to "0"
"""
credential = credential if credential else Credential()
Expand Down Expand Up @@ -123,7 +123,7 @@ def only_achieve(self, info: list) -> List[dict]:
Args:
info (list): 待筛选的数据
Returns:
list: card_type=achieve 的数据
"""
Expand All @@ -144,9 +144,9 @@ async def get_featured_list(
Args:
filter (ChannelVideosFilter) : 获取视频的相关选项. Defaults to ALL
offset (str) : 偏移值(下面的第一个视频的 ID,为该请求结果中的 offset 键对应的值),类似单向链表. Defaults to None
page_size (int) : 每页的数据大小. Defaults to 30
Returns:
Expand Down Expand Up @@ -177,9 +177,9 @@ async def get_raw_list(
Args:
order (ChannelVideosOrder) : 排序方式. Defaults to HOT
offset (str) : 偏移值(下面的第一个视频的 ID,为该请求结果中的 offset 键对应的值),类似单向链表
page_size (int) : 每页的数据大小
Returns:
Expand Down Expand Up @@ -211,9 +211,9 @@ async def get_list(
Args:
order (ChannelVideosOrder) : 排序方式. Defaults to HOT
offset (str) : 偏移值(下面的第一个视频的 ID,为该请求结果中的 offset 键对应的值),类似单向链表
page_size (int) : 每页的数据大小
Returns:
Expand Down Expand Up @@ -287,7 +287,7 @@ async def subscribe_channel(channel: Channel, credential: Credential) -> dict:
Args:
channel (Channel) : 要订阅的频道
credential (Credential): 凭据类
Returns:
Expand All @@ -304,7 +304,7 @@ async def unsubscribe_channel(channel: Channel, credential: Credential) -> dict:
Args:
channel (Channel) : 要订阅的频道
credential (Credential): 凭据类
Returns:
Expand Down
Loading

0 comments on commit 86f6882

Please sign in to comment.