mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Properly stream M3U file over http
This commit is contained in:
parent
0c9f824d0a
commit
6c42d2345d
@ -83,9 +83,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var channels = await GetChannels(host, enableCache, cancellationToken).ConfigureAwait(false);
|
var channels = await GetChannels(host, enableCache, cancellationToken).ConfigureAwait(false);
|
||||||
var newChannels = channels.Where(i => !list.Any(l => string.Equals(i.Id, l.Id, StringComparison.OrdinalIgnoreCase))).ToList();
|
|
||||||
|
|
||||||
list.AddRange(newChannels);
|
list.AddRange(channels);
|
||||||
|
|
||||||
if (!enableCache)
|
if (!enableCache)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,6 @@ using System.Threading.Tasks;
|
|||||||
using Jellyfin.Extensions;
|
using Jellyfin.Extensions;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Controller.LiveTv;
|
using MediaBrowser.Controller.LiveTv;
|
||||||
using MediaBrowser.Model.LiveTv;
|
using MediaBrowser.Model.LiveTv;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -44,22 +43,28 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||||||
|
|
||||||
public async Task<Stream> GetListingsStream(TunerHostInfo info, CancellationToken cancellationToken)
|
public async Task<Stream> GetListingsStream(TunerHostInfo info, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (info.Url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
if (info == null)
|
||||||
{
|
{
|
||||||
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, info.Url);
|
throw new ArgumentNullException(nameof(info));
|
||||||
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(cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return File.OpenRead(info.Url);
|
if (!info.Url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return File.OpenRead(info.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, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
return await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<ChannelInfo>> GetChannelsAsync(TextReader reader, string channelIdPrefix, string tunerHostId)
|
private async Task<List<ChannelInfo>> GetChannelsAsync(TextReader reader, string channelIdPrefix, string tunerHostId)
|
||||||
@ -83,7 +88,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||||||
if (trimmedLine.StartsWith(ExtInfPrefix, StringComparison.OrdinalIgnoreCase))
|
if (trimmedLine.StartsWith(ExtInfPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
extInf = trimmedLine.Substring(ExtInfPrefix.Length).Trim();
|
extInf = trimmedLine.Substring(ExtInfPrefix.Length).Trim();
|
||||||
_logger.LogInformation("Found m3u channel: {0}", extInf);
|
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrWhiteSpace(extInf) && !trimmedLine.StartsWith('#'))
|
else if (!string.IsNullOrWhiteSpace(extInf) && !trimmedLine.StartsWith('#'))
|
||||||
{
|
{
|
||||||
@ -99,6 +103,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||||||
|
|
||||||
channel.Path = trimmedLine;
|
channel.Path = trimmedLine;
|
||||||
channels.Add(channel);
|
channels.Add(channel);
|
||||||
|
_logger.LogInformation("Parsed channel: {0}", channel.Name);
|
||||||
extInf = string.Empty;
|
extInf = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user