Browse Source

update tag saving

Luke Pulverenti 9 years ago
parent
commit
ae168bc563

+ 1 - 1
MediaBrowser.Api/FilterService.cs

@@ -80,7 +80,7 @@ namespace MediaBrowser.Api
                 .OrderBy(i => i)
                 .ToArray();
 
-            result.Tags = items.OfType<IHasTags>()
+            result.Tags = items
                 .SelectMany(i => i.Tags)
                 .Distinct(StringComparer.OrdinalIgnoreCase)
                 .OrderBy(i => i)

+ 1 - 5
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)

+ 1 - 7
MediaBrowser.Api/SimilarItemsHelper.cs

@@ -116,13 +116,7 @@ namespace MediaBrowser.Api
 
         private static IEnumerable<string> GetTags(BaseItem item)
         {
-            var hasTags = item as IHasTags;
-            if (hasTags != null)
-            {
-                return hasTags.Tags;
-            }
-
-            return new List<string>();
+            return item.Tags;
         }
 
         private static IEnumerable<string> GetKeywords(BaseItem item)

+ 1 - 6
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;
                     }

+ 0 - 1
MediaBrowser.Controller/Entities/Audio/Audio.cs

@@ -20,7 +20,6 @@ namespace MediaBrowser.Controller.Entities.Audio
         IHasArtist,
         IHasMusicGenres,
         IHasLookupInfo<SongInfo>,
-        IHasTags,
         IHasMediaSources,
         IThemeMedia,
         IArchivable

+ 3 - 8
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;

+ 1 - 1
MediaBrowser.Controller/Entities/Book.cs

@@ -6,7 +6,7 @@ using MediaBrowser.Model.Entities;
 
 namespace MediaBrowser.Controller.Entities
 {
-    public class Book : BaseItem, IHasTags, IHasLookupInfo<BookInfo>, IHasSeries
+    public class Book : BaseItem, IHasLookupInfo<BookInfo>, IHasSeries
     {
         [IgnoreDataMember]
         public override string MediaType

+ 1 - 1
MediaBrowser.Controller/Entities/Folder.cs

@@ -20,7 +20,7 @@ namespace MediaBrowser.Controller.Entities
     /// <summary>
     /// Class Folder
     /// </summary>
-    public class Folder : BaseItem, IHasThemeMedia, IHasTags
+    public class Folder : BaseItem, IHasThemeMedia
     {
         public static IUserManager UserManager { get; set; }
         public static IUserViewManager UserViewManager { get; set; }

+ 1 - 1
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<GameInfo>
+    public class Game : BaseItem, IHasTrailers, IHasThemeMedia, IHasScreenshots, ISupportsPlaceHolders, IHasLookupInfo<GameInfo>
     {
         public List<Guid> ThemeSongIds { get; set; }
         public List<Guid> ThemeVideoIds { get; set; }

+ 1 - 1
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<string> Taglines { get; set; }
 

+ 1 - 1
MediaBrowser.Controller/Entities/Studio.cs

@@ -8,7 +8,7 @@ namespace MediaBrowser.Controller.Entities
     /// <summary>
     /// Class Studio
     /// </summary>
-    public class Studio : BaseItem, IItemByName, IHasTags
+    public class Studio : BaseItem, IItemByName
     {
         public override List<string> GetUserDataKeys()
         {

+ 1 - 14
MediaBrowser.Controller/Entities/IHasTags.cs → MediaBrowser.Controller/Entities/TagExtensions.cs

@@ -1,24 +1,11 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
 
 namespace MediaBrowser.Controller.Entities
 {
-    /// <summary>
-    /// Interface IHasTags
-    /// </summary>
-    public interface IHasTags
-    {
-        /// <summary>
-        /// Gets or sets the tags.
-        /// </summary>
-        /// <value>The tags.</value>
-        List<string> 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))
             {

+ 1 - 6
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;
                 }

+ 0 - 1
MediaBrowser.Controller/Entities/Video.cs

@@ -21,7 +21,6 @@ namespace MediaBrowser.Controller.Entities
     /// </summary>
     public class Video : BaseItem,
         IHasAspectRatio,
-        IHasTags,
         ISupportsPlaceHolders,
         IHasMediaSources,
         IHasShortOverview,

+ 1 - 1
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -154,7 +154,6 @@
     <Compile Include="Entities\IHasSpecialFeatures.cs" />
     <Compile Include="Entities\IHasStartDate.cs" />
     <Compile Include="Entities\IHasTaglines.cs" />
-    <Compile Include="Entities\IHasTags.cs" />
     <Compile Include="Entities\IHasThemeMedia.cs" />
     <Compile Include="Entities\IHasTrailers.cs" />
     <Compile Include="Entities\IHasUserData.cs" />
@@ -177,6 +176,7 @@
     <Compile Include="Entities\PhotoAlbum.cs" />
     <Compile Include="Entities\Share.cs" />
     <Compile Include="Entities\SourceType.cs" />
+    <Compile Include="Entities\TagExtensions.cs" />
     <Compile Include="Entities\UserView.cs" />
     <Compile Include="Entities\UserViewBuilder.cs" />
     <Compile Include="FileOrganization\IFileOrganizationService.cs" />

+ 2 - 6
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();
 

+ 7 - 11
MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs

@@ -593,20 +593,16 @@ namespace MediaBrowser.LocalMetadata.Savers
                 builder.Append("</Studios>");
             }
 
-            var hasTags = item as IHasTags;
-            if (hasTags != null)
+            if (item.Tags.Count > 0)
             {
-                if (hasTags.Tags.Count > 0)
-                {
-                    builder.Append("<Tags>");
-
-                    foreach (var tag in hasTags.Tags)
-                    {
-                        builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
-                    }
+                builder.Append("<Tags>");
 
-                    builder.Append("</Tags>");
+                foreach (var tag in item.Tags)
+                {
+                    builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
                 }
+
+                builder.Append("</Tags>");
             }
 
             if (item.Keywords.Count > 0)

+ 2 - 8
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;
                 }
             }
 

+ 1 - 10
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<string>();
-                }
+                dto.Tags = item.Tags;
             }
 
             if (fields.Contains(ItemFields.Keywords))

+ 1 - 5
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;
                     }

+ 7 - 11
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);
                 }
             }