fixes #588 - Add option to use xbmc convention when saving images

pull/702/head
Luke Pulverenti 11 years ago
parent f3c2609c8c
commit ca2e0f3451

@ -22,6 +22,7 @@ namespace MediaBrowser.Api.UserLibrary
/// Gets or sets the person types. /// Gets or sets the person types.
/// </summary> /// </summary>
/// <value>The person types.</value> /// <value>The person types.</value>
[ApiMember(Name = "PersonTypes", Description = "Optional filter by person type. Accepts multiple, comma-delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string PersonTypes { get; set; } public string PersonTypes { get; set; }
} }

@ -228,12 +228,15 @@ namespace MediaBrowser.Model.Configuration
public bool EnableVideoImageExtraction { get; set; } public bool EnableVideoImageExtraction { get; set; }
public ImageSavingConvention ImageSavingConvention { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class. /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
/// </summary> /// </summary>
public ServerConfiguration() public ServerConfiguration()
: base() : base()
{ {
ImageSavingConvention = ImageSavingConvention.Legacy;
HttpServerPortNumber = 8096; HttpServerPortNumber = 8096;
LegacyWebSocketPortNumber = 8945; LegacyWebSocketPortNumber = 8945;
EnableHttpLevelLogging = true; EnableHttpLevelLogging = true;
@ -277,4 +280,10 @@ namespace MediaBrowser.Model.Configuration
SeasonZeroDisplayName = "Specials"; SeasonZeroDisplayName = "Specials";
} }
} }
public enum ImageSavingConvention
{
Legacy,
Compatible
}
} }

@ -206,7 +206,8 @@ namespace MediaBrowser.Providers
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
image = GetImage(item, args, name); image = GetImage(item, args, name) ??
GetImage(item, args, name + "-poster");
} }
} }

