From 435fc7ade906162e0410e40844db03e9cecc69fb Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Tue, 12 Apr 2022 13:40:05 -0600 Subject: [PATCH] Merge pull request #7567 from cvium/fix_xmltv_caching (cherry picked from commit 385a0b94373606983051ff7662dfbe1e5514d4bc) Signed-off-by: Joshua Boniface --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 3da9d02b83..d56c9bb668 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; +using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using Jellyfin.Extensions; @@ -124,7 +125,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings { using (var stream = File.OpenRead(file)) { - string tempFolder = Path.Combine(_config.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString()); + string tempFolder = GetTempFolderPath(stream); Directory.CreateDirectory(tempFolder); _zipClient.ExtractFirstFileFromGz(stream, tempFolder, "data.xml"); @@ -137,7 +138,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings { using (var stream = File.OpenRead(file)) { - string tempFolder = Path.Combine(_config.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString()); + string tempFolder = GetTempFolderPath(stream); Directory.CreateDirectory(tempFolder); _zipClient.ExtractAllFromGz(stream, tempFolder, true); @@ -146,6 +147,16 @@ namespace Emby.Server.Implementations.LiveTv.Listings } } + private string GetTempFolderPath(Stream stream) + { +#pragma warning disable CA5351 + using var md5 = MD5.Create(); +#pragma warning restore CA5351 + var checksum = Convert.ToHexString(md5.ComputeHash(stream)); + stream.Position = 0; + return Path.Combine(_config.ApplicationPaths.TempDirectory, checksum); + } + private string FindXmlFile(string directory) { return _fileSystem.GetFiles(directory, true)