fixes #15 - SortRemoveWords config change not working
This commit is contained in:
parent
f4ec4876d3
commit
76dbab939c
|
@ -74,5 +74,15 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||
return Model.Entities.MediaType.Audio;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the name of the sort.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
protected override string CreateSortName()
|
||||
{
|
||||
return (ProductionYear != null ? ProductionYear.Value.ToString("000-") : "")
|
||||
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,5 +129,14 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||
base.Studios = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the name of the sort.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
protected override string CreateSortName()
|
||||
{
|
||||
return ProductionYear != null ? ProductionYear.Value.ToString("0000") : Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -370,11 +370,58 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the forced sort.
|
||||
/// </summary>
|
||||
/// <value>The name of the forced sort.</value>
|
||||
public string ForcedSortName { get; set; }
|
||||
|
||||
private string _sortName;
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the sort.
|
||||
/// </summary>
|
||||
/// <value>The name of the sort.</value>
|
||||
public string SortName { get; set; }
|
||||
[IgnoreDataMember]
|
||||
public string SortName
|
||||
{
|
||||
get
|
||||
{
|
||||
return ForcedSortName ?? _sortName ?? (_sortName = CreateSortName());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the name of the sort.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
protected virtual string CreateSortName()
|
||||
{
|
||||
if (Name == null) return null; //some items may not have name filled in properly
|
||||
|
||||
var sortable = Name.Trim().ToLower();
|
||||
sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
|
||||
|
||||
sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
|
||||
|
||||
foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
|
||||
{
|
||||
var searchLower = search.ToLower();
|
||||
// Remove from beginning if a space follows
|
||||
if (sortable.StartsWith(searchLower + " "))
|
||||
{
|
||||
sortable = sortable.Remove(0, searchLower.Length + 1);
|
||||
}
|
||||
// Remove from middle if surrounded by spaces
|
||||
sortable = sortable.Replace(" " + searchLower + " ", " ");
|
||||
|
||||
// Remove from end if followed by a space
|
||||
if (sortable.EndsWith(" " + searchLower))
|
||||
{
|
||||
sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
|
||||
}
|
||||
}
|
||||
return sortable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parent.
|
||||
|
@ -686,7 +733,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
public virtual void ClearMetaValues()
|
||||
{
|
||||
Images = null;
|
||||
SortName = null;
|
||||
ForcedSortName = null;
|
||||
PremiereDate = null;
|
||||
BackdropImagePaths = null;
|
||||
OfficialRating = null;
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
GroupContents = groupContents;
|
||||
if (shadow == null)
|
||||
{
|
||||
Name = SortName = "<Unknown>";
|
||||
Name = ForcedSortName = "<Unknown>";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
if (ShadowItem != null)
|
||||
{
|
||||
Name = ShadowItem.Name;
|
||||
SortName = ShadowItem.SortName;
|
||||
ForcedSortName = ShadowItem.SortName;
|
||||
Genres = ShadowItem.Genres;
|
||||
Studios = ShadowItem.Studios;
|
||||
OfficialRating = ShadowItem.OfficialRating;
|
||||
|
|
|
@ -159,5 +159,14 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
get { return _season ?? (_season = FindParent<Season>()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the name of the sort.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
protected override string CreateSortName()
|
||||
{
|
||||
return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("000-") : "")
|
||||
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,5 +138,14 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
|
||||
return args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the name of the sort.
|
||||
/// </summary>
|
||||
/// <returns>System.String.</returns>
|
||||
protected override string CreateSortName()
|
||||
{
|
||||
return IndexNumber != null ? IndexNumber.Value.ToString("0000") : Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,6 @@
|
|||
<Compile Include="Providers\Movies\MovieProviderFromXml.cs" />
|
||||
<Compile Include="Providers\Movies\PersonProviderFromJson.cs" />
|
||||
<Compile Include="Providers\Movies\TmdbPersonProvider.cs" />
|
||||
<Compile Include="Providers\SortNameProvider.cs" />
|
||||
<Compile Include="Providers\TV\EpisodeImageFromMediaLocationProvider.cs" />
|
||||
<Compile Include="Providers\TV\EpisodeProviderFromXml.cs" />
|
||||
<Compile Include="Providers\TV\EpisodeXmlParser.cs" />
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
break;
|
||||
}
|
||||
case "SortTitle":
|
||||
item.SortName = reader.ReadElementContentAsString();
|
||||
item.ForcedSortName = reader.ReadElementContentAsString();
|
||||
break;
|
||||
|
||||
case "Overview":
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SortNameProvider
|
||||
/// </summary>
|
||||
public class SortNameProvider : BaseMetadataProvider
|
||||
{
|
||||
public SortNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
|
||||
: base(logManager, configurationManager)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supportses the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get { return MetadataProviderPriority.Last; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
return !string.IsNullOrEmpty(item.Name) && string.IsNullOrEmpty(item.SortName);
|
||||
}
|
||||
|
||||
// Cache these since they will be used a lot
|
||||
/// <summary>
|
||||
/// The false task result
|
||||
/// </summary>
|
||||
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
|
||||
|
||||
/// <summary>
|
||||
/// The true task result
|
||||
/// </summary>
|
||||
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="force">if set to <c>true</c> [force].</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
return SetSortName(item, cancellationToken) ? TrueTaskResult : FalseTaskResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the name of the sort.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected bool SetSortName(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(item.SortName)) return false; //let the earlier provider win
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (item is Episode)
|
||||
{
|
||||
//special handling for TV episodes season and episode number
|
||||
item.SortName = (item.ParentIndexNumber != null ? item.ParentIndexNumber.Value.ToString("000-") : "")
|
||||
+ (item.IndexNumber != null ? item.IndexNumber.Value.ToString("0000 - ") : "") + item.Name;
|
||||
|
||||
}
|
||||
else if (item is Season)
|
||||
{
|
||||
//sort seasons by season number - numerically
|
||||
item.SortName = item.IndexNumber != null ? item.IndexNumber.Value.ToString("0000") : item.Name;
|
||||
}
|
||||
else if (item is Audio)
|
||||
{
|
||||
//sort tracks by production year and index no so they will sort in order if in a multi-album list
|
||||
item.SortName = (item.ProductionYear != null ? item.ProductionYear.Value.ToString("000-") : "")
|
||||
+ (item.IndexNumber != null ? item.IndexNumber.Value.ToString("0000 - ") : "") + item.Name;
|
||||
}
|
||||
else if (item is MusicAlbum)
|
||||
{
|
||||
//sort albums by year
|
||||
item.SortName = item.ProductionYear != null ? item.ProductionYear.Value.ToString("0000") : item.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Name == null) return false; //some items may not have name filled in properly
|
||||
|
||||
var sortable = item.Name.Trim().ToLower();
|
||||
sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
|
||||
|
||||
sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
|
||||
|
||||
foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var searchLower = search.ToLower();
|
||||
// Remove from beginning if a space follows
|
||||
if (sortable.StartsWith(searchLower + " "))
|
||||
{
|
||||
sortable = sortable.Remove(0, searchLower.Length + 1);
|
||||
}
|
||||
// Remove from middle if surrounded by spaces
|
||||
sortable = sortable.Replace(" " + searchLower + " ", " ");
|
||||
|
||||
// Remove from end if followed by a space
|
||||
if (sortable.EndsWith(" " + searchLower))
|
||||
{
|
||||
sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
|
||||
}
|
||||
}
|
||||
item.SortName = sortable;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user