Skip to content

[Bug]: [BiliBili] 下载B站分part视频时报错:KeyError: 'id' #817

@BrandonLittle666

Description

@BrandonLittle666

Prerequisites

  • I have searched existing issues and discussions to ensure this bug hasn't been reported before
  • I have read the troubleshooting section in the README
  • I have tested this issue with yt-dlp directly (not just through MeTube UI) as described in the README
  • I have checked that this is not a yt-dlp issue (if it is, please report it to yt-dlp repository instead)

Bug Description

尽管 #552 中提到过这个问题并且该issue提示已经解决了,但我测试了一下还是有bug, 看起来报错的位置并不相同。下载B站分part视频的时候,如果设置Strict Playlist Mode模式,只能下载到一个视频,如果不设置,就会报错:

INFO:main:Received request to add download

INFO:main:Request data: {'url': 'https://www.bilibili.com/video/BV1g3411z72f', 'quality': 'best', 'format': 'any', 'playlist_strict_mode': False, 'auto_start': True}

INFO:ytdl:adding https://www.bilibili.com/video/BV1g3411z72f: quality='best' format='any' already=None folder=None custom_name_prefix='' playlist_strict_mode=False playlist_item_limit=0 auto_start=True

INFO:ytdl:playlist detected with 5 entries

ERROR:aiohttp.server:Error handling request from 172.21.0.1

Traceback (most recent call last):

  File "/usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py", line 510, in _handle_request

    resp = await request_handler(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.13/site-packages/aiohttp/web_app.py", line 569, in _handle

    return await handler(request)

           ^^^^^^^^^^^^^^^^^^^^^^

  File "/app/app/main.py", line 238, in add

    status = await dqueue.add(url, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start)

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/app/ytdl.py", line 416, in add

    return await self.__add_entry(entry, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start, already)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/app/ytdl.py", line 391, in __add_entry

    results.append(await self.__add_entry(etr, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start, already))

                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/app/ytdl.py", line 399, in __add_entry

    dl = DownloadInfo(entry['id'], entry.get('title') or entry['id'], key, quality, format, folder, custom_name_prefix, error, entry, playlist_item_limit)

                      ~~~~~^^^^^^

KeyError: 'id'

经测试上述错误仅在分part视频中出现,合集时可以正常下载的。 我调试了一下发现是没有正确处理id这个键,一个绕过的方法是在遍历entry的时候强制加上id

    async def __add_entry(self, entry, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start, already):
        ...
        elif etype == 'playlist':
            log.debug('Processing as a playlist')
            entries = entry['entries']
            log.info(f'playlist detected with {len(entries)} entries')
            playlist_index_digits = len(str(len(entries)))
            results = []
            if playlist_item_limit > 0:
                log.info(f'Playlist item limit is set. Processing only first {playlist_item_limit} entries')
                entries = entries[:playlist_item_limit]
            for index, etr in enumerate(entries, start=1):
                etr["_type"] = "video"
                etr['id'] = etr.get('id', entry['id'])     # 👈👈👈 如果没有列表元素没有id,使用列表本身的id

报错的视频是 https://www.bilibili.com/video/BV1g3411z72f,实测加上最后这一行后可以下载了。

不过美中不足是,实际上还是没有解决分p视频解析中的id/title问题,导致webUI没有正确显示每个part的标题,而是id。

Image

yt-dlp Direct Test Results

yt-dlp https://www.bilibili.com/video/BV1g3411z72f

正常下载

Environment & Configuration

docker-compose:

version: "3"
services:
 metube:
   image: alexta69/metube:2025.10.23
   container_name: metube
   restart: unless-stopped
   ports:
     - "58081:8081" # Web UI 端口
   volumes:
     - /vol1/1000/downloads:/downloads # 下载目录
     - ./temp:/temp # 临时缓存目录
   environment:
     - DOWNLOAD_DIR=/downloads/metube # 视频下载路径
     - TEMP_DIR=/temp # 临时文件路径
     - UID=1000 # 用户 ID
     - GID=1000 # 用户组 ID
     - UMASK=022 # 文件权限掩码
     - TZ=Asia/Shanghai # 时区设置

System:

CPU AMD Ryzen 7 7840H w/ Radeon 780M Graphics 8 核 16线程
运行内存 2条共 32 GB 5600MHz DDR5
GPU AMD Radeon 780M Graphics

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions