< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.VideoAttachmentsController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/VideoAttachmentsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 85
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 0% (0/6) Total lines: 844/19/2026 - 12:14:27 AM Line coverage: 0% (0/22) Branch coverage: 0% (0/4) Total lines: 844/27/2026 - 12:15:04 AM Line coverage: 0% (0/22) Branch coverage: 0% (0/4) Total lines: 85 4/19/2026 - 12:14:27 AM Line coverage: 0% (0/22) Branch coverage: 0% (0/4) Total lines: 844/27/2026 - 12:15:04 AM Line coverage: 0% (0/22) Branch coverage: 0% (0/4) Total lines: 85

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetAttachment()0%2040%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/VideoAttachmentsController.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using System.Net.Mime;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Jellyfin.Api.Attributes;
 7using Jellyfin.Api.Extensions;
 8using Jellyfin.Api.Helpers;
 9using MediaBrowser.Common.Extensions;
 10using MediaBrowser.Controller.Entities;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Controller.MediaEncoding;
 13using Microsoft.AspNetCore.Http;
 14using Microsoft.AspNetCore.Mvc;
 15
 16namespace Jellyfin.Api.Controllers;
 17
 18/// <summary>
 19/// Attachments controller.
 20/// </summary>
 21[Route("Videos")]
 22[Tags("Video")]
 23public class VideoAttachmentsController : BaseJellyfinApiController
 24{
 25    private readonly ILibraryManager _libraryManager;
 26    private readonly IAttachmentExtractor _attachmentExtractor;
 27
 28    /// <summary>
 29    /// Initializes a new instance of the <see cref="VideoAttachmentsController"/> class.
 30    /// </summary>
 31    /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 32    /// <param name="attachmentExtractor">Instance of the <see cref="IAttachmentExtractor"/> interface.</param>
 033    public VideoAttachmentsController(
 034        ILibraryManager libraryManager,
 035        IAttachmentExtractor attachmentExtractor)
 36    {
 037        _libraryManager = libraryManager;
 038        _attachmentExtractor = attachmentExtractor;
 039    }
 40
 41    /// <summary>
 42    /// Get video attachment.
 43    /// </summary>
 44    /// <param name="videoId">Video ID.</param>
 45    /// <param name="mediaSourceId">Media Source ID.</param>
 46    /// <param name="index">Attachment Index.</param>
 47    /// <response code="200">Attachment retrieved.</response>
 48    /// <response code="404">Video or attachment not found.</response>
 49    /// <returns>An <see cref="FileStreamResult"/> containing the attachment stream on success, or a <see cref="NotFound
 50    [HttpGet("{videoId}/{mediaSourceId}/Attachments/{index}")]
 51    [ProducesFile(MediaTypeNames.Application.Octet)]
 52    [ProducesResponseType(StatusCodes.Status200OK)]
 53    [ProducesResponseType(StatusCodes.Status404NotFound)]
 54    public async Task<ActionResult> GetAttachment(
 55        [FromRoute, Required] Guid videoId,
 56        [FromRoute, Required] string mediaSourceId,
 57        [FromRoute, Required] int index)
 58    {
 59        try
 60        {
 061            var item = _libraryManager.GetItemById<BaseItem>(videoId, User.GetUserId());
 062            if (item is null)
 63            {
 064                return NotFound();
 65            }
 66
 067            var (attachment, stream) = await _attachmentExtractor.GetAttachment(
 068                    item,
 069                    mediaSourceId,
 070                    index,
 071                    CancellationToken.None)
 072                .ConfigureAwait(false);
 73
 074            var contentType = string.IsNullOrWhiteSpace(attachment.MimeType)
 075                ? MediaTypeNames.Application.Octet
 076                : attachment.MimeType;
 77
 078            return new FileStreamResult(stream, contentType);
 79        }
 080        catch (ResourceNotFoundException e)
 81        {
 082            return NotFound(e.Message);
 83        }
 084    }
 85}