The Free Software Media System - Server Backend & API
Set UserAgent when getting M3u playlist
crobibero6763d456fff5
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.csindex 8107bc427b..4b170b2e4e 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs@@ -65,7 +65,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts{var channelIdPrefix = GetFullChannelIdPrefix(info);- return await new M3uParser(Logger, _httpClientFactory, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);+ return await new M3uParser(Logger, _httpClientFactory, _appHost)+ .Parse(info, channelIdPrefix, cancellationToken)+ .ConfigureAwait(false);}public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)@@ -126,7 +128,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostspublic async Task Validate(TunerHostInfo info){- using (var stream = await new M3uParser(Logger, _httpClientFactory, _appHost).GetListingsStream(info.Url, CancellationToken.None).ConfigureAwait(false))+ using (var stream = await new M3uParser(Logger, _httpClientFactory, _appHost).GetListingsStream(info, CancellationToken.None).ConfigureAwait(false)){}}diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.csindex f066a749e3..c064e2fe6c 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs@@ -13,6 +13,7 @@ using MediaBrowser.Common.Extensions;using MediaBrowser.Common.Net;using MediaBrowser.Controller;using MediaBrowser.Controller.LiveTv;+using MediaBrowser.Model.LiveTv;using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.LiveTv.TunerHosts@@ -30,12 +31,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts_appHost = appHost;}- public async Task<List<ChannelInfo>> Parse(string url, string channelIdPrefix, string tunerHostId, CancellationToken cancellationToken)+ public async Task<List<ChannelInfo>> Parse(TunerHostInfo info, string channelIdPrefix, CancellationToken cancellationToken){// Read the file and display it line by line.- using (var reader = new StreamReader(await GetListingsStream(url, cancellationToken).ConfigureAwait(false)))+ using (var reader = new StreamReader(await GetListingsStream(info, cancellationToken).ConfigureAwait(false))){- return GetChannels(reader, channelIdPrefix, tunerHostId);+ return GetChannels(reader, channelIdPrefix, info.Id);}}@@ -48,15 +49,24 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts}}- public Task<Stream> GetListingsStream(string url, CancellationToken cancellationToken)+ public async Task<Stream> GetListingsStream(TunerHostInfo info, CancellationToken cancellationToken){- if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase))+ if (info.Url.StartsWith("http", StringComparison.OrdinalIgnoreCase)){- return _httpClientFactory.CreateClient(NamedClient.Default)- .GetStreamAsync(url);+ using var requestMessage = new HttpRequestMessage(HttpMethod.Get, info.Url);+ if (!string.IsNullOrEmpty(info.UserAgent))+ {+ requestMessage.Headers.UserAgent.TryParseAdd(info.UserAgent);+ }++ var response = await _httpClientFactory.CreateClient(NamedClient.Default)+ .SendAsync(requestMessage, cancellationToken)+ .ConfigureAwait(false);+ response.EnsureSuccessStatusCode();+ return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);}- return Task.FromResult((Stream)File.OpenRead(url));+ return File.OpenRead(info.Url);}private const string ExtInfPrefix = "#EXTINF:";