Forward user_agent config to ffprobe

This commit is contained in:
Vincent Lark 2023-10-21 23:57:05 +02:00
parent df7032b09e
commit 8ee9a0adf9
2 changed files with 53 additions and 0 deletions

View File

@ -418,6 +418,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public Task<MediaInfo> GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken)
{
var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;
var requiredHeaders = request.MediaSource.RequiredHttpHeaders;
var analyzeDuration = string.Empty;
var ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
var ffmpegProbeSize = _config.GetFFmpegProbeSize() ?? string.Empty;
@ -442,6 +443,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
extraArgs += " -probesize " + ffmpegProbeSize;
}
if (requiredHeaders.ContainsKey("user_agent"))
{
extraArgs += " -user_agent " + requiredHeaders["user_agent"];
}
return GetMediaInfoInternal(
GetInputArgument(request.MediaSource.Path, request.MediaSource),
request.MediaSource.Path,

View File

@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Threading;
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 GetMediaInfo_Uses_UserAgent()
{
var encoder = new MediaEncoder(
Mock.Of<ILogger<MediaEncoder>>(),
Mock.Of<IServerConfigurationManager>(),
Mock.Of<IFileSystem>(),
Mock.Of<IBlurayExaminer>(),
Mock.Of<ILocalizationManager>(),
new ConfigurationBuilder().Build(),
Mock.Of<IServerConfigurationManager>());
var req = new MediaBrowser.Controller.MediaEncoding.MediaInfoRequest()
{
MediaSource = new MediaBrowser.Model.Dto.MediaSourceInfo
{
Path = "/path/to/stream",
Protocol = MediaProtocol.Http,
RequiredHttpHeaders = new Dictionary<string, string>()
{
{ "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" },
}
},
ExtractChapters = false,
MediaType = MediaBrowser.Model.Dlna.DlnaProfileType.Video,
};
encoder.GetMediaInfo(req, CancellationToken.None);
}
}
}