Skip to content

Commit cb42c27

Browse files
committed
fix: avoid weak cover flicker during loading
1 parent a11436e commit cb42c27

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/lib/mergePlayerMedia.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import type { Media } from "@/interfaces";
2-
import { upgradeCoverUrl } from "@/lib/coverUrl";
2+
import { isWeakYtimgCoverUrl, upgradeCoverUrl } from "@/lib/coverUrl";
33
import { mergeTrackMetadata, peekSearchMeta } from "@/lib/searchMeta";
44
import { getYouTubeId } from "@/utils";
55
import { isSameMediaSource } from "@/utils/player";
66

77
function coverProxyUrl(raw: string | undefined, ytId: string | null): string {
8-
if (!raw) {
9-
return ytId
10-
? `/api/cover?url=${encodeURIComponent(`https://i.ytimg.com/vi/${ytId}/maxresdefault.jpg`)}`
11-
: "";
12-
}
8+
if (!raw) return "";
139
if (
1410
raw.startsWith("/api/cover") ||
1511
raw.startsWith("blob:") ||
@@ -22,6 +18,16 @@ function coverProxyUrl(raw: string | undefined, ytId: string | null): string {
2218

2319
/** Normalize a cover URL for <Image> display (proxy remote CDN URLs). */
2420
export function toDisplayCoverUrl(raw: string | undefined, ytId: string | null): string {
21+
return (
22+
coverProxyUrl(raw, ytId) ||
23+
(ytId
24+
? `/api/cover?url=${encodeURIComponent(`https://i.ytimg.com/vi/${ytId}/maxresdefault.jpg`)}`
25+
: "")
26+
);
27+
}
28+
29+
function trustedProvisionalCover(raw: string | undefined, ytId: string | null): string {
30+
if (!raw || isWeakYtimgCoverUrl(raw)) return "";
2531
return coverProxyUrl(raw, ytId);
2632
}
2733

@@ -41,7 +47,7 @@ export function buildProvisionalMedia(
4147
author: initialMeta.author || "Unknown",
4248
artist: initialMeta.artist || undefined,
4349
album: initialMeta.album || undefined,
44-
coverUrl: coverProxyUrl(initialMeta.coverUrl, ytId),
50+
coverUrl: trustedProvisionalCover(initialMeta.coverUrl, ytId),
4551
},
4652
};
4753
}
@@ -52,7 +58,7 @@ export function buildProvisionalMedia(
5258
id: ytId || null,
5359
title: "",
5460
author: "",
55-
coverUrl: coverProxyUrl(undefined, ytId),
61+
coverUrl: "",
5662
},
5763
};
5864
}

0 commit comments

Comments
 (0)