api/xiaohongshu: deduplicate h264 stream extraction

reduce() isn't called on 1 item arrays, so this is just fine

Co-authored-by: jj <log@riseup.net>
This commit is contained in:
wukko 2025-01-20 19:41:02 +06:00 committed by GitHub
parent 4963c9f128
commit e39b0ae7b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,12 +75,9 @@ export default async function ({ id, token, shareId, h265, isAudioOnly, dispatch
if (!videoURL) { if (!videoURL) {
const h264Streams = video.media?.stream?.h264; const h264Streams = video.media?.stream?.h264;
if (!h264Streams) return { error: "fetch.empty" };
if (h264Streams.length > 1) { if (h264Streams?.length) {
videoURL = h264Streams.reduce((a, b) => Number(a?.videoBitrate) > Number(b?.videoBitrate) ? a : b).masterUrl; videoURL = h264Streams.reduce((a, b) => Number(a?.videoBitrate) > Number(b?.videoBitrate) ? a : b).masterUrl;
} else {
videoURL = h264Streams[0].masterUrl;
} }
} }