feat: resolve trial-only playback via trialDuration/effectiveDuration

VIP songs for non-VIP accounts return a ~30s trial fragment. The player used the full duration for isNearEnd, so the trial end didn't trigger auto-advance (~60s stall), and currentSong.duration stayed full, leaving the UI progress stuck.

- provider.ts: SongUrlResult {url, trialDuration?}; getSongUrl signature
- netease.ts: parseNeteaseTrial (freeTrialInfo start/end in seconds) + getSongUrl
- qq.ts: parseQqTrial (isTryout/tryEnd) + getSongUrl
- bilibili/youtube: getSongUrl returns {url}
- instance.ts: resolveAndPlay uses effectiveDuration = trialDuration ?? duration -> nearEnd at trial end -> native auto-advance; BotStatus.effectiveDuration
- VIP account: freeTrialInfo absent -> full duration -> full playback (no toggle)

Backward compatible (optional fields; getSongUrl has a single caller, updated).
Tests: parseTrial assertions (seconds/alias/ms-fallback). 14 pass.
This commit is contained in:
Slldyd2077 committed 2026-06-28 21:06:52 +08:00
1 parent 7b2bd0ea6a
commit fbb127a86d
8 files changed
+90 -16

No files matched your search

+14 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
import { mapQqAlbums, mapQqSongs } from "./qq.js";
import { mapQqAlbums, mapQqSongs, parseQqTrial } from "./qq.js";
describe("QQ adapter", () => {
it("mapQqSongs maps QQMusicApi-style song entries", () => {
@@ -40,6 +40,19 @@ describe("QQ adapter", () => {
expect(out[3].vip).toBe(false);
});
it("parseQqTrial maps isTryout/tryout to trial seconds", () => {
// 非试听(VIP/免费)
expect(parseQqTrial({ isTryout: 0 })).toBeUndefined();
expect(parseQqTrial({})).toBeUndefined();
// 试听(秒)
expect(parseQqTrial({ isTryout: 1, tryBegin: 0, tryEnd: 30 })).toBe(30);
expect(parseQqTrial({ tryout: true, begin: 0, end: 45 })).toBe(45);
// 毫秒兜底
expect(parseQqTrial({ isTryout: 1, tryBegin: 0, tryEnd: 30000 })).toBe(30);
// 异常
expect(parseQqTrial({ isTryout: 1, tryEnd: 0 })).toBeUndefined();
});
it("mapQqAlbums maps albumMID-style raw entries", () => {
const raw = [
{