reduced property virtualization

This commit is contained in:
Luke Pulverenti 2013-08-07 11:59:13 -04:00
parent b7f927d43a
commit b1b4e77178
5 changed files with 148 additions and 72 deletions

View File

@ -54,24 +54,6 @@ namespace MediaBrowser.Controller.Entities.Audio
get { return Parent as MusicArtist ?? UnknwonArtist; }
}
/// <summary>
/// Override to point to first child (song)
/// </summary>
/// <value>The production year.</value>
public override int? ProductionYear
{
get
{
var child = Children.FirstOrDefault();
return child == null ? base.ProductionYear : child.ProductionYear;
}
set
{
base.ProductionYear = value;
}
}
/// <summary>
/// Override to point to first child (song)
/// </summary>
@ -92,24 +74,6 @@ namespace MediaBrowser.Controller.Entities.Audio
}
}
/// <summary>
/// Override to point to first child (song)
/// </summary>
/// <value>The studios.</value>
public override List<string> Studios
{
get
{
var child = Children.FirstOrDefault();
return child == null ? base.Studios : child.Studios;
}
set
{
base.Studios = value;
}
}
/// <summary>
/// Gets or sets the images.
/// </summary>
@ -149,24 +113,6 @@ namespace MediaBrowser.Controller.Entities.Audio
return RecursiveChildren.OfType<Audio>().Any(i => i.HasArtist(artist));
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public override string Name
{
get
{
var song = RecursiveChildren.OfType<Audio>().FirstOrDefault(i => !string.IsNullOrEmpty(i.Album));
return song == null ? base.Name : song.Album;
}
set
{
base.Name = value;
}
}
/// <summary>
/// Gets or sets the music brainz release group id.
/// </summary>

View File

@ -537,7 +537,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the studios.
/// </summary>
/// <value>The studios.</value>
public virtual List<string> Studios { get; set; }
public List<string> Studios { get; set; }
/// <summary>
/// Gets or sets the genres.
@ -613,7 +613,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the production year.
/// </summary>
/// <value>The production year.</value>
public virtual int? ProductionYear { get; set; }
public int? ProductionYear { get; set; }
/// <summary>
/// If the item is part of a series, this is it's number in the series.

View File

@ -70,20 +70,23 @@ namespace MediaBrowser.Controller.Resolvers
/// <summary>
/// The audio file extensions
/// </summary>
private static readonly Dictionary<string,string> AudioFileExtensions = new[] {
".mp3",
".flac",
".wma",
".aac",
".acc",
".m4a",
".m4b",
".wav",
".ape",
".ogg",
".oga"
public static readonly string[] AudioFileExtensions = new[]
{
".mp3",
".flac",
".wma",
".aac",
".acc",
".m4a",
".m4b",
".wav",
".ape",
".ogg",
".oga"
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
};
private static readonly Dictionary<string, string> AudioFileExtensionsDictionary = AudioFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Determines whether [is audio file] [the specified args].
@ -99,7 +102,7 @@ namespace MediaBrowser.Controller.Resolvers
return false;
}
return AudioFileExtensions.ContainsKey(extension);
return AudioFileExtensionsDictionary.ContainsKey(extension);
}
/// <summary>

View File

@ -66,6 +66,7 @@
<Compile Include="Movies\OpenMovieDatabaseProvider.cs" />
<Compile Include="Movies\PersonProviderFromXml.cs" />
<Compile Include="Movies\TmdbPersonProvider.cs" />
<Compile Include="Music\AlbumInfoFromSongProvider.cs" />
<Compile Include="Music\ArtistProviderFromXml.cs" />
<Compile Include="Music\ArtistsPostScanTask.cs" />
<Compile Include="Music\FanArtAlbumProvider.cs" />

View File

@ -0,0 +1,126 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
public class AlbumInfoFromSongProvider : BaseMetadataProvider
{
public AlbumInfoFromSongProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
: base(logManager, configurationManager)
{
}
public override bool Supports(BaseItem item)
{
return item is MusicAlbum;
}
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
// If song metadata has changed
if (GetComparisonData((MusicAlbum)item) != providerInfo.FileStamp)
{
return true;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
/// Gets the data.
/// </summary>
/// <param name="album">The album.</param>
/// <returns>Guid.</returns>
private Guid GetComparisonData(MusicAlbum album)
{
var songs = album.RecursiveChildren.OfType<Audio>().ToList();
return GetComparisonData(songs);
}
private Guid GetComparisonData(List<Audio> songs)
{
var albumNames = songs.Select(i => i.AlbumArtist)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
var studios = songs.SelectMany(i => i.Studios)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
var genres = songs.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
albumNames.AddRange(studios);
albumNames.AddRange(genres);
return string.Join(string.Empty, albumNames.OrderBy(i => i).ToArray()).GetMD5();
}
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var album = (MusicAlbum)item;
BaseProviderInfo data;
if (!item.ProviderData.TryGetValue(Id, out data))
{
data = new BaseProviderInfo();
item.ProviderData[Id] = data;
}
var songs = album.RecursiveChildren.OfType<Audio>().ToList();
if (!item.LockedFields.Contains(MetadataFields.Name))
{
var name = songs.Select(i => i.Name).FirstOrDefault(i => !string.IsNullOrEmpty(i));
if (!string.IsNullOrEmpty(name))
{
album.Name = name;
}
}
var year = songs.Select(i => i.ProductionYear ?? 1800).FirstOrDefault(i => i != 1800);
if (year != 1800)
{
album.ProductionYear = year;
}
if (!item.LockedFields.Contains(MetadataFields.Studios))
{
album.Studios = songs.SelectMany(i => i.Studios)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
if (!item.LockedFields.Contains(MetadataFields.Genres))
{
album.Genres = songs.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
data.FileStamp = GetComparisonData(songs);
SetLastRefreshed(item, DateTime.UtcNow);
return TrueTaskResult;
}
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Second; }
}
}
}