mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	Merge pull request #6551 from MrChip53/xmltv-improve
This commit is contained in:
		
						commit
						26cfde8765
					
				@ -60,34 +60,34 @@ namespace Emby.Server.Implementations.LiveTv.Listings
 | 
				
			|||||||
            return _config.Configuration.PreferredMetadataLanguage;
 | 
					            return _config.Configuration.PreferredMetadataLanguage;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private async Task<string> GetXml(string path, CancellationToken cancellationToken)
 | 
					        private async Task<string> GetXml(ListingsProviderInfo info, CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _logger.LogInformation("xmltv path: {Path}", path);
 | 
					            _logger.LogInformation("xmltv path: {Path}", info.Path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
 | 
					            if (!info.Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return UnzipIfNeeded(path, path);
 | 
					                return UnzipIfNeeded(info.Path, info.Path);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            string cacheFilename = DateTime.UtcNow.DayOfYear.ToString(CultureInfo.InvariantCulture) + "-" + DateTime.UtcNow.Hour.ToString(CultureInfo.InvariantCulture) + ".xml";
 | 
					            string cacheFilename = DateTime.UtcNow.DayOfYear.ToString(CultureInfo.InvariantCulture) + "-" + DateTime.UtcNow.Hour.ToString(CultureInfo.InvariantCulture) + "-" + info.Id + ".xml";
 | 
				
			||||||
            string cacheFile = Path.Combine(_config.ApplicationPaths.CachePath, "xmltv", cacheFilename);
 | 
					            string cacheFile = Path.Combine(_config.ApplicationPaths.CachePath, "xmltv", cacheFilename);
 | 
				
			||||||
            if (File.Exists(cacheFile))
 | 
					            if (File.Exists(cacheFile))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return UnzipIfNeeded(path, cacheFile);
 | 
					                return UnzipIfNeeded(info.Path, cacheFile);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _logger.LogInformation("Downloading xmltv listings from {Path}", path);
 | 
					            _logger.LogInformation("Downloading xmltv listings from {Path}", info.Path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
 | 
					            Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(path, cancellationToken).ConfigureAwait(false);
 | 
					            using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(info.Path, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
            await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
 | 
					            await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
            await using (var fileStream = new FileStream(cacheFile, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.CopyToBufferSize, FileOptions.Asynchronous))
 | 
					            await using (var fileStream = new FileStream(cacheFile, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.CopyToBufferSize, FileOptions.Asynchronous))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
 | 
					                await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return UnzipIfNeeded(path, cacheFile);
 | 
					            return UnzipIfNeeded(info.Path, cacheFile);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private string UnzipIfNeeded(ReadOnlySpan<char> originalUrl, string file)
 | 
					        private string UnzipIfNeeded(ReadOnlySpan<char> originalUrl, string file)
 | 
				
			||||||
@ -163,7 +163,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            _logger.LogDebug("Getting xmltv programs for channel {Id}", channelId);
 | 
					            _logger.LogDebug("Getting xmltv programs for channel {Id}", channelId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);
 | 
					            string path = await GetXml(info, 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));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -257,7 +257,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
 | 
				
			|||||||
        public async Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location)
 | 
					        public async Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // 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, 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();
 | 
				
			||||||
@ -269,7 +269,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
 | 
				
			|||||||
        public async Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken)
 | 
					        public async Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // 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, 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();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user