mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
Restore latest version
Source: 30baa15839/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs
This commit is contained in:
parent
6ebb00549b
commit
baa2afb61e
1 changed files with 53 additions and 9 deletions
|
@ -101,6 +101,45 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
||||||
var ext = Path.GetExtension(originalUrl.Split('?')[0]);
|
var ext = Path.GetExtension(originalUrl.Split('?')[0]);
|
||||||
|
|
||||||
if (string.Equals(ext, ".gz", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(ext, ".gz", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tempFolder = ExtractGz(file);
|
||||||
|
return FindXmlFile(tempFolder);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error extracting from gz file {0}", ex, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tempFolder = ExtractFirstFileFromGz(file);
|
||||||
|
return FindXmlFile(tempFolder);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error extracting from zip file {0}", ex, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ExtractFirstFileFromGz(string file)
|
||||||
|
{
|
||||||
|
using (var stream = _fileSystem.OpenRead(file))
|
||||||
|
{
|
||||||
|
var tempFolder = Path.Combine(_config.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString());
|
||||||
|
_fileSystem.CreateDirectory(tempFolder);
|
||||||
|
|
||||||
|
_zipClient.ExtractFirstFileFromGz(stream, tempFolder, "data.xml");
|
||||||
|
|
||||||
|
return tempFolder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ExtractGz(string file)
|
||||||
{
|
{
|
||||||
using (var stream = _fileSystem.OpenRead(file))
|
using (var stream = _fileSystem.OpenRead(file))
|
||||||
{
|
{
|
||||||
|
@ -109,14 +148,16 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
||||||
|
|
||||||
_zipClient.ExtractAllFromGz(stream, tempFolder, true);
|
_zipClient.ExtractAllFromGz(stream, tempFolder, true);
|
||||||
|
|
||||||
return _fileSystem.GetFiles(tempFolder, true)
|
return tempFolder;
|
||||||
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
|
||||||
.Select(i => i.FullName)
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
private string FindXmlFile(string directory)
|
||||||
|
{
|
||||||
|
return _fileSystem.GetFiles(directory, true)
|
||||||
|
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.Select(i => i.FullName)
|
||||||
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
|
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
|
||||||
|
@ -139,6 +180,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
||||||
_logger.Debug("Getting xmltv programs for channel {0}", channelId);
|
_logger.Debug("Getting xmltv programs for channel {0}", channelId);
|
||||||
|
|
||||||
var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
||||||
|
_logger.Debug("Opening XmlTvReader for {0}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
|
|
||||||
var results = reader.GetProgrammes(channelId, startDateUtc, endDateUtc, cancellationToken);
|
var results = reader.GetProgrammes(channelId, startDateUtc, endDateUtc, cancellationToken);
|
||||||
|
@ -232,6 +274,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
|
||||||
var path = await GetXml(info.Path, CancellationToken.None).ConfigureAwait(false);
|
var path = await GetXml(info.Path, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
_logger.Debug("Opening XmlTvReader for {0}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
var results = reader.GetChannels();
|
var results = reader.GetChannels();
|
||||||
|
|
||||||
|
@ -243,6 +286,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
|
||||||
var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
|
||||||
|
_logger.Debug("Opening XmlTvReader for {0}", path);
|
||||||
var reader = new XmlTvReader(path, GetLanguage(info));
|
var reader = new XmlTvReader(path, GetLanguage(info));
|
||||||
var results = reader.GetChannels();
|
var results = reader.GetChannels();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue