update tag saving

This commit is contained in:
Luke Pulverenti 2016-06-02 13:43:29 -04:00
parent 85c508bcd1
commit ae168bc563
21 changed files with 35 additions and 106 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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;
}

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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; }

View File

@ -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; }

View File

@ -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; }

View File

@ -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()
{

View File

@ -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))
{

View File

@ -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;
}

View File

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

View File

@ -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" />

View File

@ -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();

View File

@ -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 item.Tags)
{
builder.Append("<Tags>");
foreach (var tag in hasTags.Tags)
{
builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
}
builder.Append("</Tags>");
builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
}
builder.Append("</Tags>");
}
if (item.Keywords.Count > 0)

View File

@ -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;
}
}

View File

@ -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))

View File

@ -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;
}

View File

@ -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);
}
}