diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index e8041f198..4dbefca4b 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -418,10 +418,24 @@ namespace MediaBrowser.MediaEncoding.Encoder public Task GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken) { var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters; - var requiredHeaders = request.MediaSource.RequiredHttpHeaders; - var analyzeDuration = string.Empty; + var extraArgs = GetExtraArguments(request); + + return GetMediaInfoInternal( + GetInputArgument(request.MediaSource.Path, request.MediaSource), + request.MediaSource.Path, + request.MediaSource.Protocol, + extractChapters, + extraArgs, + request.MediaType == DlnaProfileType.Audio, + request.MediaSource.VideoType, + cancellationToken); + } + + internal string GetExtraArguments(MediaInfoRequest request) + { var ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty; var ffmpegProbeSize = _config.GetFFmpegProbeSize() ?? string.Empty; + var analyzeDuration = string.Empty; var extraArgs = string.Empty; if (request.MediaSource.AnalyzeDurationMs > 0) @@ -443,20 +457,12 @@ namespace MediaBrowser.MediaEncoding.Encoder extraArgs += " -probesize " + ffmpegProbeSize; } - if (requiredHeaders.ContainsKey("user_agent")) + if (request.MediaSource.RequiredHttpHeaders.TryGetValue("user_agent", out var userAgent)) { - extraArgs += " -user_agent " + requiredHeaders["user_agent"]; + extraArgs += " -user_agent " + userAgent; } - return GetMediaInfoInternal( - GetInputArgument(request.MediaSource.Path, request.MediaSource), - request.MediaSource.Path, - request.MediaSource.Protocol, - extractChapters, - extraArgs, - request.MediaType == DlnaProfileType.Audio, - request.MediaSource.VideoType, - cancellationToken); + return extraArgs; } /// diff --git a/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs index 17f8ec163..263f74c90 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs @@ -1,5 +1,5 @@ +using System; using System.Collections.Generic; -using System.Threading; using MediaBrowser.Controller.Configuration; using MediaBrowser.MediaEncoding.Encoder; using MediaBrowser.Model.Globalization; @@ -15,7 +15,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing public class ProbeExternalSourcesTests { [Fact] - public void GetMediaInfo_Uses_UserAgent() + public void GetExtraArguments_Forwards_UserAgent() { var encoder = new MediaEncoder( Mock.Of>(), @@ -26,6 +26,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing new ConfigurationBuilder().Build(), Mock.Of()); + var userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"; var req = new MediaBrowser.Controller.MediaEncoding.MediaInfoRequest() { MediaSource = new MediaBrowser.Model.Dto.MediaSourceInfo @@ -34,14 +35,16 @@ namespace Jellyfin.MediaEncoding.Tests.Probing Protocol = MediaProtocol.Http, RequiredHttpHeaders = new Dictionary() { - { "user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/530.35 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/530.35" }, + { "user_agent", userAgent }, } }, ExtractChapters = false, MediaType = MediaBrowser.Model.Dlna.DlnaProfileType.Video, }; - encoder.GetMediaInfo(req, CancellationToken.None); + var extraArg = encoder.GetExtraArguments(req); + + Assert.Contains(userAgent, extraArg, StringComparison.InvariantCulture); } } }