Skip to content

0722-依然出现 HTTP Error 412问题,但AI帮助下梳理了一下解决思路 #98

Description

@ganyz

在linux和windows系统下都试了一下,可行
主要操作是:# 二、打补丁 A:替换 yt-dlp 的 bilibili 提取器
# 三、打补丁 B:给 bili2text 加上 Referer 请求头

============================================

零、克隆项目

============================================
git clone https://github.com/lanbinleo/bili2text.git
cd bili2text

============================================

一、装依赖

============================================

Linux & Windows 通用

uv sync
uv sync --extra whisper --extra web

============================================

二、打补丁 A:替换 yt-dlp 的 bilibili 提取器

加上 412 challenge 解答逻辑,修复 "Unable to download webpage: HTTP 412"

============================================

--- Linux ---

curl -o .venv/lib/python3.12/site-packages/yt_dlp/extractor/bilibili.py
"https://raw.githubusercontent.com/0xvd/yt-dlp-exp/fix_bilibili/yt_dlp/extractor/bilibili.py"
rm -f .venv/lib/python3.12/site-packages/yt_dlp/extractor/pycache/bilibili*.pyc

--- Windows (PowerShell) ---

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/0xvd/yt-dlp-exp/fix_bilibili/yt_dlp/extractor/bilibili.py" -OutFile ".venv\Lib\site-packages\yt_dlp\extractor\bilibili.py"
Remove-Item -Force ".venv\Lib\site-packages\yt_dlp\extractor_pycache_\bilibili*.pyc" -ErrorAction SilentlyContinue

============================================

三、打补丁 B:给 bili2text 加上 Referer 请求头

修复 "Unable to download JSON metadata: HTTP 412"

============================================

--- Linux ---

python3 -c "
p = 'src/b2t/downloaders/ytdlp.py'
c = open(p).read()
if 'http_headers' not in c:
open(p, 'w').write(c.replace(
'"no_warnings": True,\n }',
'"no_warnings": True,\n'
' "http_headers": {\n'
' "Referer": "https://www.bilibili.com/\",\n'
' "User-Agent": (\n'
' "Mozilla/5.0 (X11; Linux x86_64) "\n'
' "AppleWebKit/537.36 (KHTML, like Gecko) "\n'
' "Chrome/131.0.0.0 Safari/537.36"\n'
' ),\n'
' },\n'
' }'))
print('patched')
else:
print('already patched')
"

--- Windows (PowerShell) ---

在 PowerShell 里输入:
notepad patch.py

点击是

把下面这段完整粘贴进去(注意要保持缩进):

p = "src/b2t/downloaders/ytdlp.py"
c = open(p, encoding="utf-8").read()
if "http_headers" not in c:
open(p, "w", encoding="utf-8").write(c.replace(
'"no_warnings": True,\n }',
'"no_warnings": True,\n'
' "http_headers": {\n'
' "Referer": "https://www.bilibili.com/",\n'
' "User-Agent": (\n'
' "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "\n'
' "AppleWebKit/537.36 (KHTML, like Gecko) "\n'
' "Chrome/131.0.0.0 Safari/537.36"\n'
' ),\n'
' },\n'
' }'))
print("patched")
else:
print("already patched")

然后运行

python patch.py

============================================

四、装 ffmpeg(音视频合并需要)

============================================

--- Linux ---

sudo apt install ffmpeg # Debian/Ubuntu

sudo dnf install ffmpeg # Fedora

sudo pacman -S ffmpeg # Arch

--- Windows ---

winget install ffmpeg

============================================

五、验证

============================================

确认补丁 A 生效(输出 2 才对)

grep -c "bili_challenge_result" .venv/lib/python*/site-packages/yt_dlp/extractor/bilibili.py # Linux

Select-String -Pattern "bili_challenge_result" .venv\Lib\site-packages\yt_dlp\extractor\bilibili.py # Windows

确认补丁 B 生效(输出 http_headers 相关行)

grep "http_headers" src/b2t/downloaders/ytdlp.py # Linux

Select-String -Pattern "http_headers" src\b2t\downloaders\ytdlp.py # Windows

确认 ffmpeg 可用

ffmpeg -version

============================================

六、启动

============================================
uv run bili2text ui

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions