support multiple user data keys

This commit is contained in:
Luke Pulverenti 2016-04-30 19:05:21 -04:00
parent 1f9d32afc5
commit 6330b13262
26 changed files with 219 additions and 268 deletions

View File

@ -26,7 +26,7 @@ namespace MediaBrowser.Controller.Entities.Audio
IArchivable IArchivable
{ {
public List<ChannelMediaInfo> ChannelMediaSources { get; set; } public List<ChannelMediaInfo> ChannelMediaSources { get; set; }
public long? Size { get; set; } public long? Size { get; set; }
public string Container { get; set; } public string Container { get; set; }
public int? TotalBitrate { get; set; } public int? TotalBitrate { get; set; }
@ -150,12 +150,10 @@ namespace MediaBrowser.Controller.Entities.Audio
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name; + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
} }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
var list = base.GetUserDataKeys();
if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys) if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys)
{ {
var songKey = IndexNumber.HasValue ? IndexNumber.Value.ToString("0000") : string.Empty; var songKey = IndexNumber.HasValue ? IndexNumber.Value.ToString("0000") : string.Empty;
@ -165,7 +163,7 @@ namespace MediaBrowser.Controller.Entities.Audio
{ {
songKey = ParentIndexNumber.Value.ToString("0000") + "-" + songKey; songKey = ParentIndexNumber.Value.ToString("0000") + "-" + songKey;
} }
songKey+= Name; songKey += Name;
if (!string.IsNullOrWhiteSpace(Album)) if (!string.IsNullOrWhiteSpace(Album))
{ {
@ -178,25 +176,25 @@ namespace MediaBrowser.Controller.Entities.Audio
songKey = albumArtist + "-" + songKey; songKey = albumArtist + "-" + songKey;
} }
return songKey; list.Insert(0, songKey);
} }
else
var parent = AlbumEntity;
if (parent != null)
{ {
var parentKey = parent.GetUserDataKey(); var parent = AlbumEntity;
if (IndexNumber.HasValue) if (parent != null && IndexNumber.HasValue)
{ {
var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "") list.InsertRange(0, parent.GetUserDataKeys().Select(i =>
+ IndexNumber.Value.ToString("0000 - "); {
var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
+ IndexNumber.Value.ToString("0000 - ");
return parentKey + songKey; return i + songKey;
}));
} }
} }
return base.CreateUserDataKey(); return list;
} }
public override UnratedItem GetBlockUnratedType() public override UnratedItem GetBlockUnratedType()

View File

@ -96,36 +96,34 @@ namespace MediaBrowser.Controller.Entities.Audio
public List<string> Artists { get; set; } public List<string> Artists { get; set; }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
var id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); var list = base.GetUserDataKeys();
if (!string.IsNullOrWhiteSpace(id))
{
return "MusicAlbum-MusicBrainzReleaseGroup-" + id;
}
id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);
if (!string.IsNullOrWhiteSpace(id))
{
return "MusicAlbum-Musicbrainz-" + id;
}
if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys) if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys)
{ {
var albumArtist = AlbumArtist; var albumArtist = AlbumArtist;
if (!string.IsNullOrWhiteSpace(albumArtist)) if (!string.IsNullOrWhiteSpace(albumArtist))
{ {
return albumArtist + "-" + Name; list.Insert(0, albumArtist + "-" + Name);
} }
} }
return base.CreateUserDataKey(); var id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);
if (!string.IsNullOrWhiteSpace(id))
{
list.Insert(0, "MusicAlbum-Musicbrainz-" + id);
}
id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
if (!string.IsNullOrWhiteSpace(id))
{
list.Insert(0, "MusicAlbum-MusicBrainzReleaseGroup-" + id);
}
return list;
} }
protected override bool GetBlockUnratedValue(UserPolicy config) protected override bool GetBlockUnratedValue(UserPolicy config)

View File

@ -80,13 +80,12 @@ namespace MediaBrowser.Controller.Entities.Audio
ProductionLocations = new List<string>(); ProductionLocations = new List<string>();
} }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return GetUserDataKey(this); var list = base.GetUserDataKeys();
list.InsertRange(0, GetUserDataKeys(this));
return list;
} }
/// <summary> /// <summary>
@ -121,16 +120,18 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private static string GetUserDataKey(MusicArtist item) private static List<string> GetUserDataKeys(MusicArtist item)
{ {
var list = new List<string>();
var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist); var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
if (!string.IsNullOrEmpty(id)) if (!string.IsNullOrEmpty(id))
{ {
return "Artist-Musicbrainz-" + id; list.Add("Artist-Musicbrainz-" + id);
} }
return "Artist-" + item.Name; list.Add("Artist-" + item.Name);
return list;
} }
protected override bool GetBlockUnratedValue(UserPolicy config) protected override bool GetBlockUnratedValue(UserPolicy config)

View File

@ -10,13 +10,12 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary> /// </summary>
public class MusicGenre : BaseItem, IItemByName public class MusicGenre : BaseItem, IItemByName
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "MusicGenre-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "MusicGenre-" + Name);
return list;
} }
[IgnoreDataMember] [IgnoreDataMember]

View File

@ -1158,7 +1158,7 @@ namespace MediaBrowser.Controller.Entities
{ {
if (string.IsNullOrWhiteSpace(_userDataKey)) if (string.IsNullOrWhiteSpace(_userDataKey))
{ {
var key = CreateUserDataKey(); var key = GetUserDataKeys().First();
_userDataKey = key; _userDataKey = key;
return key; return key;
} }
@ -1166,16 +1166,20 @@ namespace MediaBrowser.Controller.Entities
return _userDataKey; return _userDataKey;
} }
protected virtual string CreateUserDataKey() public virtual List<string> GetUserDataKeys()
{ {
var list = new List<string>();
if (SourceType == SourceType.Channel) if (SourceType == SourceType.Channel)
{ {
if (!string.IsNullOrWhiteSpace(ExternalId)) if (!string.IsNullOrWhiteSpace(ExternalId))
{ {
return ExternalId; list.Add(ExternalId);
} }
} }
return Id.ToString();
list.Add(Id.ToString());
return list;
} }
internal virtual bool IsValidFromResolver(BaseItem newItem) internal virtual bool IsValidFromResolver(BaseItem newItem)

View File

@ -76,15 +76,16 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public List<string> MultiPartGameFiles { get; set; } public List<string> MultiPartGameFiles { get; set; }
protected override string CreateUserDataKey() public override List<string> GetUserDataKeys()
{ {
var list = base.GetUserDataKeys();
var id = this.GetProviderId(MetadataProviders.Gamesdb); var id = this.GetProviderId(MetadataProviders.Gamesdb);
if (!string.IsNullOrEmpty(id)) if (!string.IsNullOrEmpty(id))
{ {
return "Game-Gamesdb-" + id; list.Insert(0, "Game-Gamesdb-" + id);
} }
return base.CreateUserDataKey(); return list;
} }
public override IEnumerable<string> GetDeletePaths() public override IEnumerable<string> GetDeletePaths()

View File

@ -7,13 +7,12 @@ namespace MediaBrowser.Controller.Entities
{ {
public class GameGenre : BaseItem, IItemByName public class GameGenre : BaseItem, IItemByName
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "GameGenre-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "GameGenre-" + Name);
return list;
} }
/// <summary> /// <summary>

View File

@ -2,6 +2,7 @@
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using System; using System;
using System.Collections.Generic;
using MediaBrowser.Model.Users; using MediaBrowser.Model.Users;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
@ -31,17 +32,15 @@ namespace MediaBrowser.Controller.Entities
/// <value>The game system.</value> /// <value>The game system.</value>
public string GameSystemName { get; set; } public string GameSystemName { get; set; }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
var list = base.GetUserDataKeys();
if (!string.IsNullOrEmpty(GameSystemName)) if (!string.IsNullOrEmpty(GameSystemName))
{ {
return "GameSystem-" + GameSystemName; list.Insert(0, "GameSystem-" + GameSystemName);
} }
return base.CreateUserDataKey(); return list;
} }
protected override bool GetBlockUnratedValue(UserPolicy config) protected override bool GetBlockUnratedValue(UserPolicy config)

View File

@ -11,13 +11,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public class Genre : BaseItem, IItemByName public class Genre : BaseItem, IItemByName
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "Genre-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "Genre-" + Name);
return list;
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using MediaBrowser.Model.Dto; using System.Collections.Generic;
using MediaBrowser.Model.Dto;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
{ {
@ -13,6 +14,8 @@ namespace MediaBrowser.Controller.Entities
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
string GetUserDataKey(); string GetUserDataKey();
List<string> GetUserDataKeys();
/// <summary> /// <summary>
/// Fills the user data dto values. /// Fills the user data dto values.
/// </summary> /// </summary>

View File

@ -75,34 +75,6 @@ namespace MediaBrowser.Controller.Entities.Movies
get { return TmdbCollectionName; } get { return TmdbCollectionName; }
set { TmdbCollectionName = value; } set { TmdbCollectionName = value; }
} }
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{
var key = GetMovieUserDataKey(this);
if (string.IsNullOrWhiteSpace(key))
{
key = base.CreateUserDataKey();
}
return key;
}
public static string GetMovieUserDataKey(BaseItem movie)
{
var key = movie.GetProviderId(MetadataProviders.Tmdb);
if (string.IsNullOrWhiteSpace(key))
{
key = movie.GetProviderId(MetadataProviders.Imdb);
}
return key;
}
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken) protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
{ {

View File

@ -44,15 +44,6 @@ namespace MediaBrowser.Controller.Entities
} }
} }
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{
return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.CreateUserDataKey();
}
public override UnratedItem GetBlockUnratedType() public override UnratedItem GetBlockUnratedType()
{ {
return UnratedItem.Music; return UnratedItem.Music;

View File

@ -18,13 +18,12 @@ namespace MediaBrowser.Controller.Entities
/// <value>The place of birth.</value> /// <value>The place of birth.</value>
public string PlaceOfBirth { get; set; } public string PlaceOfBirth { get; set; }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "Person-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "Person-" + Name);
return list;
} }
public PersonLookupInfo GetLookupInfo() public PersonLookupInfo GetLookupInfo()

View File

@ -10,13 +10,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public class Studio : BaseItem, IItemByName, IHasTags public class Studio : BaseItem, IItemByName, IHasTags
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "Studio-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "Studio-" + Name);
return list;
} }
/// <summary> /// <summary>

View File

@ -98,20 +98,26 @@ namespace MediaBrowser.Controller.Entities.TV
} }
} }
/// <summary> [IgnoreDataMember]
/// Gets the user data key. protected override bool EnableDefaultVideoUserDataKeys
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
var series = Series; get
{
return false;
}
}
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();
var series = Series;
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue) if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
{ {
return series.GetUserDataKey() + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000"); list.InsertRange(0, series.GetUserDataKeys().Select(i => i + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000")));
} }
return base.CreateUserDataKey(); return list;
} }
/// <summary> /// <summary>

View File

@ -53,19 +53,17 @@ namespace MediaBrowser.Controller.Entities.TV
}; };
} }
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
if (Series != null) var list = base.GetUserDataKeys();
var series = Series;
if (series != null)
{ {
var seasonNo = IndexNumber ?? 0; list.InsertRange(0, series.GetUserDataKeys().Select(i => i + (IndexNumber ?? 0).ToString("000")));
return Series.GetUserDataKey() + seasonNo.ToString("000");
} }
return base.CreateUserDataKey(); return list;
} }
/// <summary> /// <summary>

View File

