Skip to content

fix: missing dependencies, connection resets on /api/ endpoints, and large-playlist parsing failures - #3

Open
policej wants to merge 3 commits into
toki-plus:mainfrom
policej:fix/deps-and-api-reliability
Open

fix: missing dependencies, connection resets on /api/ endpoints, and large-playlist parsing failures#3
policej wants to merge 3 commits into
toki-plus:mainfrom
policej:fix/deps-and-api-reliability

Conversation

@policej

@policej policej commented Jul 2, 2026

Copy link
Copy Markdown

本 PR 修复了三个实际使用中遇到并逐一定位的问题(Windows 11 / Python 3.13 真实账号验证):

1. requirements.txt 缺少 aiohttpaiofiles

music_downloader.py 引用了这两个库,但依赖清单未列出,按 README 全新安装后启动即报 ModuleNotFoundError: No module named 'aiohttp'

2. 普通 /api/ 接口未携带默认设备 cookie,导致连接被服务器重置

interface3.music.163.com 对不带 os=pc / deviceId 等默认 cookie 的 /api/ 请求会直接重置连接(Windows 上表现为 ConnectionResetError(10054))。eapi 通道在 HTTPClient.post_request 中已正确合并 DEFAULT_COOKIES,但 get_song_detail(完全未带 cookie)、get_lyricget_playlist_detail(仅带登录 cookie)没有合并,导致单曲解析、歌词、歌单解析在部分账号/网络环境下必然失败。已实测对照:同一请求带设备 cookie 返回 200,不带则被掐断。

3. 歌单解析每批 100 首、无重试,大歌单几乎必失败

interface3 负载下经常重置连接,原实现任何一批失败即整单报废。改为每批 10 首、批间隔 1 秒、每批最多重试 3 次(2s/4s 退避)、超时放宽至 15 秒。168 首歌单实测:改前必失败,改后稳定解析。

(English summary) 1) Add missing aiohttp/aiofiles deps; 2) merge default device cookies into plain /api/ endpoints to stop server-side connection resets; 3) fetch playlist song details in batches of 10 with retry/backoff instead of 100 with none.

🤖 Generated with Claude Code

policej and others added 3 commits July 2, 2026 21:09
music_downloader.py imports aiohttp and aiofiles for async batch
downloads, but neither is listed in requirements.txt, so a fresh
install following the README fails on startup with
ModuleNotFoundError: No module named 'aiohttp'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nnection resets

interface3.music.163.com rejects plain /api/ requests that lack the
default device cookies (os=pc, deviceId, ...) by resetting the TCP
connection (ConnectionResetError 10054 on Windows, SSL EOF behind
some networks). The eapi endpoints already merge DEFAULT_COOKIES in
HTTPClient.post_request, but get_song_detail sent no cookies at all,
and get_lyric / get_playlist_detail forwarded only the login cookie
(MUSIC_U), so single-song parsing, lyrics and playlist parsing failed
for affected accounts/networks.

Merge DEFAULT_COOKIES with the login cookies on these three endpoints,
matching the behavior of the eapi channel. Verified against a live
account: identical request succeeds with the device cookies and is
reset without them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The playlist parser fetched song details in batches of 100 with a 5s
timeout and no retry, so a single dropped request (interface3 resets
connections under load fairly often) failed the whole playlist parse.
Large playlists rarely survived.

Fetch in batches of 10 with a 1s pause between batches, retry each
batch up to 3 times with backoff, and allow a 15s timeout for the
larger responses. Verified with a 168-track playlist that previously
always failed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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