From 12c7e2cb77b4c4f5743480cb2bb689e90c0f22f5 Mon Sep 17 00:00:00 2001 From: Violet Caulfield <42452695+anultravioletaurora@users.noreply.github.com> Date: Sat, 7 Mar 2026 14:27:35 -0600 Subject: [PATCH] map downloaded media source info optimistically when mapping downloaded items to their respective tracks --- src/utils/mapping/item-to-track.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utils/mapping/item-to-track.ts b/src/utils/mapping/item-to-track.ts index f9e1ad3f..23ed0da3 100644 --- a/src/utils/mapping/item-to-track.ts +++ b/src/utils/mapping/item-to-track.ts @@ -8,10 +8,11 @@ import { convertRunTimeTicksToSeconds } from './ticks-to-seconds' import { DownloadQuality } from '../../stores/settings/usage' import StreamingQuality from '../../enums/audio-quality' import { getApi } from '../../stores' -import { TrackItem } from 'react-native-nitro-player' +import { DownloadManager, TrackItem } from 'react-native-nitro-player' import { formatArtistItemsNames } from '../formatting/artist-names' import { getBlurhashFromDto } from '../parsing/blurhash' import { slimifyDto } from './slimify-dto' +import { getTrackMediaSourceInfo } from './track-extra-payload' /** * Ensures a valid session ID is returned. @@ -105,11 +106,23 @@ export function getQualityParams( export function mapDtoToTrack(item: BaseItemDto): TrackItem { const api = getApi()! + const downloadedTracks = DownloadManager.getDownloadedTrack(item.Id!) + // Only include headers when we have an API token (streaming cases). For downloaded tracks it's not needed. const headers = (api as Api | undefined)?.accessToken ? { AUTHORIZATION: (api as Api).accessToken } : undefined + /** + * The mediaSourceInfo is used to store the MediaSourceInfo object from the Jellyfin server. + * + * In the cases of downloaded tracks, this should be populated ahead of time + * + * In the cases of streaming tracks, this will be populated later in the `onTracksNeedUpdate` + * callback when the MediaSourceInfo is needed from the server. + */ + const mediaSourceInfo = getTrackMediaSourceInfo(downloadedTracks?.originalTrack) ?? '{}' + return { ...(headers ? { headers } : {}), id: item.Id, @@ -121,7 +134,7 @@ export function mapDtoToTrack(item: BaseItemDto): TrackItem { artwork: getTrackArtworkUrl(api, item), extraPayload: { item: JSON.stringify(slimifyDto(item)), - mediaSourceInfo: '{}', // This will be populated later in the playback flow when we have the MediaSourceInfo available + mediaSourceInfo: JSON.stringify(mediaSourceInfo), // This will be populated later in the playback flow when we have the MediaSourceInfo available sessionId: '', blurhash: getBlurhashFromDto(item), } as TrackExtraPayload,