diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index c0992a749..bb23f7f7e 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -471,6 +471,76 @@ namespace MediaBrowser.Api.DefaultTheme }).Where(i => i != null).ToList(); } + private void SetFavoriteGenres(MoviesView view, IEnumerable inputItems, User user) + { + var all = inputItems.SelectMany(i => i.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase); + + view.FavoriteGenres = all.Select(i => + { + try + { + var itemByName = _libraryManager.GetGenre(i); + + var counts = itemByName.GetItemByNameCounts(user); + + var count = counts == null ? 0 : counts.MovieCount; + + if (count > 0 && _userDataManager.GetUserData(user.Id, itemByName.GetUserDataKey()).IsFavorite) + { + return new ItemByNameInfo + { + Name = itemByName.Name, + ItemCount = count + }; + } + } + catch (Exception ex) + { + _logger.ErrorException("Error getting genre {0}", ex, i); + + } + + return null; + + }).Where(i => i != null).ToList(); + } + + private void SetFavoriteStudios(MoviesView view, IEnumerable inputItems, User user) + { + var all = inputItems.SelectMany(i => i.Studios) + .Distinct(StringComparer.OrdinalIgnoreCase); + + view.FavoriteStudios = all.Select(i => + { + try + { + var itemByName = _libraryManager.GetStudio(i); + + var counts = itemByName.GetItemByNameCounts(user); + + var count = counts == null ? 0 : counts.MovieCount; + + if (count > 0 && _userDataManager.GetUserData(user.Id, itemByName.GetUserDataKey()).IsFavorite) + { + return new ItemByNameInfo + { + Name = itemByName.Name, + ItemCount = count + }; + } + } + catch (Exception ex) + { + _logger.ErrorException("Error getting studio {0}", ex, i); + + } + + return null; + + }).Where(i => i != null).ToList(); + } + public object Get(GetMovieView request) { var user = _userManager.GetUserById(request.UserId); @@ -487,6 +557,9 @@ namespace MediaBrowser.Api.DefaultTheme var movies = items.OfType() .ToList(); + SetFavoriteGenres(view, movies, user); + SetFavoriteStudios(view, movies, user); + var trailers = items.OfType() .ToList(); diff --git a/MediaBrowser.Api/DefaultTheme/Models.cs b/MediaBrowser.Api/DefaultTheme/Models.cs index 6dbd6b562..bdff82de2 100644 --- a/MediaBrowser.Api/DefaultTheme/Models.cs +++ b/MediaBrowser.Api/DefaultTheme/Models.cs @@ -34,6 +34,9 @@ namespace MediaBrowser.Api.DefaultTheme public List LatestTrailers { get; set; } public List LatestMovies { get; set; } + + public List FavoriteGenres { get; set; } + public List FavoriteStudios { get; set; } } public class TvView : BaseView diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 61259a4c2..0e5f420b5 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -861,21 +861,10 @@ namespace MediaBrowser.Api.Images Position = 0 }; - var imageIndex = 0; - - if (imageType == ImageType.Screenshot) - { - imageIndex = entity.ScreenshotImagePaths.Count; - } - else if (imageType == ImageType.Backdrop) - { - imageIndex = entity.BackdropImagePaths.Count; - } - // Handle image/png; charset=utf-8 mimeType = mimeType.Split(';').FirstOrDefault(); - await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, imageIndex, null, CancellationToken.None).ConfigureAwait(false); + await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, null, null, CancellationToken.None).ConfigureAwait(false); await entity.RefreshMetadata(CancellationToken.None, forceRefresh: true, forceSave: true, allowSlowProviders: false).ConfigureAwait(false); } diff --git a/MediaBrowser.Api/Images/RemoteImageService.cs b/MediaBrowser.Api/Images/RemoteImageService.cs index 0cf51abac..f92d9d581 100644 --- a/MediaBrowser.Api/Images/RemoteImageService.cs +++ b/MediaBrowser.Api/Images/RemoteImageService.cs @@ -282,14 +282,7 @@ namespace MediaBrowser.Api.Images /// Task. private async Task DownloadRemoteImage(BaseItem item, BaseDownloadRemoteImage request) { - int? index = null; - - if (request.Type == ImageType.Backdrop) - { - index = item.BackdropImagePaths.Count; - } - - await _providerManager.SaveImage(item, request.ImageUrl, null, request.Type, index, CancellationToken.None).ConfigureAwait(false); + await _providerManager.SaveImage(item, request.ImageUrl, null, request.Type, null, CancellationToken.None).ConfigureAwait(false); await item.RefreshMetadata(CancellationToken.None, forceSave: true, allowSlowProviders: false) .ConfigureAwait(false); diff --git a/MediaBrowser.Providers/Movies/FanArtMovieProvider.cs b/MediaBrowser.Providers/Movies/FanArtMovieProvider.cs index 24f17556b..39908c3ee 100644 --- a/MediaBrowser.Providers/Movies/FanArtMovieProvider.cs +++ b/MediaBrowser.Providers/Movies/FanArtMovieProvider.cs @@ -327,15 +327,11 @@ namespace MediaBrowser.Providers.Movies if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) { - var numBackdrops = item.BackdropImagePaths.Count; - foreach (var image in images.Where(i => i.Type == ImageType.Backdrop)) { - await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken) + await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, null, cancellationToken) .ConfigureAwait(false); - numBackdrops++; - if (item.BackdropImagePaths.Count >= backdropLimit) break; } } diff --git a/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs b/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs index ab6dbf6d4..d2a12ac21 100644 --- a/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs @@ -231,7 +231,7 @@ namespace MediaBrowser.Providers.Movies }).ConfigureAwait(false); - await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Backdrop, item.BackdropImagePaths.Count, url, cancellationToken) + await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Backdrop, null, url, cancellationToken) .ConfigureAwait(false); } diff --git a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs index f3ea77584..6df21b61d 100644 --- a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs +++ b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs @@ -320,15 +320,11 @@ namespace MediaBrowser.Providers.Music if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) { - var numBackdrops = item.BackdropImagePaths.Count; - foreach (var image in images.Where(i => i.Type == ImageType.Backdrop)) { - await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken) + await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, null, cancellationToken) .ConfigureAwait(false); - numBackdrops++; - if (item.BackdropImagePaths.Count >= backdropLimit) break; } } diff --git a/MediaBrowser.Providers/TV/FanArtTVProvider.cs b/MediaBrowser.Providers/TV/FanArtTVProvider.cs index 31f8f9cb4..1f20140c5 100644 --- a/MediaBrowser.Providers/TV/FanArtTVProvider.cs +++ b/MediaBrowser.Providers/TV/FanArtTVProvider.cs @@ -260,15 +260,11 @@ namespace MediaBrowser.Providers.TV if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) { - var numBackdrops = item.BackdropImagePaths.Count; - foreach (var image in images.Where(i => i.Type == ImageType.Backdrop)) { - await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken) + await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, null, cancellationToken) .ConfigureAwait(false); - numBackdrops++; - if (item.BackdropImagePaths.Count >= backdropLimit) break; } } diff --git a/MediaBrowser.Providers/TV/TvdbSeasonProvider.cs b/MediaBrowser.Providers/TV/TvdbSeasonProvider.cs index 77a432add..05fee7861 100644 --- a/MediaBrowser.Providers/TV/TvdbSeasonProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeasonProvider.cs @@ -181,8 +181,6 @@ namespace MediaBrowser.Providers.TV if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) { - var bdNo = item.BackdropImagePaths.Count; - foreach (var backdrop in images.Where(i => i.Type == ImageType.Backdrop)) { var url = backdrop.Url; @@ -192,9 +190,7 @@ namespace MediaBrowser.Providers.TV continue; } - await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, bdNo, cancellationToken).ConfigureAwait(false); - - bdNo++; + await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, null, cancellationToken).ConfigureAwait(false); if (item.BackdropImagePaths.Count >= backdropLimit) break; } diff --git a/MediaBrowser.Providers/TV/TvdbSeriesImageProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesImageProvider.cs index 42118c063..b56b50bec 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesImageProvider.cs @@ -191,8 +191,6 @@ namespace MediaBrowser.Providers.TV if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) { - var bdNo = item.BackdropImagePaths.Count; - foreach (var backdrop in images.Where(i => i.Type == ImageType.Backdrop && (!i.Width.HasValue || i.Width.Value >= ConfigurationManager.Configuration.MinSeriesBackdropDownloadWidth))) @@ -204,9 +202,7 @@ namespace MediaBrowser.Providers.TV continue; } - await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, bdNo, cancellationToken).ConfigureAwait(false); - - bdNo++; + await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, null, cancellationToken).ConfigureAwait(false); if (item.BackdropImagePaths.Count >= backdropLimit) break; } diff --git a/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs b/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs index dfbf0736b..0ed46e761 100644 --- a/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs +++ b/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs @@ -70,6 +70,15 @@ namespace MediaBrowser.Server.Implementations.Providers throw new ArgumentNullException("mimeType"); } + if (type == ImageType.Backdrop && imageIndex == null) + { + imageIndex = item.BackdropImagePaths.Count; + } + else if (type == ImageType.Screenshot && imageIndex == null) + { + imageIndex = item.ScreenshotImagePaths.Count; + } + var saveLocally = _config.Configuration.SaveLocalMeta && item.Parent != null && !(item is Audio); if (item is IItemByName || item is User)