diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-03-19 16:23:33 -0400 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2016-03-19 16:23:33 -0400 |
| commit | 3ab212d070384c0a0000e255307aa58d15cbd0ae (patch) | |
| tree | 6ca899cd7be8685771b56b0074c5b3022faa789a /MediaBrowser.Controller/Entities | |
| parent | fd0d50ad978801164728f7f6bd067430aa090c5f (diff) | |
| parent | db1bf5b1b55c8012e9ca3393fd59b9469ee5aeaf (diff) | |
Merge pull request #1563 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Controller/Entities')
| -rw-r--r-- | MediaBrowser.Controller/Entities/Audio/Audio.cs | 36 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Audio/AudioPodcast.cs | 12 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 45 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Folder.cs | 32 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/InternalItemsQuery.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/SourceType.cs | 10 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Trailer.cs | 60 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Video.cs | 60 |
8 files changed, 245 insertions, 18 deletions
diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index dc37dcceab..4c66a6562a 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -8,6 +8,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using System.Threading; +using MediaBrowser.Controller.Channels; namespace MediaBrowser.Controller.Entities.Audio { @@ -24,6 +26,8 @@ namespace MediaBrowser.Controller.Entities.Audio IThemeMedia, IArchivable { + public List<ChannelMediaInfo> ChannelMediaSources { get; set; } + public long? Size { get; set; } public string Container { get; set; } public int? TotalBitrate { get; set; } @@ -198,7 +202,11 @@ namespace MediaBrowser.Controller.Entities.Audio public override UnratedItem GetBlockUnratedType() { - return UnratedItem.Music; + if (SourceType == SourceType.Library) + { + return UnratedItem.Music; + } + return base.GetBlockUnratedType(); } public SongInfo GetLookupInfo() @@ -214,6 +222,32 @@ namespace MediaBrowser.Controller.Entities.Audio public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution) { + if (SourceType == SourceType.Channel) + { + var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None) + .Result.ToList(); + + if (sources.Count > 0) + { + return sources; + } + + var list = new List<MediaSourceInfo> + { + GetVersionInfo(this, enablePathSubstitution) + }; + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } + + return list; + } + var result = new List<MediaSourceInfo> { GetVersionInfo(this, enablePathSubstitution) diff --git a/MediaBrowser.Controller/Entities/Audio/AudioPodcast.cs b/MediaBrowser.Controller/Entities/Audio/AudioPodcast.cs new file mode 100644 index 0000000000..983cc0100f --- /dev/null +++ b/MediaBrowser.Controller/Entities/Audio/AudioPodcast.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Entities.Audio +{ + public class AudioPodcast : Audio + { + } +} diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 4106c71975..22f688c424 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -169,6 +169,9 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public bool IsOffline { get; set; } + [IgnoreDataMember] + public virtual SourceType SourceType { get; set; } + /// <summary> /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -255,6 +258,11 @@ namespace MediaBrowser.Controller.Entities { get { + if (SourceType == SourceType.Channel) + { + return false; + } + var locationType = LocationType; return locationType != LocationType.Remote && locationType != LocationType.Virtual; @@ -301,6 +309,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool CanDelete() { + if (SourceType == SourceType.Channel) + { + return false; + } + var locationType = LocationType; return locationType != LocationType.Remote && locationType != LocationType.Virtual; @@ -460,6 +473,11 @@ namespace MediaBrowser.Controller.Entities protected virtual string GetInternalMetadataPath(string basePath) { + if (SourceType == SourceType.Channel) + { + return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N")); + } + var idString = Id.ToString("N"); basePath = System.IO.Path.Combine(basePath, "library"); @@ -1032,6 +1050,13 @@ namespace MediaBrowser.Controller.Entities protected virtual string CreateUserDataKey() { + if (SourceType == SourceType.Channel) + { + if (!string.IsNullOrWhiteSpace(ExternalId)) + { + return ExternalId; + } + } return Id.ToString(); } @@ -1110,6 +1135,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsSaveLocalMetadataEnabled() { + if (SourceType == SourceType.Channel) + { + return false; + } + return ConfigurationManager.Configuration.SaveLocalMeta; } @@ -1225,6 +1255,11 @@ namespace MediaBrowser.Controller.Entities public virtual UnratedItem GetBlockUnratedType() { + if (SourceType == SourceType.Channel) + { + return UnratedItem.ChannelContent; + } + return UnratedItem.Other; } @@ -1268,6 +1303,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsVisibleStandalone(User user) { + if (SourceType == SourceType.Channel) + { + return IsVisibleStandaloneInternal(user, false) && Channel.IsChannelVisible(this, user); + } + return IsVisibleStandaloneInternal(user, true); } @@ -1319,6 +1359,11 @@ namespace MediaBrowser.Controller.Entities public virtual string GetClientTypeName() { + if (IsFolder && SourceType == SourceType.Channel) + { + return "ChannelFolderItem"; + } + return GetType().Name; } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 824a067ad3..e6db695aa7 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -15,6 +15,7 @@ using System.Threading; using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; +using MediaBrowser.Model.Channels; namespace MediaBrowser.Controller.Entities { @@ -794,8 +795,35 @@ namespace MediaBrowser.Controller.Entities return item; } - public virtual Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query) + public virtual async Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query) { + if (SourceType == SourceType.Channel) + { + try + { + // Don't blow up here because it could cause parent screens with other content to fail + return await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery + { + ChannelId = ChannelId, + FolderId = Id.ToString("N"), + Limit = query.Limit, + StartIndex = query.StartIndex, + UserId = query.User.Id.ToString("N"), + SortBy = query.SortBy, + SortOrder = query.SortOrder + + }, new Progress<double>(), CancellationToken.None); + } + catch + { + // Already logged at lower levels + return new QueryResult<BaseItem> + { + + }; + } + } + var user = query.User; Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); @@ -817,7 +845,7 @@ namespace MediaBrowser.Controller.Entities var result = PostFilterAndSort(items, query); - return Task.FromResult(result); + return result; } protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 8b623d64ee..7b3e51cadd 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -115,6 +115,10 @@ namespace MediaBrowser.Controller.Entities public LocationType[] ExcludeLocationTypes { get; set; } public string[] PresetViews { get; set; } + public SourceType[] SourceTypes { get; set; } + public SourceType[] ExcludeSourceTypes { get; set; } + public TrailerType[] TrailerTypes { get; set; } + public TrailerType[] ExcludeTrailerTypes { get; set; } public InternalItemsQuery() { @@ -141,6 +145,10 @@ namespace MediaBrowser.Controller.Entities ExcludeTags = new string[] { }; ExcludeLocationTypes = new LocationType[] { }; PresetViews = new string[] { }; + SourceTypes = new SourceType[] { }; + ExcludeSourceTypes = new SourceType[] { }; + TrailerTypes = new TrailerType[] { }; + ExcludeTrailerTypes = new TrailerType[] { }; } public InternalItemsQuery(User user) diff --git a/MediaBrowser.Controller/Entities/SourceType.cs b/MediaBrowser.Controller/Entities/SourceType.cs new file mode 100644 index 0000000000..92976344c5 --- /dev/null +++ b/MediaBrowser.Controller/Entities/SourceType.cs @@ -0,0 +1,10 @@ + +namespace MediaBrowser.Controller.Entities +{ + public enum SourceType + { + Library = 1, + Channel = 2, + LiveTV = 3 + } +} diff --git a/MediaBrowser.Controller/Entities/Trailer.cs b/MediaBrowser.Controller/Entities/Trailer.cs index 3bff5bc64f..a4ac345453 100644 --- a/MediaBrowser.Controller/Entities/Trailer.cs +++ b/MediaBrowser.Controller/Entities/Trailer.cs @@ -24,8 +24,11 @@ namespace MediaBrowser.Controller.Entities Taglines = new List<string>(); Keywords = new List<string>(); ProductionLocations = new List<string>(); + TrailerTypes = new List<TrailerType>(); } + public List<TrailerType> TrailerTypes { get; set; } + public float? Metascore { get; set; } public List<MediaUrl> RemoteTrailers { get; set; } @@ -62,20 +65,6 @@ namespace MediaBrowser.Controller.Entities /// <value>The critic rating summary.</value> public string CriticRatingSummary { get; set; } - /// <summary> - /// Gets a value indicating whether this instance is local trailer. - /// </summary> - /// <value><c>true</c> if this instance is local trailer; otherwise, <c>false</c>.</value> - [IgnoreDataMember] - public bool IsLocalTrailer - { - get - { - // Local trailers are not part of children - return GetParent() == null; - } - } - protected override string CreateUserDataKey() { var key = Movie.GetMovieUserDataKey(this); @@ -105,9 +94,50 @@ namespace MediaBrowser.Controller.Entities { var info = GetItemLookupInfo<TrailerInfo>(); - info.IsLocalTrailer = IsLocalTrailer; + info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer); + + if (!IsInMixedFolder) + { + info.Name = System.IO.Path.GetFileName(ContainingFolderPath); + } return info; } + + public override bool BeforeMetadataRefresh() + { + var hasChanges = base.BeforeMetadataRefresh(); + + if (!ProductionYear.HasValue) + { + var info = LibraryManager.ParseName(Name); + + var yearInName = info.Year; + + if (yearInName.HasValue) + { + ProductionYear = yearInName; + hasChanges = true; + } + else + { + // Try to get the year from the folder name + if (!IsInMixedFolder) + { + info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath)); + + yearInName = info.Year; + + if (yearInName.HasValue) + { + ProductionYear = yearInName; + hasChanges = true; + } + } + } + } + + return hasChanges; + } } } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 1972226692..3b1da85b55 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -6,13 +6,16 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; +using System.Net.Mime; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Channels; namespace MediaBrowser.Controller.Entities { @@ -33,6 +36,7 @@ namespace MediaBrowser.Controller.Entities public List<string> AdditionalParts { get; set; } public List<string> LocalAlternateVersions { get; set; } public List<LinkedChild> LinkedAlternateVersions { get; set; } + public List<ChannelMediaInfo> ChannelMediaSources { get; set; } [IgnoreDataMember] public bool IsThemeMedia @@ -79,6 +83,23 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] + public override LocationType LocationType + { + get + { + if (SourceType == SourceType.Channel) + { + if (string.IsNullOrEmpty(Path)) + { + return LocationType.Remote; + } + } + + return base.LocationType; + } + } + + [IgnoreDataMember] public override bool SupportsAddingToPlaylist { get { return LocationType == LocationType.FileSystem && RunTimeTicks.HasValue; } @@ -130,6 +151,29 @@ namespace MediaBrowser.Controller.Entities return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video))); } + protected override string CreateUserDataKey() + { + if (ExtraType.HasValue) + { + var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb); + + if (!string.IsNullOrWhiteSpace(key)) + { + key = key + "-" + ExtraType.ToString().ToLower(); + + // Make sure different trailers have their own data. + if (RunTimeTicks.HasValue) + { + key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture); + } + + return key; + } + } + + return base.CreateUserDataKey(); + } + /// <summary> /// Gets the linked children. /// </summary> @@ -441,6 +485,22 @@ namespace MediaBrowser.Controller.Entities public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution) { + if (SourceType == SourceType.Channel) + { + var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None) + .Result.ToList(); + + if (sources.Count > 0) + { + return sources; + } + + return new List<MediaSourceInfo> + { + GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder) + }; + } + var item = this; var result = item.GetAlternateVersions() |
