mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #1538 from joshuaboniface/epg
Try to fix XmlTvListingsProvider
This commit is contained in:
commit
cf2f5b2026
@ -291,7 +291,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
|||||||
options.CancellationToken.ThrowIfCancellationRequested();
|
options.CancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
return new HttpResponseInfo(response.Headers)
|
return new HttpResponseInfo(response.Headers, response.Content.Headers)
|
||||||
{
|
{
|
||||||
Content = stream,
|
Content = stream,
|
||||||
StatusCode = response.StatusCode,
|
StatusCode = response.StatusCode,
|
||||||
@ -313,7 +313,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
|||||||
await stream.CopyToAsync(memoryStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
await stream.CopyToAsync(memoryStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
||||||
memoryStream.Position = 0;
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
return new HttpResponseInfo(response.Headers)
|
return new HttpResponseInfo(response.Headers, response.Content.Headers)
|
||||||
{
|
{
|
||||||
Content = memoryStream,
|
Content = memoryStream,
|
||||||
StatusCode = response.StatusCode,
|
StatusCode = response.StatusCode,
|
||||||
@ -383,7 +383,7 @@ namespace Emby.Server.Implementations.HttpClientManager
|
|||||||
|
|
||||||
options.Progress.Report(100);
|
options.Progress.Report(100);
|
||||||
|
|
||||||
var responseInfo = new HttpResponseInfo(response.Headers)
|
var responseInfo = new HttpResponseInfo(response.Headers, response.Content.Headers)
|
||||||
{
|
{
|
||||||
TempFilePath = tempFile,
|
TempFilePath = tempFile,
|
||||||
StatusCode = response.StatusCode,
|
StatusCode = response.StatusCode,
|
||||||
|
@ -2,14 +2,15 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Emby.XmlTv.Classes;
|
using Emby.XmlTv.Classes;
|
||||||
using Emby.XmlTv.Entities;
|
using Emby.XmlTv.Entities;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Progress;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.LiveTv;
|
using MediaBrowser.Controller.LiveTv;
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
@ -27,7 +28,12 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IZipClient _zipClient;
|
private readonly IZipClient _zipClient;
|
||||||
|
|
||||||
public XmlTvListingsProvider(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IFileSystem fileSystem, IZipClient zipClient)
|
public XmlTvListingsProvider(
|
||||||
|
IServerConfigurationManager config,
|
||||||
|
IHttpClient httpClient,
|
||||||
|
ILogger logger,
|
||||||
|
IFileSystem fileSystem,
|
||||||
|
IZipClient zipClient)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
@ -52,7 +58,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
|
|
||||||
private async Task<string> GetXml(string path, CancellationToken cancellationToken)
|
private async Task<string> GetXml(string path, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("xmltv path: {path}", path);
|
_logger.LogInformation("xmltv path: {Path}", path);
|
||||||
|
|
||||||
if (!path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
if (!path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
@ -66,24 +72,33 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
return UnzipIfNeeded(path, cacheFile);
|
return UnzipIfNeeded(path, cacheFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("Downloading xmltv listings from {path}", path);
|
_logger.LogInformation("Downloading xmltv listings from {Path}", path);
|
||||||
|
|
||||||
string tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
|
|
||||||
{
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = path,
|
|
||||||
Progress = new SimpleProgress<double>(),
|
|
||||||
// It's going to come back gzipped regardless of this value
|
|
||||||
// So we need to make sure the decompression method is set to gzip
|
|
||||||
DecompressionMethod = CompressionMethod.Gzip,
|
|
||||||
|
|
||||||
UserAgent = "Emby/3.0"
|
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
|
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
|
||||||
|
|
||||||
File.Copy(tempFile, cacheFile, true);
|
using (var res = await _httpClient.SendAsync(
|
||||||
|
new HttpRequestOptions
|
||||||
|
{
|
||||||
|
CancellationToken = cancellationToken,
|
||||||
|
Url = path,
|
||||||
|
DecompressionMethod = CompressionMethod.Gzip,
|
||||||
|
},
|
||||||
|
HttpMethod.Get).ConfigureAwait(false))
|
||||||
|
using (var stream = res.Content)
|
||||||
|
using (var fileStream = new FileStream(cacheFile, FileMode.CreateNew))
|
||||||
|
{
|
||||||
|
if (res.ContentHeaders.ContentEncoding.Contains("gzip"))
|
||||||
|
{
|
||||||
|
using (var gzStream = new GZipStream(stream, CompressionMode.Decompress))
|
||||||
|
{
|
||||||
|
await gzStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return UnzipIfNeeded(path, cacheFile);
|
return UnzipIfNeeded(path, cacheFile);
|
||||||
}
|
}
|
||||||
@ -101,7 +116,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error extracting from gz file {file}", file);
|
_logger.LogError(ex, "Error extracting from gz file {File}", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -111,7 +126,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error extracting from zip file {file}", file);
|
_logger.LogError(ex, "Error extracting from zip file {File}", file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,20 +174,10 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
throw new ArgumentNullException(nameof(channelId));
|
throw new ArgumentNullException(nameof(channelId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
_logger.LogDebug("Getting xmltv programs for channel {Id}", channelId);
|
||||||
if (!await EmbyTV.EmbyTVRegistration.Instance.EnableXmlTv().ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
var length = endDateUtc - startDateUtc;
|
|
||||||
if (length.TotalDays > 1)
|
|
||||||
{
|
|
||||||
endDateUtc = startDateUtc.AddDays(1);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
_logger.LogDebug("Getting xmltv programs for channel {id}", channelId);
|
|
||||||
|
|
||||||
string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
||||||
_logger.LogDebug("Opening XmlTvReader for {path}", path);
|
_logger.LogDebug("Opening XmlTvReader for {Path}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
|
|
||||||
return reader.GetProgrammes(channelId, startDateUtc, endDateUtc, cancellationToken)
|
return reader.GetProgrammes(channelId, startDateUtc, endDateUtc, cancellationToken)
|
||||||
@ -265,7 +270,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
{
|
{
|
||||||
// In theory this should never be called because there is always only one lineup
|
// In theory this should never be called because there is always only one lineup
|
||||||
string path = await GetXml(info.Path, CancellationToken.None).ConfigureAwait(false);
|
string path = await GetXml(info.Path, CancellationToken.None).ConfigureAwait(false);
|
||||||
_logger.LogDebug("Opening XmlTvReader for {path}", path);
|
_logger.LogDebug("Opening XmlTvReader for {Path}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
IEnumerable<XmlTvChannel> results = reader.GetChannels();
|
IEnumerable<XmlTvChannel> results = reader.GetChannels();
|
||||||
|
|
||||||
@ -277,7 +282,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
{
|
{
|
||||||
// In theory this should never be called because there is always only one lineup
|
// In theory this should never be called because there is always only one lineup
|
||||||
string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
||||||
_logger.LogDebug("Opening XmlTvReader for {path}", path);
|
_logger.LogDebug("Opening XmlTvReader for {Path}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
var results = reader.GetChannels();
|
var results = reader.GetChannels();
|
||||||
|
|
||||||
|
@ -52,14 +52,21 @@ namespace MediaBrowser.Common.Net
|
|||||||
/// <value>The headers.</value>
|
/// <value>The headers.</value>
|
||||||
public HttpResponseHeaders Headers { get; set; }
|
public HttpResponseHeaders Headers { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the content headers.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The content headers.</value>
|
||||||
|
public HttpContentHeaders ContentHeaders { get; set; }
|
||||||
|
|
||||||
public HttpResponseInfo()
|
public HttpResponseInfo()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseInfo(HttpResponseHeaders headers)
|
public HttpResponseInfo(HttpResponseHeaders headers, HttpContentHeaders contentHeader)
|
||||||
{
|
{
|
||||||
Headers = headers;
|
Headers = headers;
|
||||||
|
ContentHeaders = contentHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user