prioritize tmdb images ahead of fanart, but with min resolution settings

pull/702/head
Luke Pulverenti 11 years ago
parent d18f000e88
commit 42deac1dce

@ -221,8 +221,30 @@ namespace MediaBrowser.Model.Configuration
/// <value><c>true</c> if [create virtual future episodes]; otherwise, <c>false</c>.</value>
public bool CreateVirtualFutureEpisodes { get; set; }
/// <summary>
/// Gets or sets the image saving convention.
/// </summary>
/// <value>The image saving convention.</value>
public ImageSavingConvention ImageSavingConvention { get; set; }
/// <summary>
/// Gets or sets the width of the min movie backdrop.
/// </summary>
/// <value>The width of the min movie backdrop.</value>
public int MinMovieBackdropWidth { get; set; }
/// <summary>
/// Gets or sets the width of the min movie poster.
/// </summary>
/// <value>The width of the min movie poster.</value>
public int MinMoviePosterWidth { get; set; }
/// <summary>
/// Gets or sets the width of the min series backdrop.
/// </summary>
/// <value>The width of the min series backdrop.</value>
public int MinSeriesBackdropWidth { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
/// </summary>
@ -268,6 +290,10 @@ namespace MediaBrowser.Model.Configuration
SortRemoveWords = new[] { "the", "a", "an" };
SeasonZeroDisplayName = "Specials";
MinMovieBackdropWidth = 1920;
MinSeriesBackdropWidth = 1920;
MinMoviePosterWidth = 1000;
}
}

@ -97,7 +97,7 @@ namespace MediaBrowser.Providers.Movies
{
get
{
return MetadataProviderPriority.Fourth;
return MetadataProviderPriority.Fifth;
}
}
@ -300,17 +300,17 @@ namespace MediaBrowser.Providers.Movies
string path;
//if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
//{
// var node = doc.SelectSingleNode("//fanart/movie/movieposters/movieposter[@lang = \"" + language + "\"]/@url") ??
// doc.SelectSingleNode("//fanart/movie/movieposters/movieposter/@url");
// path = node != null ? node.Value : null;
// if (!string.IsNullOrEmpty(path))
// {
// await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Disc, null, cancellationToken)
// .ConfigureAwait(false);
// }
//}
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
{
var node = doc.SelectSingleNode("//fanart/movie/movieposters/movieposter[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/movieposters/movieposter/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Disc, null, cancellationToken)
.ConfigureAwait(false);
}
}
cancellationToken.ThrowIfCancellationRequested();

@ -56,7 +56,7 @@ namespace MediaBrowser.Providers.Movies
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Fifth; }
get { return MetadataProviderPriority.Fourth; }
}
/// <summary>
@ -202,15 +202,20 @@ namespace MediaBrowser.Providers.Movies
var status = ProviderRefreshStatus.Success;
var eligiblePosters = images.posters == null ?
new List<Poster>() :
images.posters.Where(i => i.width >= ConfigurationManager.Configuration.MinMoviePosterWidth)
.ToList();
// poster
if (images.posters != null && images.posters.Count > 0 && !item.HasImage(ImageType.Primary))
if (eligiblePosters.Count > 0 && !item.HasImage(ImageType.Primary))
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
// get highest rated poster for our language
var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average);
var postersSortedByVote = eligiblePosters.OrderByDescending(i => i.vote_average);
var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase));
if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en"))
@ -245,14 +250,18 @@ namespace MediaBrowser.Providers.Movies
cancellationToken.ThrowIfCancellationRequested();
var eligibleBackdrops = images.backdrops == null ? new List<Backdrop>() :
images.backdrops.Where(i => i.width >= ConfigurationManager.Configuration.MinMovieBackdropWidth)
.ToList();
// backdrops - only download if earlier providers didn't find any (fanart)
if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count == 0)
if (eligibleBackdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count == 0)
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
for (var i = 0; i < images.backdrops.Count; i++)
for (var i = 0; i < eligibleBackdrops.Count; i++)
{
var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture));
@ -262,12 +271,12 @@ namespace MediaBrowser.Providers.Movies
{
var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = tmdbImageUrl + images.backdrops[i].file_path,
Url = tmdbImageUrl + eligibleBackdrops[i].file_path,
CancellationToken = cancellationToken
}).ConfigureAwait(false);
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(images.backdrops[i].file_path), ImageType.Backdrop, item.BackdropImagePaths.Count, cancellationToken)
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(eligibleBackdrops[i].file_path), ImageType.Backdrop, item.BackdropImagePaths.Count, cancellationToken)
.ConfigureAwait(false);
}