@ -509,8 +509,6 @@ namespace MediaBrowser.Providers.Movies
var hasAltMeta = HasAltMeta(item); var hasAltMeta = HasAltMeta(item);
var isRefreshingDueToTmdbUpdate = hasAltMeta && !isForcedRefresh;
if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath)) if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath))
{ {
var isBoxSet = item is BoxSet; var isBoxSet = item is BoxSet;
@ -528,8 +526,6 @@ namespace MediaBrowser.Providers.Movies
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
JsonSerializer.SerializeToFile(mainResult, dataFilePath); JsonSerializer.SerializeToFile(mainResult, dataFilePath);
isRefreshingDueToTmdbUpdate = false;
} }
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !hasAltMeta) if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !hasAltMeta)
@ -538,7 +534,7 @@ namespace MediaBrowser.Providers.Movies
var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath); var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
ProcessMainInfo(item, mainResult, isRefreshingDueToTmdbUpdate); ProcessMainInfo(item, mainResult);
} }
} }
@ -650,8 +646,7 @@ namespace MediaBrowser.Providers.Movies
/// </summary> /// </summary>
/// <param name="movie">The movie.</param> /// <param name="movie">The movie.</param>
/// <param name="movieData">The movie data.</param> /// <param name="movieData">The movie data.</param>
/// <param name="isRefreshingDueToTmdbUpdate">if set to <c>true</c> [is refreshing due to TMDB update].</param> protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData, bool isRefreshingDueToTmdbUpdate)
{ {
if (movie != null && movieData != null) if (movie != null && movieData != null)
{ {
@ -691,14 +686,14 @@ namespace MediaBrowser.Providers.Movies
// tmdb appears to have unified their numbers to always report "7.3" regardless of country // tmdb appears to have unified their numbers to always report "7.3" regardless of country
// so I removed the culture-specific processing here because it was not working for other countries -ebr // so I removed the culture-specific processing here because it was not working for other countries -ebr
// Don't import this when responding to tmdb updates because we don't want to blow away imdb data // Movies get this from imdb
if (!isRefreshingDueToTmdbUpdate && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating)) if (movie is BoxSet && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
{ {
movie.CommunityRating = rating; movie.CommunityRating = rating;
} }
// Don't import this when responding to tmdb updates because we don't want to blow away imdb data // Movies get this from imdb
if (!isRefreshingDueToTmdbUpdate) if (movie is BoxSet)
{ {
movie.VoteCount = movieData.vote_count; movie.VoteCount = movieData.vote_count;
} }
@ -784,8 +779,8 @@ namespace MediaBrowser.Providers.Movies
} }
// genres // genres
// Don't import this when responding to tmdb updates because we don't want to blow away imdb data // Movies get this from imdb
if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres) && !isRefreshingDueToTmdbUpdate) if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres) && movie is BoxSet)
{ {
movie.Genres.Clear(); movie.Genres.Clear();

@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO; using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using System; using System;
using System.Globalization; using System.Globalization;
@ -92,7 +93,11 @@ namespace MediaBrowser.Server.Implementations.Providers
saveLocally = false; saveLocally = false;
} }
var path = GetSavePath(item, type, imageIndex, mimeType, saveLocally); var path = saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible ?
GetCompatibleSavePath(item, type, imageIndex, mimeType) :
GetLegacySavePath(item, type, imageIndex, mimeType, saveLocally);
Directory.CreateDirectory(Path.GetDirectoryName(path));
var currentPath = GetCurrentImagePath(item, type, imageIndex); var currentPath = GetCurrentImagePath(item, type, imageIndex);
@ -112,8 +117,8 @@ namespace MediaBrowser.Server.Implementations.Providers
{ {
file.Attributes &= ~FileAttributes.Hidden; file.Attributes &= ~FileAttributes.Hidden;
} }
} }
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
{ {
await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
@ -210,7 +215,7 @@ namespace MediaBrowser.Server.Implementations.Providers
/// or /// or
/// imageIndex /// imageIndex
/// </exception> /// </exception>
private string GetSavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally) private string GetLegacySavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
{ {
string filename; string filename;
@ -271,22 +276,81 @@ namespace MediaBrowser.Server.Implementations.Providers
path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename); path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename);
} }
var parentPath = Path.GetDirectoryName(path); return path;
}
Directory.CreateDirectory(parentPath); /// <summary>
/// Gets the compatible save path.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="mimeType">Type of the MIME.</param>
/// <returns>System.String.</returns>
/// <exception cref="System.ArgumentNullException">imageIndex</exception>
private string GetCompatibleSavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType)
{
var extension = mimeType.Split('/').Last();
return path; if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase))
{
extension = "jpg";
}
extension = "." + extension.ToLower();
// Backdrop paths
if (type == ImageType.Backdrop)
{
if (!imageIndex.HasValue)
{
throw new ArgumentNullException("imageIndex");
}
if (imageIndex.Value == 0)
{
return Path.Combine(item.MetaLocation, "fanart" + extension);
}
return Path.Combine(item.MetaLocation, "extrafanart", "fanart" + imageIndex.Value.ToString(UsCulture) + extension);
}
if (type == ImageType.Primary)
{
if (item is Episode)
{
return Path.ChangeExtension(item.Path, extension);
}
if (item.IsInMixedFolder)
{
return GetSavePathForItemInMixedFolder(item, type, string.Empty, extension);
}
var filename = Path.GetFileNameWithoutExtension(item.Path) + "-poster" + extension;
return Path.Combine(item.MetaLocation, filename);
}
// All other paths are the same
return GetLegacySavePath(item, type, imageIndex, mimeType, true);
} }
/// <summary>
/// Gets the save path for item in mixed folder.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageFilename">The image filename.</param>
/// <param name="extension">The extension.</param>
/// <returns>System.String.</returns>
private string GetSavePathForItemInMixedFolder(BaseItem item, ImageType type, string imageFilename, string extension) private string GetSavePathForItemInMixedFolder(BaseItem item, ImageType type, string imageFilename, string extension)
{ {
if (type == ImageType.Primary) if (type == ImageType.Primary)
{ {
return Path.ChangeExtension(item.Path, extension); imageFilename = "poster";
} }
var folder = Path.GetDirectoryName(item.Path); var folder = Path.GetDirectoryName(item.Path);
return Path.Combine(folder, Path.GetFileNameWithoutExtension(item.Path) + "-" + imageFilename); return Path.Combine(folder, Path.GetFileNameWithoutExtension(item.Path) + "-" + imageFilename + extension);
} }
} }
} }

Loading…
Cancel
Save