Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance --up_videos stability by importing cookies #9

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions biliarchiver/cli_tools/get_command.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import asyncio
from gettext import ngettext
import json
import os
from pathlib import Path
import re
import time
from httpx import AsyncClient
import requests
import json
from pathlib import Path

import click
import requests
from bilix.sites.bilibili import api
from click_option_group import optgroup
from httpx import AsyncClient
from rich import print

from biliarchiver.i18n import _, ngettext

from bilix.sites.bilibili import api
from rich import print


async def by_series(url_or_sid: str) -> Path:
sid = sid = (
Expand Down Expand Up @@ -93,6 +92,17 @@ async def by_up_videos(url_or_mid: str) -> Path:
assert mid.isdigit(), _("mid 应是数字字符串")

client = AsyncClient(**api.dft_client_settings)

from biliarchiver.config import config

if config.cookies_file.exists():
from biliarchiver.cli_tools.bili_archive_bvids import update_cookies_from_file
update_cookies_from_file(client, config.cookies_file)
delay = 3
else:
print(_("cookies 文件不存在: {}").format(config.cookies_file))
delay = 10

ps = 30 # 每页视频数,最小 1,最大 50,默认 30
order = "pubdate" # 默认为pubdate 最新发布:pubdate 最多播放:click 最多收藏:stow
keyword = "" # 搜索关键词
Expand All @@ -112,9 +122,8 @@ async def by_up_videos(url_or_mid: str) -> Path:
print(_("(如果最新的视频为合作视频的非主作者,UP 名可能会识别错误,但不影响获取 bvid 列表)"))
while pn < total_size / ps:
pn += 1
# print(f"获取第 {pn} 页 (10s...)")
print(ngettext("获取第 {} 页 (10 秒...)", "获取第 {} 页 (10 秒...)", pn).format(pn))
await asyncio.sleep(10)
print(ngettext("获取第 {} 页", "获取第 {} 页", pn).format(pn))
await asyncio.sleep(delay)
_x, _y, bv_ids_page = await api.get_up_info(client, mid, pn, ps, order, keyword)
bv_ids += bv_ids_page

Expand Down