@ -95,21 +95,23 @@ namespace MediaBrowser.Controller.Entities.TV
/// Gets the user data key. /// Gets the user data key.
/// </summary> /// </summary>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected override string CreateUserDataKey() public override List<string> GetUserDataKeys()
{ {
var key = this.GetProviderId(MetadataProviders.Tvdb); var list = base.GetUserDataKeys();
if (string.IsNullOrWhiteSpace(key)) var key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key))
{ {
key = this.GetProviderId(MetadataProviders.Imdb); list.Insert(0, key);
} }
if (string.IsNullOrWhiteSpace(key)) key = this.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrWhiteSpace(key))
{ {
key = base.CreateUserDataKey(); list.Insert(0, key);
} }
return key; return list;
} }
/// <summary> /// <summary>
@ -126,8 +128,8 @@ namespace MediaBrowser.Controller.Entities.TV
// Studio, Genre and Rating will all be the same so makes no sense to index by these // Studio, Genre and Rating will all be the same so makes no sense to index by these
protected override IEnumerable<string> GetIndexByOptions() protected override IEnumerable<string> GetIndexByOptions()
{ {
return new List<string> { return new List<string> {
{"None"}, {"None"},
{"Performer"}, {"Performer"},
{"Director"}, {"Director"},
{"Year"}, {"Year"},
@ -280,9 +282,9 @@ namespace MediaBrowser.Controller.Entities.TV
if (episode != null if (episode != null
&& refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh && refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh
&& !refreshOptions.ReplaceAllMetadata && !refreshOptions.ReplaceAllMetadata
&& episode.IsMissingEpisode && episode.IsMissingEpisode
&& episode.LocationType == Model.Entities.LocationType.Virtual && episode.LocationType == Model.Entities.LocationType.Virtual
&& episode.PremiereDate.HasValue && episode.PremiereDate.HasValue
&& (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30) && (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30)
{ {
skipItem = true; skipItem = true;

View File

@ -56,26 +56,6 @@ namespace MediaBrowser.Controller.Entities
/// <value>The revenue.</value> /// <value>The revenue.</value>
public double? Revenue { get; set; } public double? Revenue { get; set; }
protected override string CreateUserDataKey()
{
var key = Movie.GetMovieUserDataKey(this);
if (!string.IsNullOrWhiteSpace(key))
{
key = key + "-trailer";
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
}
return key;
}
return base.CreateUserDataKey();
}
public override UnratedItem GetBlockUnratedType() public override UnratedItem GetBlockUnratedType()
{ {
return UnratedItem.Trailer; return UnratedItem.Trailer;

View File

@ -131,27 +131,65 @@ namespace MediaBrowser.Controller.Entities
return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video))); return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
} }
protected override string CreateUserDataKey() [IgnoreDataMember]
protected virtual bool EnableDefaultVideoUserDataKeys
{ {
if (ExtraType.HasValue) get
{ {
var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb); return true;
}
}
if (!string.IsNullOrWhiteSpace(key)) public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();
if (EnableDefaultVideoUserDataKeys)
{
if (ExtraType.HasValue)
{ {
key = key + "-" + ExtraType.ToString().ToLower(); var key = this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{ {
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture); list.Insert(0, GetUserDataKey(key));
} }
return key; key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, GetUserDataKey(key));
}
}
else
{
var key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, key);
}
key = this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, key);
}
} }
} }
return base.CreateUserDataKey(); return list;
}
private string GetUserDataKey(string providerId)
{
var key = providerId + "-" + ExtraType.ToString().ToLower();
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
}
return key;
} }
/// <summary> /// <summary>

View File

