{"record":{"id":"c04aa536c330b742","repo":"jellyfin/jellyfin","slug":"mediasource-mediasourceid-not-found","errorCode":null,"errorMessage":"MediaSource {mediaSourceId} not found","messagePattern":"MediaSource (.+?) not found","errorType":"http","errorClass":"ResourceNotFoundException","httpStatus":404,"severity":"error","filePath":"MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs","lineNumber":77,"sourceCode":"            _pathManager = pathManager;\n        }\n\n        /// <inheritdoc />\n        public async Task<(MediaAttachment Attachment, Stream Stream)> GetAttachment(BaseItem item, string mediaSourceId, int attachmentStreamIndex, CancellationToken cancellationToken)\n        {\n            ArgumentNullException.ThrowIfNull(item);\n\n            if (string.IsNullOrWhiteSpace(mediaSourceId))\n            {\n                throw new ArgumentNullException(nameof(mediaSourceId));\n            }\n\n            var mediaSources = await _mediaSourceManager.GetPlaybackMediaSources(item, null, true, false, cancellationToken).ConfigureAwait(false);\n            var mediaSource = mediaSources\n                .FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));\n            if (mediaSource is null)\n            {\n                throw new ResourceNotFoundException($\"MediaSource {mediaSourceId} not found\");\n            }\n\n            var mediaAttachment = mediaSource.MediaAttachments\n                .FirstOrDefault(i => i.Index == attachmentStreamIndex);\n            if (mediaAttachment is null)\n            {\n                throw new ResourceNotFoundException($\"MediaSource {mediaSourceId} has no attachment with stream index {attachmentStreamIndex}\");\n            }\n\n            if (string.Equals(mediaAttachment.Codec, \"mjpeg\", StringComparison.OrdinalIgnoreCase))\n            {\n                throw new ResourceNotFoundException($\"Attachment with stream index {attachmentStreamIndex} can't be extracted for MediaSource {mediaSourceId}\");\n            }\n\n            var attachmentStream = await GetAttachmentStream(mediaSource, mediaAttachment, cancellationToken)\n                    .ConfigureAwait(false);\n\n            return (mediaAttachment, attachmentStream);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/jellyfin/jellyfin/blob/ae8723026d97b6d0f926638803edef338919b794/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs#L59-L95","documentation":"Lookup miss in AttachmentExtractor.GetFileSuffixes/ExtractAttachment entry point. The requested mediaSourceId is resolved against the item's playback media sources (case-insensitive Id match) and nothing matches, so no attachment can be addressed. Thrown as ResourceNotFoundException, which the API layer maps to 404.","triggerScenarios":"_mediaSourceManager.GetPlaybackMediaSources(item, null, true, false, ct) returns a list in which no source has an Id equal to the requested mediaSourceId (OrdinalIgnoreCase).","commonSituations":"Stale mediaSourceId cached by a client after a library refresh regenerated source IDs; the item genuinely has no media sources (empty/unreadable file); permission or path issue suppressing sources; requesting an attachment for a Live TV stream whose Id is ephemeral.","solutions":["Have the client re-fetch the item's MediaSources and use a current Id.","Confirm the underlying media file is readable and present.","If the source is dynamic (Live TV), do not call attachment extraction — it has no persistent Id."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Resolve a current media source before attachment calls.\nvar sources = await _mediaSourceManager.GetPlaybackMediaSources(item, null, true, false, ct);\nvar src = sources.FirstOrDefault(s => string.Equals(s.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));\nif (src is null) return NotFound(); // don't call the extractor","typeGuard":null,"tryCatchPattern":"try { await attachmentExtractor.ExtractAttachment(item, mediaSourceId, idx, ct); }\ncatch (ResourceNotFoundException ex) when (ex.Message.StartsWith(\"MediaSource \"))\n{\n    logger.LogWarning(\"Stale or unknown mediaSourceId {Id}.\", mediaSourceId);\n    return NotFound();\n}","preventionTips":["Have clients always re-fetch MediaSources before requesting attachments.","Do not cache mediaSourceId across library refreshes.","Avoid attachment extraction on dynamic/Live TV sources."],"tags":["media-source","attachment","media-encoding","not-found"],"backgroundTag":null,"analyzedSha":"ae8723026d97b6d0f926638803edef338919b794","analyzedAt":"2026-08-13T10:43:30.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}