Skip to content

Commit

Permalink
support multiple user data keys
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Apr 30, 2016
1 parent 1f9d32a commit 6330b13
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 263 deletions.
34 changes: 16 additions & 18 deletions MediaBrowser.Controller/Entities/Audio/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Audio : BaseItem,
IArchivable
{
public List<ChannelMediaInfo> ChannelMediaSources { get; set; }

public long? Size { get; set; }
public string Container { get; set; }
public int? TotalBitrate { get; set; }
Expand Down Expand Up @@ -150,12 +150,10 @@ protected override string CreateSortName()
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
}

/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();

if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys)
{
var songKey = IndexNumber.HasValue ? IndexNumber.Value.ToString("0000") : string.Empty;
Expand All @@ -165,7 +163,7 @@ protected override string CreateUserDataKey()
{
songKey = ParentIndexNumber.Value.ToString("0000") + "-" + songKey;
}
songKey+= Name;
songKey += Name;

if (!string.IsNullOrWhiteSpace(Album))
{
Expand All @@ -178,25 +176,25 @@ protected override string CreateUserDataKey()
songKey = albumArtist + "-" + songKey;
}

return songKey;
list.Insert(0, songKey);
}

var parent = AlbumEntity;

if (parent != null)
else
{
var parentKey = parent.GetUserDataKey();
var parent = AlbumEntity;

if (IndexNumber.HasValue)
if (parent != null && IndexNumber.HasValue)
{
var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
+ IndexNumber.Value.ToString("0000 - ");
list.InsertRange(0, parent.GetUserDataKeys().Select(i =>
{
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()
Expand Down
32 changes: 15 additions & 17 deletions MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,36 +96,34 @@ protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren

public List<string> Artists { get; set; }

/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
var id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
var list = base.GetUserDataKeys();

if (!string.IsNullOrWhiteSpace(id))
if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys)
{
return "MusicAlbum-MusicBrainzReleaseGroup-" + id;
var albumArtist = AlbumArtist;
if (!string.IsNullOrWhiteSpace(albumArtist))
{
list.Insert(0, albumArtist + "-" + Name);
}
}

id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);
var id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);

if (!string.IsNullOrWhiteSpace(id))
{
return "MusicAlbum-Musicbrainz-" + id;
list.Insert(0, "MusicAlbum-Musicbrainz-" + id);
}

if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys)
id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);

if (!string.IsNullOrWhiteSpace(id))
{
var albumArtist = AlbumArtist;
if (!string.IsNullOrWhiteSpace(albumArtist))
{
return albumArtist + "-" + Name;
}
list.Insert(0, "MusicAlbum-MusicBrainzReleaseGroup-" + id);
}

return base.CreateUserDataKey();
return list;
}

protected override bool GetBlockUnratedValue(UserPolicy config)
Expand Down
19 changes: 10 additions & 9 deletions MediaBrowser.Controller/Entities/Audio/MusicArtist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ public MusicArtist()
ProductionLocations = new List<string>();
}

/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
return GetUserDataKey(this);
var list = base.GetUserDataKeys();

list.InsertRange(0, GetUserDataKeys(this));
return list;
}

/// <summary>
Expand Down Expand Up @@ -121,16 +120,18 @@ public override bool IsOwnedItem
/// </summary>
/// <param name="item">The item.</param>
/// <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);

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)
Expand Down
11 changes: 5 additions & 6 deletions MediaBrowser.Controller/Entities/Audio/MusicGenre.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary>
public class MusicGenre : BaseItem, IItemByName
{
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
return "MusicGenre-" + Name;
var list = base.GetUserDataKeys();

list.Insert(0, "MusicGenre-" + Name);
return list;
}

