Add more channel features

This commit is contained in:
Luke Pulverenti
2014-03-18 13:05:57 -04:00
parent cd934c5d3d
commit 4d1d2bbaa1
21 changed files with 317 additions and 34 deletions

View File

@@ -0,0 +1,56 @@
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Channels
{
public class ChannelImageProvider : IDynamicImageProvider, IHasChangeMonitor
{
private readonly IChannelManager _channelManager;
public ChannelImageProvider(IChannelManager channelManager)
{
_channelManager = channelManager;
}
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return GetChannel(item).GetSupportedChannelImages();
}
public Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
{
var channel = GetChannel(item);
return channel.GetChannelImage(type, cancellationToken);
}
public string Name
{
get { return "Channel Image Provider"; }
}
public bool Supports(IHasImages item)
{
return item is Channel;
}
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{
return GetSupportedImages(item).Any(i => !item.HasImage(i));
}
private IChannel GetChannel(IHasImages item)
{
var channel = (Channel)item;
return ((ChannelManager)_channelManager).GetChannelProvider(channel);
}
}
}

View File

@@ -68,11 +68,6 @@ namespace MediaBrowser.Server.Implementations.Channels
return item is IChannelItem;
}
public int Order
{
get { return 0; }
}
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{
var channelItem = item as IChannelItem;

View File

@@ -202,16 +202,19 @@ namespace MediaBrowser.Server.Implementations.Channels
return await GetReturnItems(items, user, query.StartIndex, query.Limit, cancellationToken).ConfigureAwait(false);
}
private Task<IEnumerable<ChannelItemInfo>> GetChannelItems(IChannel channel, User user, string categoryId, CancellationToken cancellationToken)
private async Task<IEnumerable<ChannelItemInfo>> GetChannelItems(IChannel channel, User user, string categoryId, CancellationToken cancellationToken)
{
// TODO: Put some caching in here
if (string.IsNullOrWhiteSpace(categoryId))
var query = new InternalChannelItemQuery
{
return channel.GetChannelItems(user, cancellationToken);
}
User = user,
CategoryId = categoryId
};
return channel.GetChannelItems(categoryId, user, cancellationToken);
var result = await channel.GetChannelItems(query, cancellationToken).ConfigureAwait(false);
return result.Items;
}
private async Task<QueryResult<BaseItemDto>> GetReturnItems(IEnumerable<ChannelItemInfo> items, User user, int? startIndex, int? limit, CancellationToken cancellationToken)
@@ -246,10 +249,36 @@ namespace MediaBrowser.Server.Implementations.Channels
private async Task<BaseItem> GetChannelItemEntity(ChannelItemInfo info)
{
return null;
BaseItem item;
if (info.Type == ChannelItemType.Category)
{
item = new ChannelCategoryItem();
}
else if (info.MediaType == ChannelMediaType.Audio)
{
item = new ChannelAudioItem();
}
else
{
item = new ChannelVideoItem();
}
item.Name = info.Name;
item.Genres = info.Genres;
item.CommunityRating = info.CommunityRating;
item.OfficialRating = info.OfficialRating;
item.Overview = info.Overview;
item.People = info.People;
item.PremiereDate = info.PremiereDate;
item.ProductionYear = info.ProductionYear;
item.RunTimeTicks = info.RunTimeTicks;
item.ProviderIds = info.ProviderIds;
return item;
}
private IChannel GetChannelProvider(Channel channel)
internal IChannel GetChannelProvider(Channel channel)
{
return _channels.First(i => string.Equals(i.Name, channel.OriginalChannelName, StringComparison.OrdinalIgnoreCase));
}

View File

@@ -0,0 +1,63 @@
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Model.Tasks;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Channels
{
class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly IChannelManager _manager;
public RefreshChannelsScheduledTask(IChannelManager manager)
{
_manager = manager;
}
public string Name
{
get { return "Refresh Channels"; }
}
public string Description
{
get { return "Refreshes internet channel information."; }
}
public string Category
{
get { return "Channels"; }
}
public Task Execute(System.Threading.CancellationToken cancellationToken, IProgress<double> progress)
{
var manager = (ChannelManager)_manager;
return manager.RefreshChannels(progress, cancellationToken);
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new StartupTrigger(),
new SystemEventTrigger{ SystemEvent = SystemEvent.WakeFromSleep},
new IntervalTrigger{ Interval = TimeSpan.FromHours(24)}
};
}
public bool IsHidden
{
get { return true; }
}
public bool IsEnabled
{
get { return true; }
}
}
}

View File

@@ -106,8 +106,10 @@
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="BdInfo\BdInfoExaminer.cs" />
<Compile Include="Channels\ChannelImageProvider.cs" />
<Compile Include="Channels\ChannelItemImageProvider.cs" />
<Compile Include="Channels\ChannelManager.cs" />
<Compile Include="Channels\RefreshChannelsScheduledTask.cs" />
<Compile Include="Collections\CollectionManager.cs" />
<Compile Include="Collections\CollectionsDynamicFolder.cs" />
<Compile Include="Configuration\ServerConfigurationManager.cs" />