diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-28 11:27:26 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-28 11:27:26 -0400 |
| commit | 3be25f8bfbe6286d47ab5cf400fac7673e284d61 (patch) | |
| tree | f4b61c5d1082f673ebe00e117502091e41a88bd3 /MediaBrowser.Server.Implementations | |
| parent | eab030df7ff0f3a78b1aa01f06eb30f71df5a391 (diff) | |
channel improvements
Diffstat (limited to 'MediaBrowser.Server.Implementations')
6 files changed, 76 insertions, 64 deletions
diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index 12aa670b3..23c1522b5 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -547,7 +547,8 @@ namespace MediaBrowser.Server.Implementations.Channels SupportsLatestMedia = supportsLatest, Name = channel.Name, Id = channel.Id.ToString("N"), - SupportsContentDownloading = isIndexable || supportsLatest + SupportsContentDownloading = isIndexable || supportsLatest, + AutoRefreshLevels = features.AutoRefreshLevels }; } @@ -627,6 +628,13 @@ namespace MediaBrowser.Server.Implementations.Channels items = items.Where(i => contentTypes.Contains(i.Item2.ContentType)); } + if (query.ExtraTypes.Length > 0) + { + // Avoid implicitly captured closure + var contentTypes = query.ExtraTypes; + + items = items.Where(i => contentTypes.Contains(i.Item2.ExtraType)); + } // Avoid implicitly captured closure var token = cancellationToken; @@ -776,6 +784,13 @@ namespace MediaBrowser.Server.Implementations.Channels items = items.Where(i => contentTypes.Contains(i.Item2.ContentType)); } + if (query.ExtraTypes.Length > 0) + { + // Avoid implicitly captured closure + var contentTypes = query.ExtraTypes; + + items = items.Where(i => contentTypes.Contains(i.Item2.ExtraType)); + } if (query.StartIndex.HasValue) { @@ -806,7 +821,7 @@ namespace MediaBrowser.Server.Implementations.Channels Items = returnItemArray }; } - + public async Task<QueryResult<BaseItemDto>> GetAllMedia(AllChannelMediaQuery query, CancellationToken cancellationToken) { var user = string.IsNullOrWhiteSpace(query.UserId) @@ -1161,60 +1176,62 @@ namespace MediaBrowser.Server.Implementations.Channels }; } - private string GetIdToHash(string externalId, IChannel channelProvider) + private string GetIdToHash(string externalId, string channelName) { // Increment this as needed to force new downloads // Incorporate Name because it's being used to convert channel entity to provider - return externalId + (channelProvider.DataVersion ?? string.Empty) + - (channelProvider.Name ?? string.Empty) + "16"; + return externalId + (channelName ?? string.Empty) + "16"; } - private async Task<BaseItem> GetChannelItemEntity(ChannelItemInfo info, IChannel channelProvider, Guid internalChannelId, CancellationToken cancellationToken) + private T GetItemById<T>(string idString, string channelName, string channnelDataVersion, out bool isNew) + where T : BaseItem, IChannelItem, new() { - BaseItem item; - Guid id; - var isNew = false; + var id = GetIdToHash(idString, channelName).GetMBId(typeof(T)); - var idToHash = GetIdToHash(info.Id, channelProvider); + T item = null; - if (info.Type == ChannelItemType.Folder) + try { - id = idToHash.GetMBId(typeof(ChannelFolderItem)); - - item = _libraryManager.GetItemById(id) as ChannelFolderItem; - - if (item == null) - { - isNew = true; - item = new ChannelFolderItem(); - } + item = _libraryManager.GetItemById(id) as T; } - else if (info.MediaType == ChannelMediaType.Audio) + catch (Exception ex) { - id = idToHash.GetMBId(typeof(ChannelAudioItem)); - - item = _libraryManager.GetItemById(id) as ChannelAudioItem; + _logger.ErrorException("Error retrieving channel item from database", ex); + } - if (item == null) - { - isNew = true; - item = new ChannelAudioItem(); - } + if (item == null || !string.Equals(item.DataVersion, channnelDataVersion, StringComparison.Ordinal)) + { + item = new T(); + isNew = true; } else { - id = idToHash.GetMBId(typeof(ChannelVideoItem)); + isNew = false; + } - item = _libraryManager.GetItemById(id) as ChannelVideoItem; + item.DataVersion = channnelDataVersion; + item.Id = id; + return item; + } - if (item == null) - { - isNew = true; - item = new ChannelVideoItem(); - } + private async Task<BaseItem> GetChannelItemEntity(ChannelItemInfo info, IChannel channelProvider, Guid internalChannelId, CancellationToken cancellationToken) + { + BaseItem item; + bool isNew; + + if (info.Type == ChannelItemType.Folder) + { + item = GetItemById<ChannelFolderItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } + else if (info.MediaType == ChannelMediaType.Audio) + { + item = GetItemById<ChannelAudioItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } + else + { + item = GetItemById<ChannelVideoItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); } - item.Id = id; item.RunTimeTicks = info.RunTimeTicks; if (isNew) @@ -1254,6 +1271,7 @@ namespace MediaBrowser.Server.Implementations.Channels if (channelMediaItem != null) { channelMediaItem.ContentType = info.ContentType; + channelMediaItem.ExtraType = info.ExtraType; channelMediaItem.ChannelMediaSources = info.MediaSources; var mediaSource = info.MediaSources.FirstOrDefault(); diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelPostScanTask.cs b/MediaBrowser.Server.Implementations/Channels/ChannelPostScanTask.cs index b067271c5..9806aab4a 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelPostScanTask.cs @@ -64,9 +64,16 @@ namespace MediaBrowser.Server.Implementations.Channels foreach (var channel in channels.Items) { + var channelId = channel.Id.ToString("N"); + + var features = _channelManager.GetChannelFeatures(channelId); + + const int currentRefreshLevel = 1; + var maxRefreshLevel = features.AutoRefreshLevels ?? 1; + try { - await GetAllItems(user, channel.Id.ToString("N"), null, false, cancellationToken).ConfigureAwait(false); + await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { @@ -83,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Channels } - private async Task GetAllItems(string user, string channelId, string folderId, bool recursive, CancellationToken cancellationToken) + private async Task GetAllItems(string user, string channelId, string folderId, int currentRefreshLevel, int maxRefreshLevel, CancellationToken cancellationToken) { var folderItems = new List<string>(); @@ -117,13 +124,13 @@ namespace MediaBrowser.Server.Implementations.Channels totalCount = result.TotalRecordCount; } - if (recursive) + if (currentRefreshLevel < maxRefreshLevel) { foreach (var folder in folderItems) { try { - await GetAllItems(user, channelId, folder, false, cancellationToken).ConfigureAwait(false); + await GetAllItems(user, channelId, folder, currentRefreshLevel + 1, maxRefreshLevel, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs index 97129368e..1e1062161 100644 --- a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs +++ b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs @@ -99,7 +99,8 @@ namespace MediaBrowser.Server.Implementations.Intros { var channelTrailers = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery { - ContentTypes = new[] { ChannelMediaContentType.Trailer }, + ContentTypes = new[] { ChannelMediaContentType.MovieExtra }, + ExtraTypes = new[] { ExtraType.Trailer }, UserId = user.Id.ToString("N") }, CancellationToken.None); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index dc3a0d45f..4362145c1 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -449,10 +449,10 @@ namespace MediaBrowser.Server.Implementations.Library { var list = new List<string> { - ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(item.Id) + item.GetInternalMetadataPath() }; - list.AddRange(children.Select(i => ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(i.Id))); + list.AddRange(children.Select(i => i.GetInternalMetadataPath())); return list; } diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs index d35282e55..a0b604645 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs @@ -1,12 +1,9 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Chapters; -using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; @@ -22,20 +19,17 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { public class EncodingManager : IEncodingManager { - private readonly IServerConfigurationManager _config; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IFileSystem _fileSystem; private readonly ILogger _logger; private readonly IMediaEncoder _encoder; private readonly IChapterManager _chapterManager; - public EncodingManager(IServerConfigurationManager config, - IFileSystem fileSystem, + public EncodingManager(IFileSystem fileSystem, ILogger logger, IMediaEncoder encoder, IChapterManager chapterManager) { - _config = config; _fileSystem = fileSystem; _logger = logger; _encoder = encoder; @@ -46,9 +40,9 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// Gets the chapter images data path. /// </summary> /// <value>The chapter images data path.</value> - private string GetChapterImagesPath(Guid itemId) + private string GetChapterImagesPath(IHasImages item) { - return Path.Combine(_config.ApplicationPaths.GetInternalMetadataPath(itemId), "chapters"); + return Path.Combine(item.GetInternalMetadataPath(), "chapters"); } /// <summary> @@ -190,12 +184,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { var filename = video.DateModified.Ticks.ToString(_usCulture) + "_" + chapterPositionTicks.ToString(_usCulture) + ".jpg"; - return Path.Combine(GetChapterImagesPath(video.Id), filename); + return Path.Combine(GetChapterImagesPath(video), filename); } private List<string> GetSavedChapterImages(Video video) { - var path = GetChapterImagesPath(video.Id); + var path = GetChapterImagesPath(video); try { diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index df2a5f83c..b775580d9 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -251,13 +251,5 @@ namespace MediaBrowser.Server.Implementations _internalMetadataPath = value; } } - - - public string GetInternalMetadataPath(Guid id) - { - var idString = id.ToString("N"); - - return Path.Combine(InternalMetadataPath, idString.Substring(0, 2), idString); - } } } |
