mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	support display of channel images
This commit is contained in:
		
							parent
							
								
									7b6819846d
								
							
						
					
					
						commit
						01a9c07dd8
					
				@ -5,6 +5,7 @@ using MediaBrowser.Controller.Drawing;
 | 
				
			|||||||
using MediaBrowser.Controller.Dto;
 | 
					using MediaBrowser.Controller.Dto;
 | 
				
			||||||
using MediaBrowser.Controller.Entities;
 | 
					using MediaBrowser.Controller.Entities;
 | 
				
			||||||
using MediaBrowser.Controller.Library;
 | 
					using MediaBrowser.Controller.Library;
 | 
				
			||||||
 | 
					using MediaBrowser.Controller.LiveTv;
 | 
				
			||||||
using MediaBrowser.Controller.Persistence;
 | 
					using MediaBrowser.Controller.Persistence;
 | 
				
			||||||
using MediaBrowser.Controller.Providers;
 | 
					using MediaBrowser.Controller.Providers;
 | 
				
			||||||
using MediaBrowser.Model.Drawing;
 | 
					using MediaBrowser.Model.Drawing;
 | 
				
			||||||
@ -67,6 +68,19 @@ namespace MediaBrowser.Api.Images
 | 
				
			|||||||
        public string Id { get; set; }
 | 
					        public string Id { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [Route("/LiveTV/Channels/{Id}/Images/{Type}", "GET")]
 | 
				
			||||||
 | 
					    [Route("/LiveTV/Channels/{Id}/Images/{Type}/{Index}", "GET")]
 | 
				
			||||||
 | 
					    [Api(Description = "Gets an item image")]
 | 
				
			||||||
 | 
					    public class GetChannelImage : ImageRequest
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the id.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <value>The id.</value>
 | 
				
			||||||
 | 
					        [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
 | 
				
			||||||
 | 
					        public string Id { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Class UpdateItemImageIndex
 | 
					    /// Class UpdateItemImageIndex
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
@ -341,10 +355,12 @@ namespace MediaBrowser.Api.Images
 | 
				
			|||||||
        private readonly IDtoService _dtoService;
 | 
					        private readonly IDtoService _dtoService;
 | 
				
			||||||
        private readonly IImageProcessor _imageProcessor;
 | 
					        private readonly IImageProcessor _imageProcessor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private readonly ILiveTvManager _liveTv;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Initializes a new instance of the <see cref="ImageService" /> class.
 | 
					        /// Initializes a new instance of the <see cref="ImageService" /> class.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public ImageService(IUserManager userManager, ILibraryManager libraryManager, IApplicationPaths appPaths, IProviderManager providerManager, IItemRepository itemRepo, IDtoService dtoService, IImageProcessor imageProcessor)
 | 
					        public ImageService(IUserManager userManager, ILibraryManager libraryManager, IApplicationPaths appPaths, IProviderManager providerManager, IItemRepository itemRepo, IDtoService dtoService, IImageProcessor imageProcessor, ILiveTvManager liveTv)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _userManager = userManager;
 | 
					            _userManager = userManager;
 | 
				
			||||||
            _libraryManager = libraryManager;
 | 
					            _libraryManager = libraryManager;
 | 
				
			||||||
@ -353,6 +369,7 @@ namespace MediaBrowser.Api.Images
 | 
				
			|||||||
            _itemRepo = itemRepo;
 | 
					            _itemRepo = itemRepo;
 | 
				
			||||||
            _dtoService = dtoService;
 | 
					            _dtoService = dtoService;
 | 
				
			||||||
            _imageProcessor = imageProcessor;
 | 
					            _imageProcessor = imageProcessor;
 | 
				
			||||||
 | 
					            _liveTv = liveTv;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@ -492,6 +509,13 @@ namespace MediaBrowser.Api.Images
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public object Get(GetChannelImage request)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var item = _liveTv.GetChannel(request.Id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return GetImage(request, item);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets the specified request.
 | 
					        /// Gets the specified request.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,18 @@ namespace MediaBrowser.Api.LiveTv
 | 
				
			|||||||
        public string UserId { get; set; }
 | 
					        public string UserId { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [Route("/LiveTv/Channels/{Id}", "GET")]
 | 
				
			||||||
 | 
					    [Api(Description = "Gets a live tv channel")]
 | 
				
			||||||
 | 
					    public class GetChannel : IReturn<ChannelInfoDto>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the id.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <value>The id.</value>
 | 
				
			||||||
 | 
					        [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
 | 
				
			||||||
 | 
					        public string Id { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    [Route("/LiveTv/Recordings", "GET")]
 | 
					    [Route("/LiveTv/Recordings", "GET")]
 | 
				
			||||||
    [Api(Description = "Gets available live tv recordings.")]
 | 
					    [Api(Description = "Gets available live tv recordings.")]
 | 
				
			||||||
    public class GetRecordings : IReturn<List<RecordingInfo>>
 | 
					    public class GetRecordings : IReturn<List<RecordingInfo>>
 | 
				
			||||||
@ -101,6 +113,13 @@ namespace MediaBrowser.Api.LiveTv
 | 
				
			|||||||
            return ToOptimizedResult(result.ToList());
 | 
					            return ToOptimizedResult(result.ToList());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public object Get(GetChannel request)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var result = _liveTvManager.GetChannel(request.Id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return ToOptimizedResult(_liveTvManager.GetChannelInfoDto(result));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public object Get(GetRecordings request)
 | 
					        public object Get(GetRecordings request)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var result = GetRecordingsAsync(request).Result;
 | 
					            var result = GetRecordingsAsync(request).Result;
 | 
				
			||||||
 | 
				
			|||||||
@ -307,7 +307,7 @@ namespace MediaBrowser.Api.Playback.Progressive
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return new ImageService(UserManager, LibraryManager, ApplicationPaths, null, ItemRepository, DtoService, ImageProcessor)
 | 
					            return new ImageService(UserManager, LibraryManager, ApplicationPaths, null, ItemRepository, DtoService, ImageProcessor, null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Logger = Logger,
 | 
					                Logger = Logger,
 | 
				
			||||||
                RequestContext = RequestContext,
 | 
					                RequestContext = RequestContext,
 | 
				
			||||||
 | 
				
			|||||||
@ -37,9 +37,8 @@ namespace MediaBrowser.Controller.LiveTv
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets the channel.
 | 
					        /// Gets the channel.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="serviceName">Name of the service.</param>
 | 
					        /// <param name="id">The identifier.</param>
 | 
				
			||||||
        /// <param name="channelId">The channel identifier.</param>
 | 
					 | 
				
			||||||
        /// <returns>Channel.</returns>
 | 
					        /// <returns>Channel.</returns>
 | 
				
			||||||
        Channel GetChannel(string serviceName, string channelId);
 | 
					        Channel GetChannel(string id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,12 @@ namespace MediaBrowser.Model.LiveTv
 | 
				
			|||||||
        /// <value>The identifier.</value>
 | 
					        /// <value>The identifier.</value>
 | 
				
			||||||
        public string Id { get; set; }
 | 
					        public string Id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the channel identifier.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <value>The channel identifier.</value>
 | 
				
			||||||
 | 
					        public string ChannelId { get; set; }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the logo image tag.
 | 
					        /// Gets or sets the logo image tag.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
@ -42,5 +48,11 @@ namespace MediaBrowser.Model.LiveTv
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <value>The type of the channel.</value>
 | 
					        /// <value>The type of the channel.</value>
 | 
				
			||||||
        public ChannelType ChannelType { get; set; }
 | 
					        public ChannelType ChannelType { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the type.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <value>The type.</value>
 | 
				
			||||||
 | 
					        public string Type { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,12 +33,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
 | 
					        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (item.HasImage(ImageType.Primary))
 | 
					            return !item.HasImage(ImageType.Primary);
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return base.NeedsRefreshInternal(item, providerInfo);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
 | 
					        public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
 | 
				
			||||||
 | 
				
			|||||||
@ -70,9 +70,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 | 
				
			|||||||
                Name = info.Name,
 | 
					                Name = info.Name,
 | 
				
			||||||
                ServiceName = info.ServiceName,
 | 
					                ServiceName = info.ServiceName,
 | 
				
			||||||
                ChannelType = info.ChannelType,
 | 
					                ChannelType = info.ChannelType,
 | 
				
			||||||
                Id = info.ChannelId,
 | 
					                ChannelId = info.ChannelId,
 | 
				
			||||||
                Number = info.ChannelNumber,
 | 
					                Number = info.ChannelNumber,
 | 
				
			||||||
                PrimaryImageTag = GetLogoImageTag(info)
 | 
					                PrimaryImageTag = GetLogoImageTag(info),
 | 
				
			||||||
 | 
					                Type = info.GetType().Name,
 | 
				
			||||||
 | 
					                Id = info.Id.ToString("N")
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -113,9 +115,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 | 
				
			|||||||
            }).ThenBy(i => i.Name);
 | 
					            }).ThenBy(i => i.Name);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public Channel GetChannel(string serviceName, string channelId)
 | 
					        public Channel GetChannel(string id)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return _channels.FirstOrDefault(i => string.Equals(i.ServiceName, serviceName, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ChannelId, channelId, StringComparison.OrdinalIgnoreCase));
 | 
					            var guid = new Guid(id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return _channels.FirstOrDefault(i => i.Id == guid);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        internal async Task RefreshChannels(IProgress<double> progress, CancellationToken cancellationToken)
 | 
					        internal async Task RefreshChannels(IProgress<double> progress, CancellationToken cancellationToken)
 | 
				
			||||||
@ -125,36 +129,44 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            var tasks = _services.Select(i => i.GetChannelsAsync(currentCancellationToken));
 | 
					            var tasks = _services.Select(i => i.GetChannelsAsync(currentCancellationToken));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            progress.Report(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var results = await Task.WhenAll(tasks).ConfigureAwait(false);
 | 
					            var results = await Task.WhenAll(tasks).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var allChannels = results.SelectMany(i => i);
 | 
					            var allChannels = results.SelectMany(i => i).ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var channnelTasks = allChannels.Select(i => GetChannel(i, cancellationToken));
 | 
					            var list = new List<Channel>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var channelEntities = await Task.WhenAll(channnelTasks).ConfigureAwait(false);
 | 
					            var numComplete = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _channels = channelEntities.ToList();
 | 
					            foreach (var channel in allChannels)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var item = await GetChannel(channel, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    list.Add(item);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (OperationCanceledException)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    throw;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (Exception ex)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    _logger.ErrorException("Error getting channel information for {0}", ex, channel.Name);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                numComplete++;
 | 
				
			||||||
 | 
					                double percent = numComplete;
 | 
				
			||||||
 | 
					                percent /= allChannels.Count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                progress.Report(90 * percent + 10);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            _channels = list;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private async Task<Channel> GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken)
 | 
					        private async Task<Channel> GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            try
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return await GetChannelInternal(channelInfo, cancellationToken).ConfigureAwait(false);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            catch (OperationCanceledException)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                throw;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            catch (Exception ex)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                _logger.ErrorException("Error getting channel information for {0}", ex, channelInfo.Name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private async Task<Channel> GetChannelInternal(ChannelInfo channelInfo, CancellationToken cancellationToken)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.ServiceName), _fileSystem.GetValidFilename(channelInfo.Name));
 | 
					            var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.ServiceName), _fileSystem.GetValidFilename(channelInfo.Name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user