reduced property virtualization
This commit is contained in:
parent
b7f927d43a
commit
b1b4e77178
|
@ -54,24 +54,6 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
get { return Parent as MusicArtist ?? UnknwonArtist; }
|
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>
|
/// <summary>
|
||||||
/// Override to point to first child (song)
|
/// Override to point to first child (song)
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets or sets the images.
|
/// Gets or sets the images.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -149,24 +113,6 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
return RecursiveChildren.OfType<Audio>().Any(i => i.HasArtist(artist));
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the music brainz release group id.
|
/// Gets or sets the music brainz release group id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -532,12 +532,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
get { return Genres; }
|
get { return Genres; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the studios.
|
/// Gets or sets the studios.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The studios.</value>
|
/// <value>The studios.</value>
|
||||||
public virtual List<string> Studios { get; set; }
|
public List<string> Studios { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the genres.
|
/// Gets or sets the genres.
|
||||||
|
@ -613,7 +613,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// Gets or sets the production year.
|
/// Gets or sets the production year.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The production year.</value>
|
/// <value>The production year.</value>
|
||||||
public virtual int? ProductionYear { get; set; }
|
public int? ProductionYear { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If the item is part of a series, this is it's number in the series.
|
/// If the item is part of a series, this is it's number in the series.
|
||||||
|
@ -1022,7 +1022,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
rating = OfficialRatingForComparison;
|
rating = OfficialRatingForComparison;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(rating))
|
if (string.IsNullOrEmpty(rating))
|
||||||
{
|
{
|
||||||
return !user.Configuration.BlockNotRated;
|
return !user.Configuration.BlockNotRated;
|
||||||
|
|
|
@ -70,20 +70,23 @@ namespace MediaBrowser.Controller.Resolvers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The audio file extensions
|
/// The audio file extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly Dictionary<string,string> AudioFileExtensions = new[] {
|
public static readonly string[] AudioFileExtensions = new[]
|
||||||
".mp3",
|
{
|
||||||
".flac",
|
".mp3",
|
||||||
".wma",
|
".flac",
|
||||||
".aac",
|
".wma",
|
||||||
".acc",
|
".aac",
|
||||||
".m4a",
|
".acc",
|
||||||
".m4b",
|
".m4a",
|
||||||
".wav",
|
".m4b",
|
||||||
".ape",
|
".wav",
|
||||||
".ogg",
|
".ape",
|
||||||
".oga"
|
".ogg",
|
||||||
|
".oga"
|
||||||
|
|
||||||
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
};
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, string> AudioFileExtensionsDictionary = AudioFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether [is audio file] [the specified args].
|
/// Determines whether [is audio file] [the specified args].
|
||||||
|
@ -99,7 +102,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AudioFileExtensions.ContainsKey(extension);
|
return AudioFileExtensionsDictionary.ContainsKey(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
<Compile Include="Movies\OpenMovieDatabaseProvider.cs" />
|
<Compile Include="Movies\OpenMovieDatabaseProvider.cs" />
|
||||||
<Compile Include="Movies\PersonProviderFromXml.cs" />
|
<Compile Include="Movies\PersonProviderFromXml.cs" />
|
||||||
<Compile Include="Movies\TmdbPersonProvider.cs" />
|
<Compile Include="Movies\TmdbPersonProvider.cs" />
|
||||||
|
<Compile Include="Music\AlbumInfoFromSongProvider.cs" />
|
||||||
<Compile Include="Music\ArtistProviderFromXml.cs" />
|
<Compile Include="Music\ArtistProviderFromXml.cs" />
|
||||||
<Compile Include="Music\ArtistsPostScanTask.cs" />
|
<Compile Include="Music\ArtistsPostScanTask.cs" />
|
||||||
<Compile Include="Music\FanArtAlbumProvider.cs" />
|
<Compile Include="Music\FanArtAlbumProvider.cs" />
|
||||||
|
|
126
MediaBrowser.Providers/Music/AlbumInfoFromSongProvider.cs
Normal file
126
MediaBrowser.Providers/Music/AlbumInfoFromSongProvider.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user