Skip to content

[Bilibili] Fix HTTP 412 extraction and expose DASH audio formats - #3057

Open
zgxkbtl wants to merge 1 commit into
soimort:developfrom
zgxkbtl:fix/bilibili-api-fallback
Open

[Bilibili] Fix HTTP 412 extraction and expose DASH audio formats#3057
zgxkbtl wants to merge 1 commit into
soimort:developfrom
zgxkbtl:fix/bilibili-api-fallback

Conversation

@zgxkbtl

@zgxkbtl zgxkbtl commented Jul 17, 2026

Copy link
Copy Markdown

Problem

Ordinary Bilibili av/BV extraction relied on the page's embedded
__INITIAL_STATE__. The initial page request can now return HTTP 412, leaving
the state empty and eventually failing with:

TypeError: the JSON object must be str, bytes or bytearray, not NoneType

This can be reproduced with:

you-get -i https://www.bilibili.com/video/BV1nmRcBrEzv/

In addition, DASH audio tracks were only associated with video formats. They
could not be listed or selected directly with -F, and selecting an audio-only
format still triggered irrelevant video URL size probes.

Changes

  • Fetch metadata for ordinary av/BV videos from
    /x/web-interface/view, while preserving the existing bangumi and special
    URL flows.
  • Validate Bilibili API responses, report useful errors, and select the correct
    cid for multipart videos.
  • Use the current shared cookie state and a modern browser user agent for
    Bilibili requests.
  • Expose DASH audio qualities 30280, 30232, and 30216 as standalone
    dash-audio-* formats and preserve their .m4a extension.
  • Skip video size probes for explicitly selected audio-only formats, and bound
    and close HTTP size-probe requests.
  • Add focused unit coverage for API metadata, multipart selection, API errors,
    cookie handling, audio stream selection, and extension handling.

Tests

PYTHONPATH=src uv run --with dukpy python -m unittest discover -s tests -p 'test_bilibili.py'
PYTHONPATH=src uv run --with dukpy python -m unittest discover -s tests -p 'test_common.py'
PYTHONPATH=src uv run --with dukpy python -m unittest discover -s tests -p 'test_extractor.py'
uvx flake8 src tests --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics
uv build

The related unit tests pass (8 tests), the fatal flake8 check reports 0 errors,
and both the sdist and wheel build successfully. Live checks also confirmed that
format listing works for the reproducer and that a selected dash-audio-*
format downloads as an audio-only M4A file.


This change is Reviewable

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant