From efbcac6ff12164a70ba8fc6f2afe232022558b47 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 May 2013 14:04:33 -0400 Subject: [PATCH] support plex/xbmc conventions for primary images and backdrops --- .../ImageFromMediaLocationProvider.cs | 70 +++++++++++++------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs index 6e14682ddc..d9c97ddb10 100644 --- a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs @@ -146,7 +146,8 @@ namespace MediaBrowser.Controller.Providers /// FileSystemInfo. protected virtual FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension) { - return item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".png")) ?? item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".jpg")); + return item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".png")) + ?? item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".jpg")); } /// @@ -155,11 +156,13 @@ namespace MediaBrowser.Controller.Providers /// The item. private void PopulateBaseItemImages(BaseItem item) { - var backdropFiles = new List(); var screenshotFiles = new List(); // Primary Image - var image = GetImage(item, "folder"); + var image = GetImage(item, "folder") ?? + GetImage(item, "poster") ?? + GetImage(item, "cover") ?? + GetImage(item, "default"); if (image != null) { @@ -223,22 +226,25 @@ namespace MediaBrowser.Controller.Providers } // Backdrop Image - image = GetImage(item, "backdrop"); + PopulateBackdrops(item); + + // Screenshot Image + image = GetImage(item, "screenshot"); if (image != null) { - backdropFiles.Add(image.FullName); + screenshotFiles.Add(image.FullName); } var unfound = 0; for (var i = 1; i <= 20; i++) { - // Backdrop Image - image = GetImage(item, "backdrop" + i); + // Screenshot Image + image = GetImage(item, "screenshot" + i); if (image != null) { - backdropFiles.Add(image.FullName); + screenshotFiles.Add(image.FullName); } else { @@ -251,28 +257,57 @@ namespace MediaBrowser.Controller.Providers } } + if (screenshotFiles.Count > 0) + { + item.ScreenshotImagePaths = screenshotFiles; + } + } + + /// + /// Populates the backdrops. + /// + /// The item. + private void PopulateBackdrops(BaseItem item) + { + var backdropFiles = new List(); + + PopulateBackdrops(item, backdropFiles, "backdrop", "backdrop"); + + // Support plex/xbmc conventions + PopulateBackdrops(item, backdropFiles, "fanart", "fanart-"); + PopulateBackdrops(item, backdropFiles, "background", "background-"); + if (backdropFiles.Count > 0) { item.BackdropImagePaths = backdropFiles; } + } - // Screenshot Image - image = GetImage(item, "screenshot"); + /// + /// Populates the backdrops. + /// + /// The item. + /// The backdrop files. + /// The filename. + /// The numbered suffix. + private void PopulateBackdrops(BaseItem item, List backdropFiles, string filename, string numberedSuffix) + { + var image = GetImage(item, filename); if (image != null) { - screenshotFiles.Add(image.FullName); + backdropFiles.Add(image.FullName); } - unfound = 0; + var unfound = 0; for (var i = 1; i <= 20; i++) { - // Screenshot Image - image = GetImage(item, "screenshot" + i); + // Backdrop Image + image = GetImage(item, numberedSuffix + i); if (image != null) { - screenshotFiles.Add(image.FullName); + backdropFiles.Add(image.FullName); } else { @@ -284,11 +319,6 @@ namespace MediaBrowser.Controller.Providers } } } - - if (screenshotFiles.Count > 0) - { - item.ScreenshotImagePaths = screenshotFiles; - } } } }