From 588f679703b26537e0252bd139c5e03220184488 Mon Sep 17 00:00:00 2001 From: uh wot Date: Fri, 19 Jul 2024 17:28:59 +0200 Subject: [PATCH] tidal: fix downloaded tracks missing last segment --- src/streamers/tidal/parse.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/streamers/tidal/parse.ts b/src/streamers/tidal/parse.ts index 6ffb797..780d434 100644 --- a/src/streamers/tidal/parse.ts +++ b/src/streamers/tidal/parse.ts @@ -174,10 +174,10 @@ export function parseMpd(mpdString: string): string[] { if (!initializationUrl) throw new Error('No initialization url') const mediaUrl = segTemplate.getAttribute('media') if (!mediaUrl) throw new Error('No media url') - const trackUrls = [] + let trackUrls = [initializationUrl] const timeline = segTemplate.querySelector('SegmentTimeline') if (timeline) { - const timeList = [] + let numSegments = 0 // let currentTime = 0 for (const s of [...timeline.querySelectorAll('S')]) { if (s.getAttribute('t')) { @@ -185,13 +185,13 @@ export function parseMpd(mpdString: string): string[] { } const r = parseInt(s.getAttribute('r') || '0') + 1 if (!s.getAttribute('d')) throw new Error('No d property on SegmentTimeline') - for (let i = 0; i < r; i++) { - timeList.push(0) - // currentTime += parseInt(s.getAttribute('d')) - } + numSegments += r + // for (let i = 0; i < r; i++) { + // currentTime += parseInt(s.getAttribute('d')) + // } } - for (const i in timeList) { - trackUrls.push(mediaUrl.replace('$Number$', i)) + for (let i = 1; i <= numSegments; i++) { + trackUrls.push(mediaUrl.replace('$Number$', i.toString())) } } tracks.push(trackUrls)