remove need to pass in image index when adding backdrops
This commit is contained in:
parent
2fc662c9e9
commit
01f1ed05b9
|
@ -471,6 +471,76 @@ namespace MediaBrowser.Api.DefaultTheme
|
|||
}).Where(i => i != null).ToList();
|
||||
}
|
||||
|
||||
private void SetFavoriteGenres(MoviesView view, IEnumerable<BaseItem> 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<BaseItem> 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<Movie>()
|
||||
.ToList();
|
||||
|
||||
SetFavoriteGenres(view, movies, user);
|
||||
SetFavoriteStudios(view, movies, user);
|
||||
|
||||
var trailers = items.OfType<Trailer>()
|
||||
.ToList();
|
||||
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace MediaBrowser.Api.DefaultTheme
|
|||
|
||||
public List<BaseItemDto> LatestTrailers { get; set; }
|
||||
public List<BaseItemDto> LatestMovies { get; set; }
|
||||
|
||||
public List<ItemByNameInfo> FavoriteGenres { get; set; }
|
||||
public List<ItemByNameInfo> FavoriteStudios { get; set; }
|
||||
}
|
||||
|
||||
public class TvView : BaseView
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -282,14 +282,7 @@ namespace MediaBrowser.Api.Images
|
|||
/// <returns>Task.</returns>
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user