@ -61,7 +61,7 @@ namespace MediaBrowser.Providers.Movies
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
if (!_config.Configuration.EnableInternetProviders || !_config.Configuration.EnableTmdbUpdates)
if (!_config.Configuration.EnableInternetProviders)
{
progress.Report(100);
return;
@ -97,8 +97,10 @@ namespace MediaBrowser.Providers.Movies
var timestampFileInfo = new FileInfo(timestampFile);
var refreshDays = _config.Configuration.EnableTmdbUpdates ? 1 : 7;
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - timestampFileInfo.LastWriteTimeUtc).TotalDays < 1)
if (timestampFileInfo.Exists && (DateTime.UtcNow - timestampFileInfo.LastWriteTimeUtc).TotalDays < refreshDays)
{
return;
}

@ -172,7 +172,6 @@
<Compile Include="Persistence\SqliteExtensions.cs" />
<Compile Include="Persistence\SqliteNotificationsRepository.cs" />
<Compile Include="Persistence\TypeMapper.cs" />
<Compile Include="Persistence\UserDataMigration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\ImageSaver.cs" />
<Compile Include="Providers\ProviderManager.cs" />

@ -86,13 +86,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
};
_connection.RunQueries(queries, _logger);
var oldFile = Path.Combine(_appPaths.DataPath, "userdata.db");
if (File.Exists(oldFile))
{
await UserDataMigration.Migrate(oldFile, _connection, _logger, _jsonSerializer).ConfigureAwait(false);
}
}
/// <summary>

@ -1,144 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Persistence
{
public static class UserDataMigration
{
/// <summary>
/// Migrates the specified old file.
/// </summary>
/// <param name="oldFile">The old file.</param>
/// <param name="newDatabase">The new database.</param>
/// <param name="logger">The logger.</param>
/// <param name="json">The json.</param>
/// <returns>Task.</returns>
public static async Task Migrate(string oldFile, IDbConnection newDatabase, ILogger logger, IJsonSerializer json)
{
var oldDb = await SqliteExtensions.ConnectToDb(oldFile).ConfigureAwait(false);
using (oldDb)
{
IDbTransaction transaction = null;
var data = GetAllUserData(oldDb, json).ToList();
try
{
transaction = newDatabase.BeginTransaction();
foreach (var userdata in data)
{
PersistUserData(userdata, newDatabase, transaction);
}
transaction.Commit();
}
catch (OperationCanceledException)
{
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
catch (Exception e)
{
logger.ErrorException("Failed to save user data:", e);
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
finally
{
if (transaction != null)
{
transaction.Dispose();
}
}
}
var backupFile = Path.Combine(Path.GetDirectoryName(oldFile), "userdata_v1.db.bak");
if (File.Exists(backupFile))
{
File.Delete(backupFile);
}
File.Move(oldFile, backupFile);
}
/// <summary>
/// Gets all user data.
/// </summary>
/// <param name="oldDatabase">The old database.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <returns>IEnumerable{UserItemData}.</returns>
private static IEnumerable<UserItemData> GetAllUserData(IDbConnection oldDatabase, IJsonSerializer jsonSerializer)
{
using (var cmd = oldDatabase.CreateCommand())
{
cmd.CommandText = "select userId,key,data from userdata";
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
{
while (reader.Read())
{
var userId = reader.GetGuid(0);
var key = reader.GetString(1);
using (var stream = reader.GetMemoryStream(2))
{
var userData = jsonSerializer.DeserializeFromStream<UserItemData>(stream);
userData.UserId = userId;
userData.Key = key;
yield return userData;
}
}
}
}
}
/// <summary>
/// Persists the user data.
/// </summary>
/// <param name="userData">The user data.</param>
/// <param name="database">The database.</param>
/// <param name="transaction">The transaction.</param>
private static void PersistUserData(UserItemData userData, IDbConnection database, IDbTransaction transaction)
{
using (var cmd = database.CreateCommand())
{
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate)";
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = userData.Key;
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userData.UserId;
cmd.Parameters.Add(cmd, "@rating", DbType.Double).Value = userData.Rating;
cmd.Parameters.Add(cmd, "@played", DbType.Boolean).Value = userData.Played;
cmd.Parameters.Add(cmd, "@playCount", DbType.Int32).Value = userData.PlayCount;
cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userData.IsFavorite;
cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userData.PlaybackPositionTicks;
cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userData.LastPlayedDate;
cmd.Transaction = transaction;
cmd.ExecuteNonQuery();
}
}
}
}
Loading…
Cancel
Save