From ae168bc56394057c42fa50a36e54e52617f84244 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jun 2016 13:43:29 -0400 Subject: [PATCH] update tag saving --- MediaBrowser.Api/FilterService.cs | 2 +- MediaBrowser.Api/ItemUpdateService.cs | 6 +----- MediaBrowser.Api/SimilarItemsHelper.cs | 8 +------- .../UserLibrary/BaseItemsByNameService.cs | 7 +------ .../Entities/Audio/Audio.cs | 1 - MediaBrowser.Controller/Entities/BaseItem.cs | 11 +++-------- MediaBrowser.Controller/Entities/Book.cs | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 2 +- MediaBrowser.Controller/Entities/Game.cs | 2 +- MediaBrowser.Controller/Entities/Photo.cs | 2 +- MediaBrowser.Controller/Entities/Studio.cs | 2 +- .../Entities/{IHasTags.cs => TagExtensions.cs} | 15 +-------------- .../Entities/UserViewBuilder.cs | 7 +------ MediaBrowser.Controller/Entities/Video.cs | 1 - .../MediaBrowser.Controller.csproj | 2 +- .../Providers/BaseItemXmlParser.cs | 8 ++------ .../Savers/XmlSaverHelpers.cs | 18 +++++++----------- .../Manager/ProviderUtils.cs | 10 ++-------- .../Dto/DtoService.cs | 11 +---------- .../Parsers/BaseNfoParser.cs | 6 +----- .../Savers/BaseNfoSaver.cs | 18 +++++++----------- 21 files changed, 35 insertions(+), 106 deletions(-) rename MediaBrowser.Controller/Entities/{IHasTags.cs => TagExtensions.cs} (54%) diff --git a/MediaBrowser.Api/FilterService.cs b/MediaBrowser.Api/FilterService.cs index c4419531c..b3b75359a 100644 --- a/MediaBrowser.Api/FilterService.cs +++ b/MediaBrowser.Api/FilterService.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.Api .OrderBy(i => i) .ToArray(); - result.Tags = items.OfType() + result.Tags = items .SelectMany(i => i.Tags) .Distinct(StringComparer.OrdinalIgnoreCase) .OrderBy(i => i) diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 36e8a504c..6cb23a140 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -280,11 +280,7 @@ namespace MediaBrowser.Api episode.AbsoluteEpisodeNumber = request.AbsoluteEpisodeNumber; } - var hasTags = item as IHasTags; - if (hasTags != null) - { - hasTags.Tags = request.Tags; - } + item.Tags = request.Tags; var hasTaglines = item as IHasTaglines; if (hasTaglines != null) diff --git a/MediaBrowser.Api/SimilarItemsHelper.cs b/MediaBrowser.Api/SimilarItemsHelper.cs index 76bc16a96..537ffc913 100644 --- a/MediaBrowser.Api/SimilarItemsHelper.cs +++ b/MediaBrowser.Api/SimilarItemsHelper.cs @@ -116,13 +116,7 @@ namespace MediaBrowser.Api private static IEnumerable GetTags(BaseItem item) { - var hasTags = item as IHasTags; - if (hasTags != null) - { - return hasTags.Tags; - } - - return new List(); + return item.Tags; } private static IEnumerable GetKeywords(BaseItem item) diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 565bed053..18dec3253 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -333,12 +333,7 @@ namespace MediaBrowser.Api.UserLibrary var tags = request.GetTags(); if (tags.Length > 0) { - var hasTags = i as IHasTags; - if (hasTags == null) - { - return false; - } - if (!tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))) + if (!tags.Any(v => i.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))) { return false; } diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index c34a884ff..06710b030 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -20,7 +20,6 @@ namespace MediaBrowser.Controller.Entities.Audio IHasArtist, IHasMusicGenres, IHasLookupInfo, - IHasTags, IHasMediaSources, IThemeMedia, IArchivable diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 5101a9f28..a45a462df 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1397,15 +1397,10 @@ namespace MediaBrowser.Controller.Entities private bool IsVisibleViaTags(User user) { - var hasTags = this as IHasTags; - - if (hasTags != null) + var policy = user.Policy; + if (policy.BlockedTags.Any(i => Tags.Contains(i, StringComparer.OrdinalIgnoreCase))) { - var policy = user.Policy; - if (policy.BlockedTags.Any(i => hasTags.Tags.Contains(i, StringComparer.OrdinalIgnoreCase))) - { - return false; - } + return false; } return true; diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 1c86a53f0..96fad670e 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -6,7 +6,7 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Controller.Entities { - public class Book : BaseItem, IHasTags, IHasLookupInfo, IHasSeries + public class Book : BaseItem, IHasLookupInfo, IHasSeries { [IgnoreDataMember] public override string MediaType diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index a4cbd34b2..ba94c99d2 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Controller.Entities /// /// Class Folder /// - public class Folder : BaseItem, IHasThemeMedia, IHasTags + public class Folder : BaseItem, IHasThemeMedia { public static IUserManager UserManager { get; set; } public static IUserViewManager UserViewManager { get; set; } diff --git a/MediaBrowser.Controller/Entities/Game.cs b/MediaBrowser.Controller/Entities/Game.cs index 9ed240046..317c71529 100644 --- a/MediaBrowser.Controller/Entities/Game.cs +++ b/MediaBrowser.Controller/Entities/Game.cs @@ -7,7 +7,7 @@ using System.Linq; namespace MediaBrowser.Controller.Entities { - public class Game : BaseItem, IHasTrailers, IHasThemeMedia, IHasTags, IHasScreenshots, ISupportsPlaceHolders, IHasLookupInfo + public class Game : BaseItem, IHasTrailers, IHasThemeMedia, IHasScreenshots, ISupportsPlaceHolders, IHasLookupInfo { public List ThemeSongIds { get; set; } public List ThemeVideoIds { get; set; } diff --git a/MediaBrowser.Controller/Entities/Photo.cs b/MediaBrowser.Controller/Entities/Photo.cs index 3358ccc6f..de756563d 100644 --- a/MediaBrowser.Controller/Entities/Photo.cs +++ b/MediaBrowser.Controller/Entities/Photo.cs @@ -5,7 +5,7 @@ using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities { - public class Photo : BaseItem, IHasTags, IHasTaglines + public class Photo : BaseItem, IHasTaglines { public List Taglines { get; set; } diff --git a/MediaBrowser.Controller/Entities/Studio.cs b/MediaBrowser.Controller/Entities/Studio.cs index 48ca7bbcc..e46978af3 100644 --- a/MediaBrowser.Controller/Entities/Studio.cs +++ b/MediaBrowser.Controller/Entities/Studio.cs @@ -8,7 +8,7 @@ namespace MediaBrowser.Controller.Entities /// /// Class Studio /// - public class Studio : BaseItem, IItemByName, IHasTags + public class Studio : BaseItem, IItemByName { public override List GetUserDataKeys() { diff --git a/MediaBrowser.Controller/Entities/IHasTags.cs b/MediaBrowser.Controller/Entities/TagExtensions.cs similarity index 54% rename from MediaBrowser.Controller/Entities/IHasTags.cs rename to MediaBrowser.Controller/Entities/TagExtensions.cs index 45a56009d..0e1df72cd 100644 --- a/MediaBrowser.Controller/Entities/IHasTags.cs +++ b/MediaBrowser.Controller/Entities/TagExtensions.cs @@ -1,24 +1,11 @@ using System; -using System.Collections.Generic; using System.Linq; namespace MediaBrowser.Controller.Entities { - /// - /// Interface IHasTags - /// - public interface IHasTags - { - /// - /// Gets or sets the tags. - /// - /// The tags. - List Tags { get; set; } - } - public static class TagExtensions { - public static void AddTag(this IHasTags item, string name) + public static void AddTag(this BaseItem item, string name) { if (string.IsNullOrWhiteSpace(name)) { diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 655dff06a..a7b23112e 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1646,12 +1646,7 @@ namespace MediaBrowser.Controller.Entities var tags = query.Tags; if (tags.Length > 0) { - var hasTags = item as IHasTags; - if (hasTags == null) - { - return false; - } - if (!tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))) + if (!tags.Any(v => item.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))) { return false; } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 6a9d7cb51..2502033c8 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -21,7 +21,6 @@ namespace MediaBrowser.Controller.Entities /// public class Video : BaseItem, IHasAspectRatio, - IHasTags, ISupportsPlaceHolders, IHasMediaSources, IHasShortOverview, diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index b15bb94c7..4cfdc641c 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -154,7 +154,6 @@ - @@ -177,6 +176,7 @@ + diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index aaa440060..a783910e3 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -803,11 +803,7 @@ namespace MediaBrowser.Controller.Providers { using (var subtree = reader.ReadSubtree()) { - var hasTags = item as IHasTags; - if (hasTags != null) - { - FetchFromTagsNode(subtree, hasTags); - } + FetchFromTagsNode(subtree, item); } break; } @@ -1066,7 +1062,7 @@ namespace MediaBrowser.Controller.Providers } } - private void FetchFromTagsNode(XmlReader reader, IHasTags item) + private void FetchFromTagsNode(XmlReader reader, BaseItem item) { reader.MoveToContent(); diff --git a/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs b/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs index ca19b403a..2b3f53aeb 100644 --- a/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs +++ b/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs @@ -593,20 +593,16 @@ namespace MediaBrowser.LocalMetadata.Savers builder.Append(""); } - var hasTags = item as IHasTags; - if (hasTags != null) + if (item.Tags.Count > 0) { - if (hasTags.Tags.Count > 0) + builder.Append(""); + + foreach (var tag in item.Tags) { - builder.Append(""); - - foreach (var tag in hasTags.Tags) - { - builder.Append("" + SecurityElement.Escape(tag) + ""); - } - - builder.Append(""); + builder.Append("" + SecurityElement.Escape(tag) + ""); } + + builder.Append(""); } if (item.Keywords.Count > 0) diff --git a/MediaBrowser.Providers/Manager/ProviderUtils.cs b/MediaBrowser.Providers/Manager/ProviderUtils.cs index a6f02f3f7..5f23cf69c 100644 --- a/MediaBrowser.Providers/Manager/ProviderUtils.cs +++ b/MediaBrowser.Providers/Manager/ProviderUtils.cs @@ -151,15 +151,9 @@ namespace MediaBrowser.Providers.Manager if (!lockedFields.Contains(MetadataFields.Tags)) { - var sourceHasTags = source as IHasTags; - var targetHasTags = target as IHasTags; - - if (sourceHasTags != null && targetHasTags != null) + if (replaceData || target.Tags.Count == 0) { - if (replaceData || targetHasTags.Tags.Count == 0) - { - targetHasTags.Tags = sourceHasTags.Tags; - } + target.Tags = source.Tags; } } diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index bfcdb2a26..5588405e3 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -969,16 +969,7 @@ namespace MediaBrowser.Server.Implementations.Dto if (fields.Contains(ItemFields.Tags)) { - var hasTags = item as IHasTags; - if (hasTags != null) - { - dto.Tags = hasTags.Tags; - } - - if (dto.Tags == null) - { - dto.Tags = new List(); - } + dto.Tags = item.Tags; } if (fields.Contains(ItemFields.Keywords)) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index ad1c6802d..2e34135a6 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -919,11 +919,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { - var hasTags = item as IHasTags; - if (hasTags != null) - { - hasTags.AddTag(val); - } + item.AddTag(val); } break; } diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index 5bb9577ff..42f0a3364 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -736,19 +736,15 @@ namespace MediaBrowser.XbmcMetadata.Savers writer.WriteElementString("studio", studio); } - var hasTags = item as IHasTags; - if (hasTags != null) + foreach (var tag in item.Tags) { - foreach (var tag in hasTags.Tags) + if (item is MusicAlbum || item is MusicArtist) { - if (item is MusicAlbum || item is MusicArtist) - { - writer.WriteElementString("style", tag); - } - else - { - writer.WriteElementString("tag", tag); - } + writer.WriteElementString("style", tag); + } + else + { + writer.WriteElementString("tag", tag); } }