support more xbmc image conventions

This commit is contained in:
Luke Pulverenti 2013-10-15 21:44:23 -04:00
parent d176da1ba9
commit 28bb5c7903
3 changed files with 264 additions and 97 deletions

View File

@ -173,73 +173,16 @@ namespace MediaBrowser.Providers
/// <param name="args">The args.</param>
private void PopulateBaseItemImages(BaseItem item, ItemResolveArgs args)
{
// Primary Image
var image = GetImage(item, args, "folder") ??
GetImage(item, args, "poster") ??
GetImage(item, args, "cover") ??
GetImage(item, args, "default");
// Support plex/xbmc convention
if (image == null && item is Series)
{
image = GetImage(item, args, "show");
}
// Support plex/xbmc convention
if (image == null && item is Season && item.IndexNumber.HasValue)
{
var num = item.IndexNumber.Value.ToString(_usCulture);
image = GetImage(item, args, string.Format("season-{0}", num));
}
// Support plex/xbmc convention
if (image == null && (item is Movie || item is MusicVideo || item is AdultVideo))
{
image = GetImage(item, args, "movie");
}
// Look for a file with the same name as the item
if (image == null)
{
var name = Path.GetFileNameWithoutExtension(item.Path);
if (!string.IsNullOrEmpty(name))
{
image = GetImage(item, args, name) ??
GetImage(item, args, name + "-poster");
}
}
if (image != null)
{
item.SetImage(ImageType.Primary, image.FullName);
}
PopulatePrimaryImage(item, args);
// Logo Image
image = GetImage(item, args, "logo");
var image = GetImage(item, args, "logo");
if (image != null)
{
item.SetImage(ImageType.Logo, image.FullName);
}
// Banner Image
image = GetImage(item, args, "banner");
// Support plex/xbmc convention
if (image == null && item is Season && item.IndexNumber.HasValue)
{
var num = item.IndexNumber.Value.ToString(_usCulture);
image = GetImage(item, args, string.Format("season-{0}-banner", num));
}
if (image != null)
{
item.SetImage(ImageType.Banner, image.FullName);
}
// Clearart
image = GetImage(item, args, "clearart");
@ -257,14 +200,6 @@ namespace MediaBrowser.Providers
item.SetImage(ImageType.Disc, image.FullName);
}
// Thumbnail Image
image = GetImage(item, args, "thumb");
if (image != null)
{
item.SetImage(ImageType.Thumb, image.FullName);
}
// Box Image
image = GetImage(item, args, "box");
@ -289,46 +224,166 @@ namespace MediaBrowser.Providers
item.SetImage(ImageType.Menu, image.FullName);
}
PopulateBanner(item, args);
PopulateThumb(item, args);
// Backdrop Image
PopulateBackdrops(item, args);
PopulateScreenshots(item, args);
}
// Screenshot Image
image = GetImage(item, args, "screenshot");
private void PopulatePrimaryImage(BaseItem item, ItemResolveArgs args)
{
// Primary Image
var image = GetImage(item, args, "folder") ??
GetImage(item, args, "poster") ??
GetImage(item, args, "cover") ??
GetImage(item, args, "default");
var screenshotFiles = new List<string>();
// Support plex/xbmc convention
if (image == null && item is Series)
{
image = GetImage(item, args, "show") ??
GetImage(item, args, "season-all-poster");
}
// Support plex/xbmc convention
if (image == null && item is Season && item.IndexNumber.HasValue)
{
var seasonMarker = item.IndexNumber.Value == 0
? "-specials"
: item.IndexNumber.Value.ToString("00", _usCulture);
// Get this one directly from the file system since we have to go up a level
var filename = "season" + seasonMarker + "-poster";
var path = Path.GetDirectoryName(item.Path);
path = Path.Combine(path, filename);
image = new FileInfo(path);
if (!image.Exists)
{
image = null;
}
}
// Support plex/xbmc convention
if (image == null && (item is Movie || item is MusicVideo || item is AdultVideo))
{
image = GetImage(item, args, "movie");
}
// Look for a file with the same name as the item
if (image == null)
{
var name = Path.GetFileNameWithoutExtension(item.Path);
if (!string.IsNullOrEmpty(name))
{
image = GetImage(item, args, name) ??
GetImage(item, args, name + "-poster");
}
}
if (image != null)
{
screenshotFiles.Add(image.FullName);
item.SetImage(ImageType.Primary, image.FullName);
}
}
var unfound = 0;
for (var i = 1; i <= 20; i++)
/// <summary>
/// Populates the banner.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
private void PopulateBanner(BaseItem item, ItemResolveArgs args)
{
// Banner Image
var image = GetImage(item, args, "banner");
if (image == null)
{
// Screenshot Image
image = GetImage(item, args, "screenshot" + i);
if (image != null)
// Supprt xbmc conventions
if (item is Series)
{
screenshotFiles.Add(image.FullName);
image = GetImage(item, args, "season-all-banner");
}
else
else if (item is Season && item.IndexNumber.HasValue)
{
unfound++;
var seasonMarker = item.IndexNumber.Value == 0
? "-specials"
: item.IndexNumber.Value.ToString("00", _usCulture);
if (unfound >= 3)
// Get this one directly from the file system since we have to go up a level
var filename = "season" + seasonMarker + "-banner";
var path = Path.GetDirectoryName(item.Path);
path = Path.Combine(path, filename);
image = new FileInfo(path);
if (!image.Exists)
{
break;
image = null;
}
}
}
if (screenshotFiles.Count > 0)
if (image != null)
{
item.ScreenshotImagePaths = screenshotFiles;
item.SetImage(ImageType.Banner, image.FullName);
}
}
/// <summary>
/// Populates the thumb.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
private void PopulateThumb(BaseItem item, ItemResolveArgs args)
{
// Thumbnail Image
var image = GetImage(item, args, "thumb");
if (image == null)
{
// Supprt xbmc conventions
if (item is Series)
{
image = GetImage(item, args, "season-all-landscape");
}
else if (item is Season && item.IndexNumber.HasValue)
{
var seasonMarker = item.IndexNumber.Value == 0
? "-specials"
: item.IndexNumber.Value.ToString("00", _usCulture);
// Get this one directly from the file system since we have to go up a level
var filename = "season" + seasonMarker + "-landscape";
var path = Path.GetDirectoryName(item.Path);
path = Path.Combine(path, filename);
image = new FileInfo(path);
if (!image.Exists)
{
image = null;
}
}
}
if (image != null)
{
item.SetImage(ImageType.Thumb, image.FullName);
}
}
/// <summary>
/// Populates the backdrops.
/// </summary>
@ -345,6 +400,37 @@ namespace MediaBrowser.Providers
PopulateBackdrops(item, args, backdropFiles, "background", "background-");
PopulateBackdrops(item, args, backdropFiles, "art", "art-");
if (item is Series)
{
var image = GetImage(item, args, "season-all-fanart");
if (image != null)
{
backdropFiles.Add(image.FullName);
}
}
if (item is Season && item.IndexNumber.HasValue)
{
var seasonMarker = item.IndexNumber.Value == 0
? "-specials"
: item.IndexNumber.Value.ToString("00", _usCulture);
// Get this one directly from the file system since we have to go up a level
var filename = "season" + seasonMarker + "-fanart";
var path = Path.GetDirectoryName(item.Path);
path = Path.Combine(path, filename);
var image = new FileInfo(path);
if (image.Exists)
{
backdropFiles.Add(image.FullName);
}
}
PopulateBackdropsFromExtraFanart(args, backdropFiles);
if (backdropFiles.Count > 0)
@ -425,5 +511,49 @@ namespace MediaBrowser.Providers
}
}
}
/// <summary>
/// Populates the screenshots.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
private void PopulateScreenshots(BaseItem item, ItemResolveArgs args)
{
// Screenshot Image
var image = GetImage(item, args, "screenshot");
var screenshotFiles = new List<string>();
if (image != null)
{
screenshotFiles.Add(image.FullName);
}
var unfound = 0;
for (var i = 1; i <= 20; i++)
{
// Screenshot Image
image = GetImage(item, args, "screenshot" + i);
if (image != null)
{
screenshotFiles.Add(image.FullName);
}
else
{
unfound++;
if (unfound >= 3)
{
break;
}
}
}
if (screenshotFiles.Count > 0)
{
item.ScreenshotImagePaths = screenshotFiles;
}
}
}
}

