aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-08 16:58:52 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-08 16:58:52 -0400
commitfbd052abfc2724fcb151582746c9783d7ab8a97a (patch)
tree4b3e126d72aa53e6aa4e74c74380bdcb80bc412c /MediaBrowser.Controller
parenta0dfbdfd70fe85fca64b341b6fe30708e9a9ebe9 (diff)
removed local trailers and special features from memory
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/Dto/DtoBuilder.cs4
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs162
-rw-r--r--MediaBrowser.Controller/Entities/Movies/Movie.cs70
-rw-r--r--MediaBrowser.Controller/Persistence/IItemRepository.cs9
-rw-r--r--MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs16
-rw-r--r--MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs1
-rw-r--r--MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs1
-rw-r--r--MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs1
8 files changed, 106 insertions, 158 deletions
diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs
index e16fb6d94..d84227059 100644
--- a/MediaBrowser.Controller/Dto/DtoBuilder.cs
+++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs
@@ -331,7 +331,7 @@ namespace MediaBrowser.Controller.Dto
dto.CriticRatingSummary = item.CriticRatingSummary;
}
- var localTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count;
+ var localTrailerCount = item.LocalTrailerIds.Count;
if (localTrailerCount > 0)
{
@@ -492,7 +492,7 @@ namespace MediaBrowser.Controller.Dto
if (movie != null)
{
- var specialFeatureCount = movie.SpecialFeatures == null ? 0 : movie.SpecialFeatures.Count;
+ var specialFeatureCount = movie.SpecialFeatureIds.Count;
if (specialFeatureCount > 0)
{
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index d7fc1cc8e..e31939d59 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -38,6 +38,9 @@ namespace MediaBrowser.Controller.Entities
Images = new Dictionary<ImageType, string>();
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Tags = new List<string>();
+ ThemeSongIds = new List<Guid>();
+ ThemeVideoIds = new List<Guid>();
+ LocalTrailerIds = new List<Guid>();
}
/// <summary>
@@ -572,7 +575,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The tags.</value>
public List<string> Tags { get; set; }
-
+
/// <summary>
/// Override this if you need to combine/collapse person information
/// </summary>
@@ -612,7 +615,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The revenue.</value>
public double? Revenue { get; set; }
-
+
/// <summary>
/// Gets or sets the production locations.
/// </summary>
@@ -630,7 +633,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The critic rating summary.</value>
public string CriticRatingSummary { get; set; }
-
+
/// <summary>
/// Gets or sets the community rating.
/// </summary>
@@ -672,84 +675,9 @@ namespace MediaBrowser.Controller.Entities
/// <value>The critic reviews.</value>
public List<ItemReview> CriticReviews { get; set; }
- /// <summary>
- /// The _local trailers
- /// </summary>
- private List<Trailer> _localTrailers;
- /// <summary>
- /// The _local trailers initialized
- /// </summary>
- private bool _localTrailersInitialized;
- /// <summary>
- /// The _local trailers sync lock
- /// </summary>
- private object _localTrailersSyncLock = new object();
- /// <summary>
- /// Gets the local trailers.
- /// </summary>
- /// <value>The local trailers.</value>
- [IgnoreDataMember]
- public List<Trailer> LocalTrailers
- {
- get
- {
- LazyInitializer.EnsureInitialized(ref _localTrailers, ref _localTrailersInitialized, ref _localTrailersSyncLock, LoadLocalTrailers);
- return _localTrailers;
- }
- private set
- {
- _localTrailers = value;
-
- if (value == null)
- {
- _localTrailersInitialized = false;
- }
- }
- }
-
- private List<Audio.Audio> _themeSongs;
- private bool _themeSongsInitialized;
- private object _themeSongsSyncLock = new object();
- [IgnoreDataMember]
- public List<Audio.Audio> ThemeSongs
- {
- get
- {
- LazyInitializer.EnsureInitialized(ref _themeSongs, ref _themeSongsInitialized, ref _themeSongsSyncLock, LoadThemeSongs);
- return _themeSongs;
- }
- private set
- {
- _themeSongs = value;
-
- if (value == null)
- {
- _themeSongsInitialized = false;
- }
- }
- }
-
- private List<Video> _themeVideos;
- private bool _themeVideosInitialized;
- private object _themeVideosSyncLock = new object();
- [IgnoreDataMember]
- public List<Video> ThemeVideos
- {
- get
- {
- LazyInitializer.EnsureInitialized(ref _themeVideos, ref _themeVideosInitialized, ref _themeVideosSyncLock, LoadThemeVideos);
- return _themeVideos;
- }
- private set
- {
- _themeVideos = value;
-
- if (value == null)
- {
- _themeVideosInitialized = false;
- }
- }
- }
+ public List<Guid> ThemeSongIds { get; set; }
+ public List<Guid> ThemeVideoIds { get; set; }
+ public List<Guid> LocalTrailerIds { get; set; }
/// <summary>
/// Loads local trailers from the file system
@@ -956,36 +884,25 @@ namespace MediaBrowser.Controller.Entities
ResolveArgs = null;
}
- // Lazy load these again
- LocalTrailers = null;
- ThemeSongs = null;
- ThemeVideos = null;
-
// Refresh for the item
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
cancellationToken.ThrowIfCancellationRequested();
- // Refresh metadata for local trailers
- var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+ var themeSongsChanged = await RefreshThemeSongs(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
- var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+ var themeVideosChanged = await RefreshThemeVideos(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
- var videoBackdropTasks = ThemeVideos.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
-
- cancellationToken.ThrowIfCancellationRequested();
+ var localTrailersChanged = await RefreshLocalTrailers(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
- // Await the trailer tasks
- await Task.WhenAll(trailerTasks).ConfigureAwait(false);
- await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
- await Task.WhenAll(videoBackdropTasks).ConfigureAwait(false);
+ cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
// Get the result from the item task
var changed = await itemRefreshTask.ConfigureAwait(false);
- if (changed || forceSave)
+ if (changed || forceSave || themeSongsChanged || themeVideosChanged || localTrailersChanged)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -995,6 +912,57 @@ namespace MediaBrowser.Controller.Entities
return changed;
}
+ private async Task<bool> RefreshLocalTrailers(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
+ {
+ var newItems = LoadLocalTrailers().ToList();
+ var newItemIds = newItems.Select(i => i.Id).ToList();
+
+ var itemsChanged = !LocalTrailerIds.SequenceEqual(newItemIds);
+
+ var tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+
+ var results = await Task.WhenAll(tasks).ConfigureAwait(false);
+
+ LocalTrailerIds = newItemIds;
+
+ return itemsChanged || results.Contains(true);
+ }
+
+ private async Task<bool> RefreshThemeVideos(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
+ {
+ var newThemeVideos = LoadThemeVideos().ToList();
+ var newThemeVideoIds = newThemeVideos.Select(i => i.Id).ToList();
+
+ var themeVideosChanged = !ThemeVideoIds.SequenceEqual(newThemeVideoIds);
+
+ var tasks = newThemeVideos.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+
+ var results = await Task.WhenAll(tasks).ConfigureAwait(false);
+
+ ThemeVideoIds = newThemeVideoIds;
+
+ return themeVideosChanged || results.Contains(true);
+ }
+
+ /// <summary>
+ /// Refreshes the theme songs.
+ /// </summary>
+ private async Task<bool> RefreshThemeSongs(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
+ {
+ var newThemeSongs = LoadThemeSongs().ToList();
+ var newThemeSongIds = newThemeSongs.Select(i => i.Id).ToList();
+
+ var themeSongsChanged = !ThemeSongIds.SequenceEqual(newThemeSongIds);
+
+ var tasks = newThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+
+ var results = await Task.WhenAll(tasks).ConfigureAwait(false);
+
+ ThemeSongIds = newThemeSongIds;
+
+ return themeSongsChanged || results.Contains(true);
+ }
+
/// <summary>
/// Clear out all metadata properties. Extend for sub-classes.
/// </summary>
diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs
index 593255989..5e068c261 100644
--- a/MediaBrowser.Controller/Entities/Movies/Movie.cs
+++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.IO;
+using System;
+using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.IO;
@@ -14,6 +15,13 @@ namespace MediaBrowser.Controller.Entities.Movies
/// </summary>
public class Movie : Video
{
+ public List<Guid> SpecialFeatureIds { get; set; }
+
+ public Movie()
+ {
+ SpecialFeatureIds = new List<Guid>();
+ }
+
/// <summary>
/// Should be overridden to return the proper folder where metadata lives
/// </summary>
@@ -37,41 +45,6 @@ namespace MediaBrowser.Controller.Entities.Movies
}
/// <summary>
- /// The _special features
- /// </summary>
- private List<Video> _specialFeatures;
- /// <summary>
- /// The _special features initialized
- /// </summary>
- private bool _specialFeaturesInitialized;
- /// <summary>
- /// The _special features sync lock
- /// </summary>
- private object _specialFeaturesSyncLock = new object();
- /// <summary>
- /// Gets the special features.
- /// </summary>
- /// <value>The special features.</value>
- [IgnoreDataMember]
- public List<Video> SpecialFeatures
- {
- get
- {
- LazyInitializer.EnsureInitialized(ref _specialFeatures, ref _specialFeaturesInitialized, ref _specialFeaturesSyncLock, () => LoadSpecialFeatures().ToList());
- return _specialFeatures;
- }
- private set
- {
- _specialFeatures = value;
-
- if (value == null)
- {
- _specialFeaturesInitialized = false;
- }
- }
- }
-
- /// <summary>
/// Needed because the resolver stops at the movie folder and we find the video inside.
/// </summary>
/// <value><c>true</c> if [use parent path to create resolve args]; otherwise, <c>false</c>.</value>
@@ -94,21 +67,30 @@ namespace MediaBrowser.Controller.Entities.Movies
/// <returns>Task{System.Boolean}.</returns>
public override async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
{
- // Lazy load these again
- SpecialFeatures = null;
-
// Kick off a task to refresh the main item
var result = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs).ConfigureAwait(false);
- var tasks = SpecialFeatures.Select(item => item.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+ var specialFeaturesChanged = await RefreshSpecialFeatures(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
- await Task.WhenAll(tasks).ConfigureAwait(false);
+ return specialFeaturesChanged || result;
+ }
+
+ private async Task<bool> RefreshSpecialFeatures(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
+ {
+ var newItems = LoadSpecialFeatures().ToList();
+ var newItemIds = newItems.Select(i => i.Id).ToList();
- cancellationToken.ThrowIfCancellationRequested();
+ var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
- return result;
- }
+ var tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
+ var results = await Task.WhenAll(tasks).ConfigureAwait(false);
+
+ SpecialFeatureIds = newItemIds;
+
+ return itemsChanged || results.Contains(true);
+ }
+
/// <summary>
/// Loads the special features.
/// </summary>
diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs
index c7e51e38c..c91aeb9a5 100644
--- a/MediaBrowser.Controller/Persistence/IItemRepository.cs
+++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs
@@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.Persistence
/// </summary>
/// <param name="id">The id.</param>
/// <returns>BaseItem.</returns>
- BaseItem RetrieveItem(Guid id);
+ BaseItem GetItem(Guid id);
/// <summary>
/// Gets children of a given Folder
@@ -34,6 +34,13 @@ namespace MediaBrowser.Controller.Persistence
IEnumerable<BaseItem> RetrieveChildren(Folder parent);
/// <summary>
+ /// Retrieves the items.
+ /// </summary>
+ /// <param name="ids">The ids.</param>
+ /// <returns>IEnumerable{BaseItem}.</returns>
+ IEnumerable<BaseItem> GetItems(IEnumerable<Guid> ids);
+
+ /// <summary>
/// Saves children of a given Folder
/// </summary>
/// <param name="parentId">The parent id.</param>
diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
index 0e56b8c08..9fdbd8b09 100644
--- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
+++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
@@ -57,15 +57,9 @@ namespace MediaBrowser.Controller.Providers.Music
if (result != null)
{
- if (!string.IsNullOrEmpty(result.Item1))
+ if (!string.IsNullOrEmpty(result))
{
- return result.Item1;
- }
-
- // If there were no artists returned at all, then don't bother with musicbrainz
- if (!result.Item2)
- {
- return null;
+ return result;
}
}
@@ -94,7 +88,7 @@ namespace MediaBrowser.Controller.Providers.Music
return artist != null ? artist.GetProviderId(MetadataProviders.Musicbrainz) : null;
}
- private async Task<Tuple<string,bool>> FindIdFromLastFm(BaseItem item, CancellationToken cancellationToken)
+ private async Task<string> FindIdFromLastFm(BaseItem item, CancellationToken cancellationToken)
{
//Execute the Artist search against our name and assume first one is the one we want
var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
@@ -125,10 +119,10 @@ namespace MediaBrowser.Controller.Providers.Music
var artist = searchResult.results.artistmatches.artist.FirstOrDefault(i => i.name != null && string.Compare(i.name, item.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0) ??
searchResult.results.artistmatches.artist.First();
- return new Tuple<string, bool>(artist.mbid, true);
+ return artist.mbid;
}
- return new Tuple<string,bool>(null, false);
+ return null;
}
private async Task<string> FindIdFromMusicBrainz(BaseItem item, CancellationToken cancellationToken)
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
index efa4b1f0c..487ea98cb 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
@@ -146,7 +146,6 @@ namespace MediaBrowser.Controller.Providers.TV
string name = episode.Name;
string location = episode.Path;
- Logger.Debug("TvDbProvider: Fetching episode data for: " + name);
string epNum = TVUtils.EpisodeNumberFromFile(location, episode.Season != null);
if (epNum == null)
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
index e3a5d459d..211b6fec8 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
@@ -130,7 +130,6 @@ namespace MediaBrowser.Controller.Providers.TV
{
string name = season.Name;
- Logger.Debug("TvDbProvider: Fetching season data: " + name);
var seasonNumber = TVUtils.GetSeasonNumberFromPath(season.Path) ?? -1;
season.IndexNumber = seasonNumber;
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs
index 88a2a6dae..9dd5aa418 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs
@@ -193,7 +193,6 @@ namespace MediaBrowser.Controller.Providers.TV
var success = false;
var name = series.Name;
- Logger.Debug("TvDbProvider: Fetching series data: " + name);
if (!string.IsNullOrEmpty(seriesId))
{