Skip to content

Commit af08bd5

Browse files
committed
feat: Allow downloading without being logged in
Removes the strict requirement for a `SESSDATA` cookie, allowing the archiver to proceed even when not authenticated. - Replaces hard assertions for login status with warnings. - Informs the user that video quality is limited to 1080p when not logged in.
1 parent 11d610b commit af08bd5

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

biliarchiver/archive_bvid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ async def archive_bvid(
9595
):
9696
async with semaphore:
9797
assert d.hierarchy is True, _("hierarchy 必须为 True") # 为保持后续目录结构、文件命名的一致性
98-
assert d.client.cookies.get("SESSDATA") is not None, _(
99-
"sess_data 不能为空"
100-
) # 开个大会员呗,能下 4k 呢。
101-
assert logined is True, _("请先检查 SESSDATA 是否过期,再将 logined 设置为 True") # 防误操作
98+
if d.client.cookies.get("SESSDATA") is None:
99+
print(_("未登录,SESSDATA 为空")) # 开个大会员呗,能下 4k 呢。
100+
else:
101+
assert logined is True, _(message="请先检查 SESSDATA 是否过期,再将 logined 设置为 True") # 防误操作
102102
upper_part = human_readable_upper_part_map(string=bvid, backward=True)
103103
videos_basepath: Path = (
104104
config.storage_home_dir / "videos" / f"{bvid}-{upper_part}"

biliarchiver/cli_tools/bili_archive_bvids.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ async def _down(
9595
update_cookies_from_file(d.client, config.cookies_file)
9696
client = Client(cookies=d.client.cookies, headers=d.client.headers)
9797
logined = is_login(client)
98-
if not logined:
99-
return
10098

10199
def check_free_space():
102100
if min_free_space_gb != 0:
@@ -194,7 +192,9 @@ def update_cookies_from_file(client: AsyncClient, cookies_path: Union[str, Path]
194192
else:
195193
raise TypeError(f"cookies_path: {type(cookies_path)}")
196194

197-
assert os.path.exists(cookies_path), _("cookies 文件不存在: {}").format(cookies_path)
195+
if not os.path.exists(cookies_path):
196+
print(_("cookies 文件不存在: {}").format(cookies_path))
197+
return
198198

199199
from http.cookiejar import MozillaCookieJar
200200

@@ -223,7 +223,6 @@ def update_cookies_from_file(client: AsyncClient, cookies_path: Union[str, Path]
223223
if loadded_cookies > 100:
224224
print(_("吃了过多的 cookies,可能导致 httpx.Client 怠工,响应非常缓慢"))
225225

226-
assert client.cookies.get("SESSDATA") is not None, "SESSDATA 不存在"
227226
# print(f'SESS_DATA: {client.cookies.get("SESSDATA")}')
228227

229228

@@ -234,9 +233,9 @@ def is_login(cilent: Client) -> bool:
234233
if nav_json["code"] == 0:
235234
print(_("BiliBili 登录成功,饼干真香。"))
236235
print(_("NOTICE: 存档过程中请不要在 cookies 的源浏览器访问 B 站,避免 B 站刷新"), end=" ")
237-
print(_("cookies 导致我们半路下到的视频全是 480P 的优酷土豆级醇享画质。"))
238236
return True
239237
print(_("未登录/SESSDATA无效/过期,你这饼干它保真吗?"))
238+
print(_("未登录时下到的视频均为最高 1080P 画质。"))
240239
return False
241240

242241

0 commit comments

Comments
 (0)