Skip to content

Commit

Permalink
Merge pull request #9 from imtipi/patch-1
Browse files Browse the repository at this point in the history
feat: enhance `--up_videos` stability by importing cookies
  • Loading branch information
yzqzss authored Sep 21, 2023
2 parents 47753eb + 26459d4 commit 2e70615
Showing 1 changed file with 20 additions and 11 deletions.
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

0 comments on commit 2e70615

Please sign in to comment.