@ -11,13 +11,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public class Year : BaseItem, IItemByName public class Year : BaseItem, IItemByName
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return "Year-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, "Year-" + Name);
return list;
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,7 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using System; using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Library namespace MediaBrowser.Controller.Library
{ {
@ -15,11 +16,7 @@ namespace MediaBrowser.Controller.Library
/// <value>The user id.</value> /// <value>The user id.</value>
public Guid UserId { get; set; } public Guid UserId { get; set; }
/// <summary> public List<string> Keys { get; set; }
/// Gets or sets the key.
/// </summary>
/// <value>The key.</value>
public string Key { get; set; }
/// <summary> /// <summary>
/// Gets or sets the save reason. /// Gets or sets the save reason.

View File

@ -45,17 +45,6 @@ namespace MediaBrowser.Controller.LiveTv
set { } set { }
} }
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{
var name = GetClientTypeName();
return name + "-" + Name + (EpisodeTitle ?? string.Empty);
}
/// <summary> /// <summary>
/// Gets a value indicating whether this instance is owned item. /// Gets a value indicating whether this instance is owned item.
/// </summary> /// </summary>

View File

@ -11,13 +11,12 @@ namespace MediaBrowser.Controller.LiveTv
{ {
public class LiveTvChannel : BaseItem, IHasMediaSources public class LiveTvChannel : BaseItem, IHasMediaSources
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
return GetClientTypeName() + "-" + Name; var list = base.GetUserDataKeys();
list.Insert(0, GetClientTypeName() + "-" + Name);
return list;
} }
public override UnratedItem GetBlockUnratedType() public override UnratedItem GetBlockUnratedType()

View File

@ -4,36 +4,40 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.LiveTv;
using System; using System;
using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.LiveTv namespace MediaBrowser.Controller.LiveTv
{ {
public class LiveTvProgram : BaseItem, IHasLookupInfo<LiveTvProgramLookupInfo>, IHasStartDate, IHasProgramAttributes public class LiveTvProgram : BaseItem, IHasLookupInfo<LiveTvProgramLookupInfo>, IHasStartDate, IHasProgramAttributes
{ {
/// <summary> public override List<string> GetUserDataKeys()
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{ {
if (IsMovie) var list = base.GetUserDataKeys();
{
var key = Movie.GetMovieUserDataKey(this);
if (!IsSeries)
{
var key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key)) if (!string.IsNullOrWhiteSpace(key))
{ {
return key; list.Insert(0, key);
}
key = this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, key);
} }
} }
else if (!string.IsNullOrWhiteSpace(EpisodeTitle))
if (IsSeries && !string.IsNullOrWhiteSpace(EpisodeTitle))
{ {
var name = GetClientTypeName(); var name = GetClientTypeName();
return name + "-" + Name + (EpisodeTitle ?? string.Empty); list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty));
} }
return base.CreateUserDataKey(); return list;
} }
[IgnoreDataMember] [IgnoreDataMember]

View File

@ -45,32 +45,6 @@ namespace MediaBrowser.Controller.LiveTv
set { } set { }
} }
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
{
if (IsMovie)
{
var key = Movie.GetMovieUserDataKey(this);
if (!string.IsNullOrWhiteSpace(key))
{
return key;
}
}
if (IsSeries && !string.IsNullOrWhiteSpace(EpisodeTitle))
{
var name = GetClientTypeName();
return name + "-" + Name + (EpisodeTitle ?? string.Empty);
}
return base.CreateUserDataKey();
}
[IgnoreDataMember] [IgnoreDataMember]
public override string MediaType public override string MediaType
{ {

View File

@ -56,27 +56,30 @@ namespace MediaBrowser.Server.Implementations.Library
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var key = item.GetUserDataKey(); var keys = item.GetUserDataKeys();
try foreach (var key in keys)
{ {
await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false); try
{
await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);
var newValue = userData; var newValue = userData;
// Once it succeeds, put it into the dictionary to make it available to everyone else // Once it succeeds, put it into the dictionary to make it available to everyone else
_userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; }); _userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.ErrorException("Error saving user data", ex); _logger.ErrorException("Error saving user data", ex);
throw; throw;
}
} }
EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
{ {
Key = key, Keys = keys,
UserData = userData, UserData = userData,
SaveReason = reason, SaveReason = reason,
UserId = userId, UserId = userId,