View File

@ -218,8 +218,6 @@ namespace MediaBrowser.Providers.TV
if (!string.IsNullOrEmpty(seriesId))
{
series.SetProviderId(MetadataProviders.Tvdb, seriesId);
var seriesDataPath = GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId);
await FetchSeriesData(series, seriesId, seriesDataPath, force, cancellationToken).ConfigureAwait(false);
@ -255,19 +253,25 @@ namespace MediaBrowser.Providers.TV
await DownloadSeriesZip(seriesId, seriesDataPath, null, cancellationToken).ConfigureAwait(false);
}
// Examine if there's no local metadata, or save local is on (to get updates)
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTvDbUpdates || !HasLocalMeta(series))
// Have to check this here since we prevent the normal enforcement through ProviderManager
if (!series.DontFetchMeta)
{
var seriesXmlPath = Path.Combine(seriesDataPath, seriesXmlFilename);
var actorsXmlPath = Path.Combine(seriesDataPath, "actors.xml");
FetchSeriesInfo(series, seriesXmlPath, cancellationToken);
if (!series.LockedFields.Contains(MetadataFields.Cast))
// Examine if there's no local metadata, or save local is on (to get updates)
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTvDbUpdates || !HasLocalMeta(series))
{
series.People.Clear();
series.SetProviderId(MetadataProviders.Tvdb, seriesId);
FetchActors(series, actorsXmlPath, cancellationToken);
var seriesXmlPath = Path.Combine(seriesDataPath, seriesXmlFilename);
var actorsXmlPath = Path.Combine(seriesDataPath, "actors.xml");
FetchSeriesInfo(series, seriesXmlPath, cancellationToken);
if (!series.LockedFields.Contains(MetadataFields.Cast))
{
series.People.Clear();
FetchActors(series, actorsXmlPath, cancellationToken);
}
}
}
}

