mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 09:59:06 -07:00
grab image sizes at discovery time
This commit is contained in:
parent
47915df62c
commit
69b83082c8
@ -312,36 +312,6 @@ namespace MediaBrowser.Api.Images
|
||||
}
|
||||
}
|
||||
|
||||
var video = item as Video;
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
var index = 0;
|
||||
|
||||
foreach (var chapter in _itemRepo.GetChapters(video.Id))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(chapter.ImagePath))
|
||||
{
|
||||
var image = chapter.ImagePath;
|
||||
|
||||
var info = GetImageInfo(item, new ItemImageInfo
|
||||
{
|
||||
Path = image,
|
||||
Type = ImageType.Chapter,
|
||||
DateModified = _fileSystem.GetLastWriteTimeUtc(image)
|
||||
|
||||
}, index);
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
list.Add(info);
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -351,8 +321,6 @@ namespace MediaBrowser.Api.Images
|
||||
{
|
||||
var fileInfo = new FileInfo(info.Path);
|
||||
|
||||
var size = _imageProcessor.GetImageSize(info.Path);
|
||||
|
||||
return new ImageInfo
|
||||
{
|
||||
Path = info.Path,
|
||||
@ -360,8 +328,8 @@ namespace MediaBrowser.Api.Images
|
||||
ImageType = info.Type,
|
||||
ImageTag = _imageProcessor.GetImageCacheTag(item, info),
|
||||
Size = fileInfo.Length,
|
||||
Width = Convert.ToInt32(size.Width),
|
||||
Height = Convert.ToInt32(size.Height)
|
||||
Width = info.Width ?? 0,
|
||||
Height = info.Height ?? 0
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -47,10 +47,9 @@ namespace MediaBrowser.Controller.Dto
|
||||
/// <summary>
|
||||
/// Gets the chapter information dto.
|
||||
/// </summary>
|
||||
/// <param name="chapterInfo">The chapter information.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>ChapterInfoDto.</returns>
|
||||
ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item);
|
||||
List<ChapterInfoDto> GetChapterInfoDtos(BaseItem item);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user item data dto.
|
||||
|
@ -3,6 +3,7 @@ using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Collections;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.Localization;
|
||||
@ -253,6 +254,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
public static ILiveTvManager LiveTvManager { get; set; }
|
||||
public static IChannelManager ChannelManager { get; set; }
|
||||
public static ICollectionManager CollectionManager { get; set; }
|
||||
public static IImageProcessor ImageProcessor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
@ -1455,17 +1457,16 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (image == null)
|
||||
{
|
||||
ImageInfos.Add(new ItemImageInfo
|
||||
{
|
||||
Path = file.FullName,
|
||||
Type = type,
|
||||
DateModified = FileSystem.GetLastWriteTimeUtc(file)
|
||||
});
|
||||
ImageInfos.Add(GetImageInfo(file, type));
|
||||
}
|
||||
else
|
||||
{
|
||||
var imageInfo = GetImageInfo(file, type);
|
||||
|
||||
image.Path = file.FullName;
|
||||
image.DateModified = FileSystem.GetLastWriteTimeUtc(file);
|
||||
image.DateModified = imageInfo.DateModified;
|
||||
image.Width = imageInfo.Width;
|
||||
image.Height = imageInfo.Height;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1574,7 +1575,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
Path = path,
|
||||
DateModified = FileSystem.GetLastWriteTimeUtc(path),
|
||||
Type = imageType
|
||||
Type = imageType,
|
||||
Width = chapter.ImageWidth,
|
||||
Height = chapter.ImageHeight
|
||||
};
|
||||
}
|
||||
|
||||
@ -1631,16 +1634,35 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
ImageInfos.AddRange(newImageList.Select(i => new ItemImageInfo
|
||||
{
|
||||
Path = i.FullName,
|
||||
Type = imageType,
|
||||
DateModified = FileSystem.GetLastWriteTimeUtc(i)
|
||||
}));
|
||||
ImageInfos.AddRange(newImageList.Select(i => GetImageInfo(i, imageType)));
|
||||
|
||||
return newImageList.Count > 0;
|
||||
}
|
||||
|
||||
private ItemImageInfo GetImageInfo(FileSystemInfo file, ImageType type)
|
||||
{
|
||||
var info = new ItemImageInfo
|
||||
{
|
||||
Path = file.FullName,
|
||||
Type = type,
|
||||
DateModified = FileSystem.GetLastWriteTimeUtc(file)
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var size = ImageProcessor.GetImageSize(info.Path);
|
||||
|
||||
info.Width = Convert.ToInt32(size.Width);
|
||||
info.Height = Convert.ToInt32(size.Height);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system path to delete when the item is to be deleted
|
||||
/// </summary>
|
||||
|
@ -10,5 +10,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
public ImageType Type { get; set; }
|
||||
|
||||
public DateTime DateModified { get; set; }
|
||||
|
||||
public int? Width { get; set; }
|
||||
|
||||
public int? Height { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -869,9 +869,11 @@ namespace MediaBrowser.Dlna.Didl
|
||||
|
||||
}
|
||||
|
||||
int? width = null;
|
||||
int? height = null;
|
||||
int? width = imageInfo.Width;
|
||||
int? height = imageInfo.Height;
|
||||
|
||||
if (!height.HasValue && !width.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var size = _imageProcessor.GetImageSize(imageInfo.Path, imageInfo.DateModified);
|
||||
@ -883,6 +885,7 @@ namespace MediaBrowser.Dlna.Didl
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new ImageDownloadInfo
|
||||
{
|
||||
|
@ -23,5 +23,17 @@ namespace MediaBrowser.Model.Entities
|
||||
/// </summary>
|
||||
/// <value>The image path.</value>
|
||||
public string ImagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height of the image.
|
||||
/// </summary>
|
||||
/// <value>The height of the image.</value>
|
||||
public int? ImageHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the width of the image.
|
||||
/// </summary>
|
||||
/// <value>The width of the image.</value>
|
||||
public int? ImageWidth { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@ -18,12 +17,10 @@ namespace MediaBrowser.Providers.Photos
|
||||
public class PhotoProvider : ICustomMetadataProvider<Photo>, IHasItemChangeMonitor
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImageProcessor _imageProcessor;
|
||||
|
||||
public PhotoProvider(ILogger logger, IImageProcessor imageProcessor)
|
||||
public PhotoProvider(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_imageProcessor = imageProcessor;
|
||||
}
|
||||
|
||||
public Task<ItemUpdateType> FetchAsync(Photo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
@ -142,9 +139,10 @@ namespace MediaBrowser.Providers.Photos
|
||||
_logger.ErrorException("Image Provider - Error reading image tag for {0}", e, item.Path);
|
||||
}
|
||||
|
||||
var size = _imageProcessor.GetImageSize(item.Path);
|
||||
item.Height = Convert.ToInt32(size.Height);
|
||||
item.Width = Convert.ToInt32(size.Width);
|
||||
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
|
||||
|
||||
item.Height = imageInfo.Height;
|
||||
item.Width = imageInfo.Width;
|
||||
|
||||
const ItemUpdateType result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport;
|
||||
return Task.FromResult(result);
|
||||
|
@ -93,10 +93,10 @@ namespace MediaBrowser.Providers.TV
|
||||
|
||||
var hasBadData = HasInvalidContent(group);
|
||||
|
||||
var anySeasonsRemoved = await RemoveObsoleteOrMissingSeasons(group, episodeLookup, hasBadData)
|
||||
var anySeasonsRemoved = await RemoveObsoleteOrMissingSeasons(group, episodeLookup, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var anyEpisodesRemoved = await RemoveObsoleteOrMissingEpisodes(group, episodeLookup, hasBadData)
|
||||
var anyEpisodesRemoved = await RemoveObsoleteOrMissingEpisodes(group, episodeLookup, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var hasNewEpisodes = false;
|
||||
@ -204,12 +204,6 @@ namespace MediaBrowser.Providers.TV
|
||||
IEnumerable<Tuple<int, int>> episodeLookup,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Be conservative here to avoid creating missing episodes for ones they already have
|
||||
if (!seriesHasBadData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var existingEpisodes = (from s in series
|
||||
let seasonOffset = TvdbSeriesProvider.GetSeriesOffset(s.ProviderIds) ?? ((s.AnimeSeriesIndex ?? 1) - 1)
|
||||
from c in s.RecursiveChildren.OfType<Episode>()
|
||||
|
@ -659,7 +659,7 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
/// <param name="chapterInfo">The chapter info.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>ChapterInfoDto.</returns>
|
||||
public ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item)
|
||||
private ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item)
|
||||
{
|
||||
var dto = new ChapterInfoDto
|
||||
{
|
||||
@ -680,6 +680,13 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
return dto;
|
||||
}
|
||||
|
||||
public List<ChapterInfoDto> GetChapterInfoDtos(BaseItem item)
|
||||
{
|
||||
return _itemRepo.GetChapters(item.Id)
|
||||
.Select(c => GetChapterInfoDto(c, item))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets simple property values on a DTOBaseItem
|
||||
/// </summary>
|
||||
@ -1055,20 +1062,7 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
|
||||
if (fields.Contains(ItemFields.Chapters))
|
||||
{
|
||||
List<ChapterInfoDto> chapters;
|
||||
|
||||
if (dto.MediaSources != null && dto.MediaSources.Count > 0)
|
||||
{
|
||||
chapters = _itemRepo.GetChapters(item.Id).Select(c => GetChapterInfoDto(c, item)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
chapters = _itemRepo.GetChapters(video.Id)
|
||||
.Select(c => GetChapterInfoDto(c, item))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
dto.Chapters = chapters;
|
||||
dto.Chapters = GetChapterInfoDtos(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1435,8 +1429,13 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
// See if we can avoid a file system lookup by looking for the file in ResolveArgs
|
||||
var dateModified = imageInfo.DateModified;
|
||||
|
||||
double? width = imageInfo.Width;
|
||||
double? height = imageInfo.Height;
|
||||
|
||||
ImageSize size;
|
||||
|
||||
if (!width.HasValue || !height.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
size = _imageProcessor.GetImageSize(path, dateModified);
|
||||
@ -1451,6 +1450,15 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = new ImageSize
|
||||
{
|
||||
Height = height.Value,
|
||||
Width = width.Value
|
||||
};
|
||||
}
|
||||
|
||||
dto.OriginalPrimaryImageAspectRatio = size.Width / size.Height;
|
||||
|
||||
|
@ -1224,6 +1224,6 @@
|
||||
"MessageNoDevicesSupportCameraUpload": "You currently don't have any devices that support camera upload.",
|
||||
"LabelCameraUploadPath": "Camera upload path:",
|
||||
"LabelCameraUploadPathHelp": "Select a custom upload path, if desired. If unspecified a default folder will be used.",
|
||||
"LabelCreateCameraUploadSubfolder": "Create a sub-folder for each device",
|
||||
"LabelCreateCameraUploadSubfolderHelp": "Specific folders can be assigned to devices by clicking on the device on the Devices page."
|
||||
"LabelCreateCameraUploadSubfolder": "Create a subfolder for each device",
|
||||
"LabelCreateCameraUploadSubfolderHelp": "Specific folders can be assigned to a device by clicking on it from the Devices page."
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -1594,7 +1593,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
{
|
||||
info.ChapterImagesItemId = chapterOwner.Id.ToString("N");
|
||||
|
||||
info.Chapters = _itemRepo.GetChapters(chapterOwner.Id).Select(i => _dtoService.GetChapterInfoDto(i, chapterOwner)).ToList();
|
||||
info.Chapters = _dtoService.GetChapterInfoDtos(chapterOwner).ToList();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(mediaSourceId))
|
||||
|
Loading…
Reference in New Issue
Block a user