diff --git a/bilibili_api/article.py b/bilibili_api/article.py index 5ee96ba3..94f8a8e6 100644 --- a/bilibili_api/article.py +++ b/bilibili_api/article.py @@ -129,7 +129,7 @@ def __init__(self, rlid: int, credential: Union[Credential, None] = None): credential (Credential | None, optional): 凭据类. Defaults to None. """ self.__rlid = rlid - self.credential = credential + self.credential: Credential = credential def get_rlid(self) -> int: return self.__rlid diff --git a/bilibili_api/ass.py b/bilibili_api/ass.py index 7a93d4e1..27a15336 100644 --- a/bilibili_api/ass.py +++ b/bilibili_api/ass.py @@ -91,7 +91,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: Optional[Credential] = None, ) -> None: """ 生成视频字幕文件 @@ -109,7 +109,7 @@ async def make_ass_file_subtitle( lan_code (str, optional) : 字幕语言代码,如 ”中文(自动翻译)” 和 ”中文(自动生成)“ 为 "ai-zh" - credential (Credential) : Credential 类. 必须在此处或传入的视频 obj 中传入凭据,两者均存在则优先此处 + credential (Credential, optional): Credential 类. 必须在此处或传入的视频 obj 中传入凭据,两者均存在则优先此处 """ # 目测必须得有 Credential 才能获取字幕 if credential.has_sessdata(): diff --git a/bilibili_api/audio.py b/bilibili_api/audio.py index ec5858da..670aadb2 100644 --- a/bilibili_api/audio.py +++ b/bilibili_api/audio.py @@ -29,7 +29,7 @@ def __init__(self, auid: int, credential: Union[Credential, None] = None): credential (Credential | None, optional): 凭据. Defaults to None """ - self.credential = credential if credential is not None else Credential() + self.credential: Credential = credential if credential is not None else Credential() self.__auid = auid def get_auid(self) -> int: @@ -111,7 +111,7 @@ def __init__(self, amid: int, credential: Union[Credential, None] = None): credential (Credential | None, optional): 凭据. Defaults to None. """ self.__amid = amid - self.credential = credential if credential is not None else Credential() + self.credential: Credential = credential if credential is not None else Credential() def get_amid(self) -> int: return self.__amid diff --git a/bilibili_api/audio_uploader.py b/bilibili_api/audio_uploader.py index f7d34ee1..6261a161 100644 --- a/bilibili_api/audio_uploader.py +++ b/bilibili_api/audio_uploader.py @@ -516,9 +516,9 @@ def __init__(self, path: str, meta: SongMeta, credential: Credential): credential (Credential): 账号信息 """ super().__init__() - self.path = path - self.meta = meta - self.credential = credential + self.path: str = path + self.meta: str = meta + self.credential: Credential = credential self.__upos_file = UposFile(path) async def _preupload(self) -> dict: diff --git a/bilibili_api/bangumi.py b/bilibili_api/bangumi.py index b2876bc5..e039772e 100644 --- a/bilibili_api/bangumi.py +++ b/bilibili_api/bangumi.py @@ -1003,7 +1003,7 @@ def __init__( """ if media_id == -1 and ssid == -1 and epid == -1: raise ValueError("需要 Media_id 或 Season_id 或 epid 中的一个 !") - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() # 处理极端情况 params = {} self.__ssid = ssid diff --git a/bilibili_api/black_room.py b/bilibili_api/black_room.py index a15ad643..3fcc73ad 100644 --- a/bilibili_api/black_room.py +++ b/bilibili_api/black_room.py @@ -198,7 +198,7 @@ def __init__(self, black_room_id: int, credential: Union[Credential, None] = Non credential (Credential | None, optional): 凭据类. Defaults to None. """ self.__id = black_room_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() async def get_details(self) -> dict: """ @@ -238,7 +238,7 @@ def __init__(self, case_id: str, credential: Credential): credential (Credential) : 凭据类 """ self.case_id = case_id - self.credential = credential + self.credential: Credential = credential async def get_details(self) -> dict: """ diff --git a/bilibili_api/channel_series.py b/bilibili_api/channel_series.py index fab585b3..1be72cf3 100644 --- a/bilibili_api/channel_series.py +++ b/bilibili_api/channel_series.py @@ -78,7 +78,7 @@ def __init__( self.is_new = type_.value self.id_ = id_ self.owner = User(self.__uid, credential=credential) - self.credential = credential + self.credential: Credential = credential self.meta = None if not f"{type_.value}-{id_}" in channel_meta_cache.keys(): if self.is_new: diff --git a/bilibili_api/cheese.py b/bilibili_api/cheese.py index ac914368..c3015872 100644 --- a/bilibili_api/cheese.py +++ b/bilibili_api/cheese.py @@ -61,7 +61,7 @@ def __init__( raise ValueError("season id 和 ep id 必须选一个") self.__season_id = season_id self.__ep_id = ep_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() if self.__season_id == -1: # self.season_id = str(sync(self.get_meta())["season_id"]) api = API["info"]["meta"] @@ -150,7 +150,7 @@ def __init__(self, epid, credential: Union[Credential, None] = None): self.cheese = CheeseList(ep_id=self.__epid) else: self.cheese = CheeseList(season_id=meta["ssid"]) - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() if meta == None: api = API["info"]["meta"] params = {"season_id": self.cheese.get_season_id(), "ep_id": self.__epid} diff --git a/bilibili_api/comment.py b/bilibili_api/comment.py index cc373f7b..67fdff3a 100644 --- a/bilibili_api/comment.py +++ b/bilibili_api/comment.py @@ -133,7 +133,7 @@ def __init__( self.__oid = oid self.__rpid = rpid self.__type = type_ - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() def __get_data(self, status: bool) -> dict: """ diff --git a/bilibili_api/dynamic.py b/bilibili_api/dynamic.py index be2f5e3b..a393002a 100644 --- a/bilibili_api/dynamic.py +++ b/bilibili_api/dynamic.py @@ -738,7 +738,7 @@ def __init__( credential (Credential | None, optional): 凭据类. Defaults to None. """ self.__dynamic_id = dynamic_id - self.credential = credential if credential is not None else Credential() + self.credential: Credential = credential if credential is not None else Credential() if cache_pool.dynamic_is_opus.get(self.__dynamic_id): self.__opus = cache_pool.dynamic_is_opus[self.__dynamic_id] diff --git a/bilibili_api/favorite_list.py b/bilibili_api/favorite_list.py index 58fedcc7..71ef99fb 100644 --- a/bilibili_api/favorite_list.py +++ b/bilibili_api/favorite_list.py @@ -81,7 +81,7 @@ def __init__( """ self.__type = type_ self.__media_id = media_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() def is_video_favorite_list(self) -> bool: """ diff --git a/bilibili_api/festival.py b/bilibili_api/festival.py index b16fbdce..5d5a02a0 100644 --- a/bilibili_api/festival.py +++ b/bilibili_api/festival.py @@ -24,7 +24,7 @@ def __init__(self, fes_id: str, credential: Optional[Credential] = None) -> None credential (Credential, optional): 凭据类. Defaults to None. """ self.fes_id = fes_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() async def get_info(self) -> dict: """ diff --git a/bilibili_api/game.py b/bilibili_api/game.py index 9f9c12c7..a0f7a89f 100644 --- a/bilibili_api/game.py +++ b/bilibili_api/game.py @@ -35,7 +35,7 @@ def __init__(self, game_id: int, credential: Union[None, Credential] = None): credential (Credential): 凭据类. Defaults to None. """ self.__game_id = game_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() def get_game_id(self) -> int: return self.__game_id diff --git a/bilibili_api/live.py b/bilibili_api/live.py index fd0a2379..1335b42d 100644 --- a/bilibili_api/live.py +++ b/bilibili_api/live.py @@ -118,9 +118,9 @@ def __init__( self.room_display_id = room_display_id if credential is None: - self.credential = Credential() + self.credential: Credential = Credential() else: - self.credential = credential + self.credential: Credential = credential self.__ruid = None @@ -884,17 +884,17 @@ def __init__( """ super().__init__() - self.credential = credential if credential is not None else Credential() - self.room_display_id = room_display_id - self.max_retry = max_retry - self.retry_after = retry_after + self.credential: Credential = credential if credential is not None else Credential() + self.room_display_id: int = room_display_id + self.max_retry: int = max_retry + self.retry_after: float = retry_after self.__room_real_id = None self.__status = 0 self.__ws = None self.__tasks = [] self.__debug = debug self.__heartbeat_timer = 60.0 - self.err_reason = "" + self.err_reason: str = "" # logging self.logger = logging.getLogger(f"LiveDanmaku_{self.room_display_id}") diff --git a/bilibili_api/manga.py b/bilibili_api/manga.py index 5809a921..944da135 100644 --- a/bilibili_api/manga.py +++ b/bilibili_api/manga.py @@ -142,7 +142,7 @@ def __init__(self, manga_id: int, credential: Optional[Credential] = None): """ credential = credential if credential else Credential() self.__manga_id = manga_id - self.credential = credential + self.credential: Credential = credential self.__info: Optional[Dict] = None def get_manga_id(self) -> int: diff --git a/bilibili_api/opus.py b/bilibili_api/opus.py index cd3519e3..cb33c178 100644 --- a/bilibili_api/opus.py +++ b/bilibili_api/opus.py @@ -43,7 +43,7 @@ def __init__(self, opus_id: int, credential: Optional[Credential] = None): self.__id = opus_id self.__is_note = False self.__info = None - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() if cache_pool.opus_type.get(self.__id): self.__is_note = cache_pool.opus_is_note[self.__id] diff --git a/bilibili_api/session.py b/bilibili_api/session.py index 56977c40..c9e5975a 100644 --- a/bilibili_api/session.py +++ b/bilibili_api/session.py @@ -433,7 +433,7 @@ def __init__(self, credential: Credential, debug=False): self.maxSeqno = dict() # 凭证 - self.credential = credential + self.credential: Credential = credential # 异步定时任务框架 self.sched = AsyncIOScheduler(timezone="Asia/Shanghai") diff --git a/bilibili_api/topic.py b/bilibili_api/topic.py index e7316f54..d4463e49 100644 --- a/bilibili_api/topic.py +++ b/bilibili_api/topic.py @@ -82,7 +82,7 @@ def __init__(self, topic_id: int, credential: Union[Credential, None] = None): credential (Credential): 凭据类 """ self.__topic_id = topic_id - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() def get_topic_id(self) -> int: """ diff --git a/bilibili_api/user.py b/bilibili_api/user.py index 76d5b891..1f3b5417 100644 --- a/bilibili_api/user.py +++ b/bilibili_api/user.py @@ -250,7 +250,7 @@ def __init__(self, uid: int, credential: Union[Credential, None] = None): if credential is None: credential = Credential() - self.credential = credential + self.credential: Credential = credential self.__self_info = None def get_user_info_sync(self) -> dict: diff --git a/bilibili_api/video.py b/bilibili_api/video.py index c46da95e..24e15eb3 100644 --- a/bilibili_api/video.py +++ b/bilibili_api/video.py @@ -1777,7 +1777,7 @@ def __init__( debug (bool, optional) : 调试模式,将输出更详细信息. Defaults to False. """ super().__init__() - self.credential = credential + self.credential: Credential = credential if credential else Credential() self.__video = Video(bvid, aid, credential=credential) # 智能选择在 log 中展示的 ID。 diff --git a/bilibili_api/video_tag.py b/bilibili_api/video_tag.py index a3589e32..ceba2bce 100644 --- a/bilibili_api/video_tag.py +++ b/bilibili_api/video_tag.py @@ -45,7 +45,7 @@ def __init__( else: self.__tag_id = tag_id credential = credential if credential else Credential() - self.credential = credential + self.credential: Credential = credential def get_tag_id(self) -> int: return self.__tag_id diff --git a/bilibili_api/video_uploader.py b/bilibili_api/video_uploader.py index ebd7ea45..bf679a9d 100644 --- a/bilibili_api/video_uploader.py +++ b/bilibili_api/video_uploader.py @@ -728,7 +728,7 @@ def __init__( super().__init__() self.meta = meta self.pages = pages - self.credential = credential + self.credential: Credential = credential self.cover = ( self.meta.cover if isinstance(self.meta, VideoMeta) @@ -1410,7 +1410,7 @@ def __init__( super().__init__() self.bvid = bvid self.meta = meta - self.credential = credential if credential else Credential() + self.credential: Credential = credential if credential else Credential() self.cover_path = cover self.__old_configs = {} self.meta["aid"] = bvid2aid(bvid) diff --git a/bilibili_api/vote.py b/bilibili_api/vote.py index 66cccb52..b7e6bd52 100644 --- a/bilibili_api/vote.py +++ b/bilibili_api/vote.py @@ -87,7 +87,7 @@ class Vote: credential (Credential): 凭据类 """ - def __init__(self, vote_id: int, credential: Credential = Credential()) -> None: + def __init__(self, vote_id: int, credential: Optional[Credential] = None) -> None: """ Args: vote_id (int): vote_id, 获取:https://nemo2011.github.io/bilibili-api/#/vote_id @@ -95,7 +95,7 @@ def __init__(self, vote_id: int, credential: Credential = Credential()) -> None: credential (Credential): 凭据类,非必要. """ self.__vote_id = vote_id - self.credential = credential + self.credential: Credential = credential if credential else Credential() self.title: Optional[str] = None def get_vote_id(self) -> int: diff --git a/bilibili_api/watchroom.py b/bilibili_api/watchroom.py index d788b55b..2d08f4e4 100644 --- a/bilibili_api/watchroom.py +++ b/bilibili_api/watchroom.py @@ -116,7 +116,7 @@ def __init__(self, room_id: int, credential: Credential = None): """ credential = credential if credential else Credential() self.__room_id = room_id - self.credential = credential + self.credential: Credential = credential self.credential.raise_for_no_sessdata() self.credential.raise_for_no_bili_jct() if room_id in watch_room_bangumi_cache.keys():