View File

@ -396,6 +396,24 @@ namespace MediaBrowser.Server.Implementations.Providers
if (imageIndex.Value == 0)
{
if (item is Series)
{
return new[] { Path.Combine(item.Path, "season-all-fanart" + extension) };
}
if (item is Season && item.IndexNumber.HasValue)
{
var seriesFolder = Path.GetDirectoryName(item.Path);
var seasonMarker = item.IndexNumber.Value == 0
? "-specials"
: item.IndexNumber.Value.ToString("00", UsCulture);
var imageFilename = "season" + seasonMarker + "-fanart" + extension;
return new[] { Path.Combine(seriesFolder, imageFilename) };
}
return new[]
{
Path.Combine(item.MetaLocation, "fanart" + extension)
@ -413,6 +431,11 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Primary)
{
if (item is Series)
{
return new[] { Path.Combine(item.Path, "season-all-poster" + extension) };
}
if (item is Season && item.IndexNumber.HasValue)
{
var seriesFolder = Path.GetDirectoryName(item.Path);
@ -446,6 +469,11 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Banner)
{
if (item is Series)
{
return new[] { Path.Combine(item.Path, "season-all-banner" + extension) };
}
if (item is Season && item.IndexNumber.HasValue)
{
var seriesFolder = Path.GetDirectoryName(item.Path);
@ -462,6 +490,11 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Thumb)
{
if (item is Series)
{
return new[] { Path.Combine(item.Path, "season-all-landscape" + extension) };
}
if (item is Season && item.IndexNumber.HasValue)
{
var seriesFolder = Path.GetDirectoryName(item.Path);