added error handling to image tag generation

This commit is contained in:
Luke Pulverenti 2013-07-05 20:19:44 -04:00
parent 4341bd865d
commit da5eaddd91
5 changed files with 66 additions and 25 deletions

View File

@ -292,7 +292,12 @@ namespace MediaBrowser.Controller.Dto
{ {
var type = image.Key; var type = image.Key;
dto.ImageTags[type] = Kernel.Instance.ImageManager.GetImageCacheTag(item, type, image.Value); var tag = GetImageCacheTag(item, type, image.Value);
if (tag.HasValue)
{
dto.ImageTags[type] = tag.Value;
}
} }
dto.Id = GetClientItemId(item); dto.Id = GetClientItemId(item);
@ -365,7 +370,7 @@ namespace MediaBrowser.Controller.Dto
{ {
dto.ParentLogoItemId = GetClientItemId(parentWithLogo); dto.ParentLogoItemId = GetClientItemId(parentWithLogo);
dto.ParentLogoImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImage(ImageType.Logo)); dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo, parentWithLogo.GetImage(ImageType.Logo));
} }
} }
@ -393,7 +398,7 @@ namespace MediaBrowser.Controller.Dto
{ {
dto.CustomRating = item.CustomRating; dto.CustomRating = item.CustomRating;
} }
if (fields.Contains(ItemFields.Taglines)) if (fields.Contains(ItemFields.Taglines))
{ {
dto.Taglines = item.Taglines; dto.Taglines = item.Taglines;
@ -656,7 +661,7 @@ namespace MediaBrowser.Controller.Dto
if (!string.IsNullOrEmpty(primaryImagePath)) if (!string.IsNullOrEmpty(primaryImagePath))
{ {
baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath); baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
} }
} }
@ -712,7 +717,7 @@ namespace MediaBrowser.Controller.Dto
if (!string.IsNullOrEmpty(primaryImagePath)) if (!string.IsNullOrEmpty(primaryImagePath))
{ {
studioDto.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath); studioDto.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
} }
} }
@ -805,7 +810,7 @@ namespace MediaBrowser.Controller.Dto
if (!string.IsNullOrEmpty(chapterInfo.ImagePath)) if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
{ {
dto.ImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Chapter, chapterInfo.ImagePath); dto.ImageTag = GetImageCacheTag(item, ImageType.Chapter, chapterInfo.ImagePath);
} }
return dto; return dto;
@ -838,7 +843,13 @@ namespace MediaBrowser.Controller.Dto
if (!string.IsNullOrEmpty(imagePath)) if (!string.IsNullOrEmpty(imagePath))
{ {
info.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Primary, imagePath); try
{
info.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Primary, imagePath);
}
catch (IOException)
{
}
} }
return info; return info;
@ -980,12 +991,11 @@ namespace MediaBrowser.Controller.Dto
/// <returns>List{System.String}.</returns> /// <returns>List{System.String}.</returns>
private List<Guid> GetBackdropImageTags(BaseItem item) private List<Guid> GetBackdropImageTags(BaseItem item)
{ {
if (item.BackdropImagePaths == null) return item.BackdropImagePaths
{ .Select(p => GetImageCacheTag(item, ImageType.Backdrop, p))
return new List<Guid>(); .Where(i => i.HasValue)
} .Select(i => i.Value)
.ToList();
return item.BackdropImagePaths.Select(p => Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Backdrop, p)).ToList();
} }
/// <summary> /// <summary>
@ -995,12 +1005,24 @@ namespace MediaBrowser.Controller.Dto
/// <returns>List{Guid}.</returns> /// <returns>List{Guid}.</returns>
private List<Guid> GetScreenshotImageTags(BaseItem item) private List<Guid> GetScreenshotImageTags(BaseItem item)
{ {
if (item.ScreenshotImagePaths == null) return item.ScreenshotImagePaths
{ .Select(p => GetImageCacheTag(item, ImageType.Screenshot, p))
return new List<Guid>(); .Where(i => i.HasValue)
} .Select(i => i.Value)
.ToList();
}
return item.ScreenshotImagePaths.Select(p => Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Screenshot, p)).ToList(); private Guid? GetImageCacheTag(BaseItem item, ImageType type, string path)
{
try
{
return Kernel.Instance.ImageManager.GetImageCacheTag(item, ImageType.Screenshot, path);
}
catch (IOException ex)
{
_logger.ErrorException("Error getting {0} image info for {1}", ex, type, path);
return null;
}
} }
} }
} }

