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.
/// </summary>
/// <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; }
}

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

@ -206,7 +206,8 @@ namespace MediaBrowser.Providers
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 isRefreshingDueToTmdbUpdate = hasAltMeta && !isForcedRefresh;
if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath))
{
var isBoxSet = item is BoxSet;
@ -528,8 +526,6 @@ namespace MediaBrowser.Providers.Movies
Directory.CreateDirectory(directory);
JsonSerializer.SerializeToFile(mainResult, dataFilePath);
isRefreshingDueToTmdbUpdate = false;
}
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !hasAltMeta)
@ -538,7 +534,7 @@ namespace MediaBrowser.Providers.Movies
var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
ProcessMainInfo(item, mainResult, isRefreshingDueToTmdbUpdate);
ProcessMainInfo(item, mainResult);
}
}
@ -650,8 +646,7 @@ namespace MediaBrowser.Providers.Movies
/// </summary>
/// <param name="movie">The movie.</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, bool isRefreshingDueToTmdbUpdate)
protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
{
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
// 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
if (!isRefreshingDueToTmdbUpdate && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
// Movies get this from imdb
if (movie is BoxSet && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
{
movie.CommunityRating = rating;
}
// Don't import this when responding to tmdb updates because we don't want to blow away imdb data
if (!isRefreshingDueToTmdbUpdate)
// Movies get this from imdb
if (movie is BoxSet)
{
movie.VoteCount = movieData.vote_count;
}
@ -784,8 +779,8 @@ namespace MediaBrowser.Providers.Movies
}
// genres
// Don't import this when responding to tmdb updates because we don't want to blow away imdb data
if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres) && !isRefreshingDueToTmdbUpdate)
// Movies get this from imdb
if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres) && movie is BoxSet)
{
movie.Genres.Clear();

@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using System;
using System.Globalization;
@ -92,7 +93,11 @@ namespace MediaBrowser.Server.Implementations.Providers
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);
@ -112,8 +117,8 @@ namespace MediaBrowser.Server.Implementations.Providers
{
file.Attributes &= ~FileAttributes.Hidden;
}
}
}
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);
@ -210,7 +215,7 @@ namespace MediaBrowser.Server.Implementations.Providers
/// or
/// imageIndex
/// </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;
@ -271,22 +276,81 @@ namespace MediaBrowser.Server.Implementations.Providers
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)
{
if (type == ImageType.Primary)
{
return Path.ChangeExtension(item.Path, extension);
imageFilename = "poster";
}
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