switch to generic lookup type

This commit is contained in:
Luke Pulverenti
2014-02-06 22:10:13 -05:00
parent 57c92fa948
commit b1713a16cd
74 changed files with 458 additions and 202 deletions

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,7 +10,7 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class Audio
/// </summary>
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasLookupInfo<SongInfo>
{
public Audio()
{
@@ -127,5 +128,16 @@ namespace MediaBrowser.Controller.Entities.Audio
{
return config.BlockUnratedMusic;
}
public SongInfo GetLookupInfo()
{
var info = GetItemLookupInfo<SongInfo>();
info.AlbumArtist = AlbumArtist;
info.Album = Album;
info.Artists = Artists;
return info;
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
@@ -10,10 +11,10 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class MusicAlbum
/// </summary>
public class MusicAlbum : Folder, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasTags
public class MusicAlbum : Folder, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasTags, IHasLookupInfo<AlbumInfo>
{
public List<Guid> SoundtrackIds { get; set; }
public MusicAlbum()
{
Artists = new List<string>();
@@ -112,6 +113,26 @@ namespace MediaBrowser.Controller.Entities.Audio
{
return config.BlockUnratedMusic;
}
public AlbumInfo GetLookupInfo()
{
var id = GetItemLookupInfo<AlbumInfo>();
id.AlbumArtist = AlbumArtist;
var artist = Parents.OfType<MusicArtist>().FirstOrDefault();
if (artist != null)
{
id.ArtistProviderIds = artist.ProviderIds;
}
id.SongInfos = RecursiveChildren.OfType<Audio>()
.Select(i => i.GetLookupInfo())
.ToList();
return id;
}
}
public class MusicAlbumDisc : Folder

View File

@@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class MusicArtist
/// </summary>
public class MusicArtist : Folder, IMetadataContainer, IItemByName, IHasMusicGenres, IHasDualAccess, IHasTags, IHasProductionLocations
public class MusicArtist : Folder, IMetadataContainer, IItemByName, IHasMusicGenres, IHasDualAccess, IHasTags, IHasProductionLocations, IHasLookupInfo<ArtistInfo>
{
[IgnoreDataMember]
public List<ItemByNameCounts> UserItemCountList { get; set; }
@@ -201,5 +201,16 @@ namespace MediaBrowser.Controller.Entities.Audio
progress.Report(100);
}
public ArtistInfo GetLookupInfo()
{
var info = GetItemLookupInfo<ArtistInfo>();
info.SongInfos = RecursiveChildren.OfType<Audio>()
.Select(i => i.GetLookupInfo())
.ToList();
return info;
}
}
}

View File

@@ -21,7 +21,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Class BaseItem
/// </summary>
public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData, IHasMetadata
public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData, IHasMetadata, IHasLookupInfo<ItemLookupInfo>
{
protected BaseItem()
{
@@ -236,7 +236,7 @@ namespace MediaBrowser.Controller.Entities
{
var locationType = LocationType;
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
{
return new string[] { };
}
@@ -610,7 +610,7 @@ namespace MediaBrowser.Controller.Entities
localTrailersChanged = await RefreshLocalTrailers(hasTrailers, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
}
}
if (themeSongsChanged || themeVideosChanged || localTrailersChanged)
{
options.ForceSave = true;
@@ -1455,5 +1455,24 @@ namespace MediaBrowser.Controller.Entities
return userdata == null || !userdata.Played;
}
ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
{
return GetItemLookupInfo<ItemLookupInfo>();
}
protected T GetItemLookupInfo<T>()
where T : ItemLookupInfo, new()
{
return new T
{
MetadataCountryCode = GetPreferredMetadataCountryCode(),
MetadataLanguage = GetPreferredMetadataLanguage(),
Name = Name,
ProviderIds = ProviderIds,
IndexNumber = IndexNumber,
ParentIndexNumber = ParentIndexNumber
};
}
}
}

View File

@@ -1,9 +1,10 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
public class Book : BaseItem, IHasTags, IHasPreferredMetadataLanguage
public class Book : BaseItem, IHasTags, IHasPreferredMetadataLanguage, IHasLookupInfo<BookInfo>
{
public override string MediaType
{
@@ -38,5 +39,10 @@ namespace MediaBrowser.Controller.Entities
{
return config.BlockUnratedBooks;
}
public BookInfo GetLookupInfo()
{
return GetItemLookupInfo<BookInfo>();
}
}
}

View File

@@ -1,11 +1,12 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
public class Game : BaseItem, IHasSoundtracks, IHasTrailers, IHasThemeMedia, IHasTags, IHasScreenshots, IHasPreferredMetadataLanguage
public class Game : BaseItem, IHasSoundtracks, IHasTrailers, IHasThemeMedia, IHasTags, IHasScreenshots, IHasPreferredMetadataLanguage, IHasLookupInfo<GameInfo>
{
public List<Guid> SoundtrackIds { get; set; }
@@ -115,5 +116,14 @@ namespace MediaBrowser.Controller.Entities
{
return config.BlockUnratedGames;
}
public GameInfo GetLookupInfo()
{
var id = GetItemLookupInfo<GameInfo>();
id.GameSystem = GameSystem;
return id;
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using System;
@@ -7,7 +8,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Class GameSystem
/// </summary>
public class GameSystem : Folder
public class GameSystem : Folder, IHasLookupInfo<GameSystemInfo>
{
/// <summary>
/// Return the id that should be used to key display prefs for this item.
@@ -47,5 +48,14 @@ namespace MediaBrowser.Controller.Entities
// Don't block. Determine by game
return false;
}
public GameSystemInfo GetLookupInfo()
{
var id = GetItemLookupInfo<GameSystemInfo>();
id.Path = Path;
return id;
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Interface IHasMetadata
/// </summary>
public interface IHasMetadata : IHasImages
{
/// <summary>
/// Gets the preferred metadata country code.
/// </summary>
/// <returns>System.String.</returns>
string GetPreferredMetadataCountryCode();
/// <summary>
/// Gets the date modified.
/// </summary>
/// <value>The date modified.</value>
DateTime DateModified { get; }
/// <summary>
/// Gets the locked fields.
/// </summary>
/// <value>The locked fields.</value>
List<MetadataFields> LockedFields { get; }
/// <summary>
/// Gets or sets the date last saved.
/// </summary>
/// <value>The date last saved.</value>
DateTime DateLastSaved { get; set; }
/// <summary>
/// Determines whether [is save local metadata enabled].
/// </summary>
/// <returns><c>true</c> if [is save local metadata enabled]; otherwise, <c>false</c>.</returns>
bool IsSaveLocalMetadataEnabled();
/// <summary>
/// Gets a value indicating whether this instance is in mixed folder.
/// </summary>
/// <value><c>true</c> if this instance is in mixed folder; otherwise, <c>false</c>.</value>
bool IsInMixedFolder { get; }
}
}

View File

@@ -1,15 +1,20 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class BoxSet
/// </summary>
public class BoxSet : Folder, IHasTrailers, IHasTags, IHasKeywords, IHasPreferredMetadataLanguage, IHasDisplayOrder
public class BoxSet : Folder, IHasTrailers, IHasTags, IHasKeywords, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>, IMetadataContainer
{
public BoxSet()
{
@@ -74,5 +79,67 @@ namespace MediaBrowser.Controller.Entities.Movies
// Default sorting
return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
}
public BoxSetInfo GetLookupInfo()
{
return GetItemLookupInfo<BoxSetInfo>();
}
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
{
// Refresh bottom up, children first, then the boxset
// By then hopefully the movies within will have Tmdb collection values
var items = RecursiveChildren.ToList();
var totalItems = items.Count;
var percentages = new Dictionary<Guid, double>(totalItems);
var tasks = new List<Task>();
// Refresh songs
foreach (var item in items)
{
if (tasks.Count > 3)
{
await Task.WhenAll(tasks).ConfigureAwait(false);
tasks.Clear();
}
cancellationToken.ThrowIfCancellationRequested();
var innerProgress = new ActionableProgress<double>();
// Avoid implicitly captured closure
var currentChild = item;
innerProgress.RegisterAction(p =>
{
lock (percentages)
{
percentages[currentChild.Id] = p / 100;
var percent = percentages.Values.Sum();
percent /= totalItems;
percent *= 100;
progress.Report(percent);
}
});
tasks.Add(RefreshItem(item, refreshOptions, innerProgress, cancellationToken));
}
await Task.WhenAll(tasks).ConfigureAwait(false);
tasks.Clear();
// Refresh current item
await RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
private async Task RefreshItem(BaseItem item, MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
{
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
}
}

View File

@@ -13,7 +13,7 @@ namespace MediaBrowser.Controller.Entities.Movies
/// <summary>
/// Class Movie
/// </summary>
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasTags, IHasPreferredMetadataLanguage, IHasAwards, IHasMetascore
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasTags, IHasPreferredMetadataLanguage, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>
{
public List<Guid> SpecialFeatureIds { get; set; }
@@ -166,5 +166,10 @@ namespace MediaBrowser.Controller.Entities.Movies
{
return config.BlockUnratedMovies;
}
public MovieInfo GetLookupInfo()
{
return GetItemLookupInfo<MovieInfo>();
}
}
}

View File

@@ -1,11 +1,12 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using System;
namespace MediaBrowser.Controller.Entities
{
public class MusicVideo : Video, IHasArtist, IHasMusicGenres, IHasBudget
public class MusicVideo : Video, IHasArtist, IHasMusicGenres, IHasBudget, IHasLookupInfo<MusicVideoInfo>
{
/// <summary>
/// Gets or sets the artist.
@@ -54,5 +55,10 @@ namespace MediaBrowser.Controller.Entities
{
return config.BlockUnratedMusic;
}
public MusicVideoInfo GetLookupInfo()
{
return GetItemLookupInfo<MusicVideoInfo>();
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Model.Dto;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using System.Collections.Generic;
using System.Runtime.Serialization;
@@ -7,7 +8,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// This is the full Person object that can be retrieved with all of it's data.
/// </summary>
public class Person : BaseItem, IItemByName
public class Person : BaseItem, IItemByName, IHasLookupInfo<Providers.PersonLookupInfo>
{
public Person()
{
@@ -31,6 +32,11 @@ namespace MediaBrowser.Controller.Entities
{
return "Person-" + Name;
}
public Providers.PersonLookupInfo GetLookupInfo()
{
return GetItemLookupInfo<Providers.PersonLookupInfo>();
}
}
/// <summary>

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,7 +10,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// <summary>
/// Class Episode
/// </summary>
public class Episode : Video
public class Episode : Video, IHasLookupInfo<EpisodeInfo>
{
/// <summary>
/// Gets the season in which it aired.
@@ -41,7 +42,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// </summary>
/// <value>The index number.</value>
public int? IndexNumberEnd { get; set; }
/// <summary>
/// We want to group into series not show individually in an index
/// </summary>
@@ -233,5 +234,21 @@ namespace MediaBrowser.Controller.Entities.TV
{
return config.BlockUnratedSeries;
}
public EpisodeInfo GetLookupInfo()
{
var id = GetItemLookupInfo<EpisodeInfo>();
var series = Series;
if (series != null)
{
id.SeriesProviderIds = series.ProviderIds;
}
id.IndexNumberEnd = IndexNumberEnd;
return id;
}
}
}

View File

@@ -1,5 +1,6 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
@@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// <summary>
/// Class Series
/// </summary>
public class Series : Folder, IHasSoundtracks, IHasTrailers, IHasTags, IHasPreferredMetadataLanguage, IHasDisplayOrder
public class Series : Folder, IHasSoundtracks, IHasTrailers, IHasTags, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>
{
public List<Guid> SpecialFeatureIds { get; set; }
public List<Guid> SoundtrackIds { get; set; }
@@ -222,5 +223,10 @@ namespace MediaBrowser.Controller.Entities.TV
}
public string PreferredMetadataLanguage { get; set; }
public SeriesInfo GetLookupInfo()
{
return GetItemLookupInfo<SeriesInfo>();
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Model.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
@@ -9,7 +10,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Class Trailer
/// </summary>
public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers, IHasKeywords, IHasTaglines, IHasTags, IHasPreferredMetadataLanguage, IHasMetascore
public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers, IHasKeywords, IHasTaglines, IHasTags, IHasPreferredMetadataLanguage, IHasMetascore, IHasLookupInfo<TrailerInfo>
{
public List<Guid> SoundtrackIds { get; set; }
@@ -105,5 +106,10 @@ namespace MediaBrowser.Controller.Entities
{
return config.BlockUnratedTrailers;
}
public TrailerInfo GetLookupInfo()
{
return GetItemLookupInfo<TrailerInfo>();
}
}
}