View File

@ -588,7 +588,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the community rating vote count. /// Gets or sets the community rating vote count.
/// </summary> /// </summary>
/// <value>The community rating vote count.</value> /// <value>The community rating vote count.</value>
public int VoteCount { get; set; } public int? VoteCount { get; set; }
/// <summary> /// <summary>
/// Gets or sets the run time ticks. /// Gets or sets the run time ticks.

View File

@ -91,7 +91,7 @@ namespace MediaBrowser.Controller.Entities
public List<LinkedChild> LinkedChildren { get; set; } public List<LinkedChild> LinkedChildren { get; set; }
protected virtual bool SupportsLinkedChildren protected virtual bool SupportsShortcutChildren
{ {
get { return false; } get { return false; }
} }
@ -856,6 +856,7 @@ namespace MediaBrowser.Controller.Entities
{ {
var parent = System.IO.Path.GetDirectoryName(path); var parent = System.IO.Path.GetDirectoryName(path);
// Depending on whether the path is local or unc, it may return either null or '\' at the top
while (!string.IsNullOrEmpty(parent) && !parent.ToCharArray()[0].Equals(System.IO.Path.DirectorySeparatorChar)) while (!string.IsNullOrEmpty(parent) && !parent.ToCharArray()[0].Equals(System.IO.Path.DirectorySeparatorChar))
{ {
if (Directory.Exists(parent)) if (Directory.Exists(parent))
@ -999,15 +1000,32 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetLinkedChildren() public IEnumerable<BaseItem> GetLinkedChildren()
{ {
return LinkedChildren return LinkedChildren
.Select(i => LibraryManager.RootFolder.FindByPath(i.Path)) .Select(GetLinkedChild)
.Where(i => i != null); .Where(i => i != null);
} }
/// <summary>
/// Gets the linked child.
/// </summary>
/// <param name="info">The info.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetLinkedChild(LinkedChild info)
{
var item = LibraryManager.RootFolder.FindByPath(info.Path);
if (item == null)
{
Logger.Warn("Unable to find linked item at {0}", info.Path);
}
return item;
}
public override async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true) public override async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
{ {
var changed = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs).ConfigureAwait(false); var changed = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs).ConfigureAwait(false);
return changed || (SupportsLinkedChildren && LocationType == LocationType.FileSystem && RefreshLinkedChildren()); return changed || (SupportsShortcutChildren && LocationType == LocationType.FileSystem && RefreshLinkedChildren());
} }
/// <summary> /// <summary>
@ -1059,6 +1077,7 @@ namespace MediaBrowser.Controller.Entities
if (!newShortcutLinks.SequenceEqual(currentShortcutLinks)) if (!newShortcutLinks.SequenceEqual(currentShortcutLinks))
{ {
Logger.Info("Shortcut links have changed for {0}", Path);
newShortcutLinks.AddRange(currentManualLinks); newShortcutLinks.AddRange(currentManualLinks);
LinkedChildren = newShortcutLinks; LinkedChildren = newShortcutLinks;
return true; return true;

View File

@ -6,7 +6,7 @@ namespace MediaBrowser.Controller.Entities.Movies
/// </summary> /// </summary>
public class BoxSet : Folder public class BoxSet : Folder
{ {
protected override bool SupportsLinkedChildren protected override bool SupportsShortcutChildren
{ {
get get
{ {

View File

@ -314,7 +314,7 @@ namespace MediaBrowser.Providers.Movies
if (boxset != null) if (boxset != null)
{ {
// See if any movies have a collection id already // See if any movies have a collection id already
return boxset.Children.OfType<Video>() return boxset.Children.Concat(boxset.GetLinkedChildren()).OfType<Video>()
.Select(i => i.GetProviderId(MetadataProviders.TmdbCollection)) .Select(i => i.GetProviderId(MetadataProviders.TmdbCollection))
.FirstOrDefault(i => i != null); .FirstOrDefault(i => i != null);
} }
@ -744,7 +744,7 @@ namespace MediaBrowser.Providers.Movies
var boxset = movie as BoxSet; var boxset = movie as BoxSet;
Logger.Info("MovieDbProvider - Using rating of first child of boxset..."); Logger.Info("MovieDbProvider - Using rating of first child of boxset...");
var firstChild = boxset.Children.FirstOrDefault(); var firstChild = boxset.Children.Concat(boxset.GetLinkedChildren()).FirstOrDefault();
boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null; boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null;
} }