aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs')
-rw-r--r--src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs b/src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs
index 318c3a2d36..ec2e6cfcc9 100644
--- a/src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs
+++ b/src/Jellyfin.LiveTv/Listings/XmlTvListingsProvider.cs
@@ -77,25 +77,39 @@ namespace Jellyfin.LiveTv.Listings
Directory.CreateDirectory(cacheDir);
}
- if (info.Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
+ try
{
- _logger.LogInformation("Downloading xmltv listings from {Path}", info.Path);
+ if (info.Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogInformation("Downloading xmltv listings from {Path}", info.Path);
- using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(info.Path, cancellationToken).ConfigureAwait(false);
- var redirectedUrl = response.RequestMessage?.RequestUri?.ToString() ?? info.Path;
- var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
- await using (stream.ConfigureAwait(false))
+ using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(info.Path, cancellationToken).ConfigureAwait(false);
+ var redirectedUrl = response.RequestMessage?.RequestUri?.ToString() ?? info.Path;
+ var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
+ await using (stream.ConfigureAwait(false))
+ {
+ return await UnzipIfNeededAndCopy(redirectedUrl, stream, cacheFile, cancellationToken).ConfigureAwait(false);
+ }
+ }
+ else
{
- return await UnzipIfNeededAndCopy(redirectedUrl, stream, cacheFile, cancellationToken).ConfigureAwait(false);
+ var stream = AsyncFile.OpenRead(info.Path);
+ await using (stream.ConfigureAwait(false))
+ {
+ return await UnzipIfNeededAndCopy(info.Path, stream, cacheFile, cancellationToken).ConfigureAwait(false);
+ }
}
}
- else
+ catch (Exception ex)
{
- var stream = AsyncFile.OpenRead(info.Path);
- await using (stream.ConfigureAwait(false))
+ _logger.LogError(ex, "Error downloading or processing XMLTV file from {Path}", info.Path);
+
+ if (File.Exists(cacheFile))
{
- return await UnzipIfNeededAndCopy(info.Path, stream, cacheFile, cancellationToken).ConfigureAwait(false);
+ File.Delete(cacheFile);
}
+
+ throw;
}
}
@@ -128,9 +142,20 @@ namespace Jellyfin.LiveTv.Listings
{
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
}
+ }
+
+ var fileInfo = new FileInfo(file);
+ if (!fileInfo.Exists || fileInfo.Length == 0)
+ {
+ if (fileInfo.Exists)
+ {
+ File.Delete(file);
+ }
- return file;
+ throw new InvalidOperationException("Downloaded XMLTV file is empty: " + originalUrl);
}
+
+ return file;
}
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)