diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 4668b8bbb..4dbefca4b 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -418,9 +418,24 @@ namespace MediaBrowser.MediaEncoding.Encoder public Task GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken) { var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters; - 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) @@ -442,15 +457,12 @@ namespace MediaBrowser.MediaEncoding.Encoder extraArgs += " -probesize " + ffmpegProbeSize; } - return GetMediaInfoInternal( - GetInputArgument(request.MediaSource.Path, request.MediaSource), - request.MediaSource.Path, - request.MediaSource.Protocol, - extractChapters, - extraArgs, - request.MediaType == DlnaProfileType.Audio, - request.MediaSource.VideoType, - cancellationToken); + if (request.MediaSource.RequiredHttpHeaders.TryGetValue("user_agent", out var userAgent)) + { + extraArgs += " -user_agent " + userAgent; + } + + return extraArgs; } /// diff --git a/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs new file mode 100644 index 000000000..263f74c90 --- /dev/null +++ b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeExternalSourcesTests.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.MediaEncoding.Encoder; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.MediaInfo; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Moq; +using Xunit; + +namespace Jellyfin.MediaEncoding.Tests.Probing +{ + public class ProbeExternalSourcesTests + { + [Fact] + public void GetExtraArguments_Forwards_UserAgent() + { + var encoder = new MediaEncoder( + Mock.Of>(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + 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 + { + Path = "/path/to/stream", + Protocol = MediaProtocol.Http, + RequiredHttpHeaders = new Dictionary() + { + { "user_agent", userAgent }, + } + }, + ExtractChapters = false, + MediaType = MediaBrowser.Model.Dlna.DlnaProfileType.Video, + }; + + var extraArg = encoder.GetExtraArguments(req); + + Assert.Contains(userAgent, extraArg, StringComparison.InvariantCulture); + } + } +}