refactor(by_up_videos): enhance session stability by importing cookies

This commit is contained in:
tipi 2023-09-15 23:44:01 +08:00 committed by GitHub
parent 47753eb76b
commit 5cdb09adc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,8 @@ from biliarchiver.i18n import _, ngettext
from bilix.sites.bilibili import api
from rich import print
from biliarchiver.cli_tools.bili_archive_bvids import update_cookies_from_file
from biliarchiver.config import config
async def by_series(url_or_sid: str) -> Path:
sid = sid = (
@ -93,6 +94,7 @@ async def by_up_videos(url_or_mid: str) -> Path:
assert mid.isdigit(), _("mid 应是数字字符串")
client = AsyncClient(**api.dft_client_settings)
update_cookies_from_file(client,config.cookies_file)
ps = 30 # 每页视频数,最小 1最大 50默认 30
order = "pubdate" # 默认为pubdate 最新发布pubdate 最多播放click 最多收藏stow
keyword = "" # 搜索关键词
@ -113,8 +115,8 @@ async def by_up_videos(url_or_mid: str) -> Path:
while pn < total_size / ps:
pn += 1
# print(f"获取第 {pn} 页 (10s...)")
print(ngettext("获取第 {} 页 (10 秒...)", "获取第 {} 页 (10 秒...)", pn).format(pn))
await asyncio.sleep(10)
print(ngettext("获取第 {} 页 (3 秒...)", "获取第 {} 页 (3 秒...)", pn).format(pn))
await asyncio.sleep(3)
_x, _y, bv_ids_page = await api.get_up_info(client, mid, pn, ps, order, keyword)
bv_ids += bv_ids_page