[IgnoreDataMember]
Expand Down
12 changes: 8 additions & 4 deletions MediaBrowser.Controller/Entities/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,24 +1158,28 @@ public string GetUserDataKey()
{
if (string.IsNullOrWhiteSpace(_userDataKey))
{
var key = CreateUserDataKey();
var key = GetUserDataKeys().First();
_userDataKey = key;
return key;
}

return _userDataKey;
}

protected virtual string CreateUserDataKey()
public virtual List<string> GetUserDataKeys()
{
var list = new List<string>();

if (SourceType == SourceType.Channel)
{
if (!string.IsNullOrWhiteSpace(ExternalId))
{
return ExternalId;
list.Add(ExternalId);
}
}
return Id.ToString();

list.Add(Id.ToString());
return list;
}

internal virtual bool IsValidFromResolver(BaseItem newItem)
Expand Down
7 changes: 4 additions & 3 deletions MediaBrowser.Controller/Entities/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public override string MediaType
/// </summary>
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);

if (!string.IsNullOrEmpty(id))
{
return "Game-Gamesdb-" + id;
list.Insert(0, "Game-Gamesdb-" + id);
}
return base.CreateUserDataKey();
return list;
}

public override IEnumerable<string> GetDeletePaths()
Expand Down
11 changes: 5 additions & 6 deletions MediaBrowser.Controller/Entities/GameGenre.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ namespace MediaBrowser.Controller.Entities
{
public class GameGenre : BaseItem, IItemByName
{
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
return "GameGenre-" + Name;
var list = base.GetUserDataKeys();

list.Insert(0, "GameGenre-" + Name);
return list;
}

/// <summary>
Expand Down
13 changes: 6 additions & 7 deletions MediaBrowser.Controller/Entities/GameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Users;

namespace MediaBrowser.Controller.Entities
Expand Down Expand Up @@ -31,17 +32,15 @@ public override Guid DisplayPreferencesId
/// <value>The game system.</value>
public string GameSystemName { get; set; }

/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();

if (!string.IsNullOrEmpty(GameSystemName))
{
return "GameSystem-" + GameSystemName;
list.Insert(0, "GameSystem-" + GameSystemName);
}
return base.CreateUserDataKey();
return list;
}

protected override bool GetBlockUnratedValue(UserPolicy config)
Expand Down
11 changes: 5 additions & 6 deletions MediaBrowser.Controller/Entities/Genre.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Genre : BaseItem, IItemByName
{
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
return "Genre-" + Name;
var list = base.GetUserDataKeys();

list.Insert(0, "Genre-" + Name);
return list;
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion MediaBrowser.Controller/Entities/IHasUserData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Model.Dto;
using System.Collections.Generic;
using MediaBrowser.Model.Dto;

namespace MediaBrowser.Controller.Entities
{
Expand All @@ -13,6 +14,8 @@ public interface IHasUserData : IHasId
/// <returns>System.String.</returns>
string GetUserDataKey();

List<string> GetUserDataKeys();

/// <summary>
/// Fills the user data dto values.
/// </summary>
Expand Down
28 changes: 0 additions & 28 deletions MediaBrowser.Controller/Entities/Movies/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,6 @@ public string CollectionName
get { return TmdbCollectionName; }
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)
{
Expand Down
9 changes: 0 additions & 9 deletions MediaBrowser.Controller/Entities/MusicVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ public List<string> AllArtists
}
}

/// <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()
{
return UnratedItem.Music;
Expand Down
11 changes: 5 additions & 6 deletions MediaBrowser.Controller/Entities/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ public class Person : BaseItem, IItemByName, IHasLookupInfo<PersonLookupInfo>
/// <value>The place of birth.</value>
public string PlaceOfBirth { get; set; }

/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateUserDataKey()
public override List<string> GetUserDataKeys()
{
return "Person-" + Name;
var list = base.GetUserDataKeys();

list.Insert(0, "Person-" + Name);
return list;
}

public PersonLookupInfo GetLookupInfo()
Expand Down
Loading

0 comments on commit 6330b13

Please sign in to comment.