fix images saving with incorrect paths.

pull/702/head
Luke Pulverenti 11 years ago
parent c997effcb1
commit 77cff18dce

@ -145,6 +145,11 @@ namespace MediaBrowser.Providers.Movies
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
{
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
{
return false;
}
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
if (!string.IsNullOrEmpty(path))
@ -169,13 +174,18 @@ namespace MediaBrowser.Providers.Movies
/// <returns>Task{System.Boolean}.</returns>
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var images = FetchImages(item, item.GetProviderId(MetadataProviders.Tmdb), cancellationToken);
var id = item.GetProviderId(MetadataProviders.Tmdb);
var status = ProviderRefreshStatus.Success;
if (images != null)
if (!string.IsNullOrEmpty(id))
{
status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
var images = FetchImages(item);
if (images != null)
{
status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
}
}
SetLastRefreshed(item, DateTime.UtcNow, status);
@ -186,10 +196,8 @@ namespace MediaBrowser.Providers.Movies
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="id">The id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private MovieDbProvider.Images FetchImages(BaseItem item, string id, CancellationToken cancellationToken)
private MovieDbProvider.Images FetchImages(BaseItem item)
{
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");

@ -194,9 +194,6 @@ namespace MediaBrowser.Providers.Movies
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (HasAltMeta(item) && !ConfigurationManager.Configuration.EnableTmdbUpdates)
return false;
// Boxsets require two passes because we need the children to be refreshed
if (item is BoxSet && string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
{
@ -220,6 +217,8 @@ namespace MediaBrowser.Providers.Movies
{
return fileInfo.LastWriteTimeUtc > providerInfo.LastRefreshed;
}
return true;
}
return base.NeedsRefreshBasedOnCompareDate(item, providerInfo);
@ -507,8 +506,6 @@ namespace MediaBrowser.Providers.Movies
var dataFilePath = GetDataFilePath(item, language);
var hasAltMeta = HasAltMeta(item);
if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath))
{
var isBoxSet = item is BoxSet;
@ -535,7 +532,7 @@ namespace MediaBrowser.Providers.Movies
JsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !hasAltMeta)
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item))
{
dataFilePath = GetDataFilePath(item, language);

@ -2,7 +2,6 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
@ -83,7 +82,7 @@ namespace MediaBrowser.Providers.Movies
// Find out the last time we queried tvdb for updates
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
var existingDirectories = GetExistingIds(path).ToList();
if (!string.IsNullOrEmpty(lastUpdateTime))
{
@ -105,7 +104,7 @@ namespace MediaBrowser.Providers.Movies
var idsToUpdate = updatedIds.Where(i => !string.IsNullOrWhiteSpace(i) && existingDictionary.ContainsKey(i));
await UpdatePeople(idsToUpdate, path, progress, cancellationToken).ConfigureAwait(false);
await UpdatePeople(idsToUpdate, progress, cancellationToken).ConfigureAwait(false);
}
}
@ -113,6 +112,18 @@ namespace MediaBrowser.Providers.Movies
progress.Report(100);
}
/// <summary>
/// Gets the existing ids.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>IEnumerable{System.String}.</returns>
private IEnumerable<string> GetExistingIds(string path)
{
return Directory.EnumerateDirectories(path)
.SelectMany(Directory.EnumerateDirectories)
.Select(Path.GetFileNameWithoutExtension);
}
/// <summary>
/// Gets the ids to update.
/// </summary>
@ -159,11 +170,10 @@ namespace MediaBrowser.Providers.Movies
/// Updates the people.
/// </summary>
/// <param name="ids">The ids.</param>
/// <param name="peopleDataPath">The people data path.</param>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private async Task UpdatePeople(IEnumerable<string> ids, string peopleDataPath, IProgress<double> progress, CancellationToken cancellationToken)
private async Task UpdatePeople(IEnumerable<string> ids, IProgress<double> progress, CancellationToken cancellationToken)
{
var list = ids.ToList();
var numComplete = 0;
@ -172,7 +182,7 @@ namespace MediaBrowser.Providers.Movies
{
try
{
await UpdatePerson(id, peopleDataPath, cancellationToken).ConfigureAwait(false);
await UpdatePerson(id, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -192,18 +202,13 @@ namespace MediaBrowser.Providers.Movies
/// Updates the person.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="peopleDataPath">The people data path.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private Task UpdatePerson(string id, string peopleDataPath, CancellationToken cancellationToken)
private Task UpdatePerson(string id, CancellationToken cancellationToken)
{
_logger.Info("Updating person from tmdb " + id);
var personDataPath = Path.Combine(peopleDataPath, id);
Directory.CreateDirectory(peopleDataPath);
return TmdbPersonProvider.Current.DownloadPersonInfo(id, personDataPath, cancellationToken);
return TmdbPersonProvider.Current.DownloadPersonInfo(id, cancellationToken);
}
class Result

@ -1,4 +1,5 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
@ -27,7 +28,9 @@ namespace MediaBrowser.Providers.Movies
protected readonly IProviderManager ProviderManager;
internal static TmdbPersonProvider Current { get; private set; }
const string DataFileName = "info.json";
public TmdbPersonProvider(IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
@ -68,7 +71,7 @@ namespace MediaBrowser.Providers.Movies
{
get
{
return "2";
return "3";
}
}
@ -97,23 +100,15 @@ namespace MediaBrowser.Providers.Movies
// Process images
var path = GetPersonDataPath(ConfigurationManager.ApplicationPaths, provderId);
try
{
var files = new DirectoryInfo(path)
.EnumerateFiles("*.json", SearchOption.TopDirectoryOnly)
.Select(i => i.LastWriteTimeUtc)
.ToList();
if (files.Count > 0)
{
return files.Max() > providerInfo.LastRefreshed;
}
}
catch (DirectoryNotFoundException)
var file = Path.Combine(path, DataFileName);
var fileInfo = new FileInfo(file);
if (fileInfo.Exists)
{
// Don't blow up
return true;
return fileInfo.LastWriteTimeUtc > providerInfo.LastRefreshed;
}
return true;
}
return base.NeedsRefreshBasedOnCompareDate(item, providerInfo);
@ -121,7 +116,9 @@ namespace MediaBrowser.Providers.Movies
internal static string GetPersonDataPath(IApplicationPaths appPaths, string tmdbId)
{
var seriesDataPath = Path.Combine(GetPersonsDataPath(appPaths), tmdbId);
var letter = tmdbId.GetMD5().ToString().Substring(0, 1);
var seriesDataPath = Path.Combine(GetPersonsDataPath(appPaths), letter, tmdbId);
return seriesDataPath;
}
@ -240,18 +237,16 @@ namespace MediaBrowser.Providers.Movies
.Select(Path.GetFileName)
.ToList();
const string dataFileName = "info.json";
// Only download if not already there
// The prescan task will take care of updates so we don't need to re-download here
if (!files.Contains(dataFileName, StringComparer.OrdinalIgnoreCase))
if (!files.Contains(DataFileName, StringComparer.OrdinalIgnoreCase))
{
await DownloadPersonInfo(id, personDataPath, cancellationToken).ConfigureAwait(false);
await DownloadPersonInfo(id, cancellationToken).ConfigureAwait(false);
}
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(person))
{
var info = JsonSerializer.DeserializeFromFile<PersonResult>(Path.Combine(personDataPath, dataFileName));
var info = JsonSerializer.DeserializeFromFile<PersonResult>(Path.Combine(personDataPath, DataFileName));
cancellationToken.ThrowIfCancellationRequested();
@ -263,8 +258,10 @@ namespace MediaBrowser.Providers.Movies
}
}
internal async Task DownloadPersonInfo(string id, string personDataPath, CancellationToken cancellationToken)
internal async Task DownloadPersonInfo(string id, CancellationToken cancellationToken)
{
var personDataPath = GetPersonDataPath(ConfigurationManager.ApplicationPaths, id);
var url = string.Format(@"http://api.themoviedb.org/3/person/{1}?api_key={0}&append_to_response=credits,images", MovieDbProvider.ApiKey, id);
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
@ -275,7 +272,9 @@ namespace MediaBrowser.Providers.Movies
}).ConfigureAwait(false))
{
using (var fs = new FileStream(Path.Combine(personDataPath, "info.json"), FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true))
Directory.CreateDirectory(personDataPath);
using (var fs = new FileStream(Path.Combine(personDataPath, DataFileName), FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true))
{
await json.CopyToAsync(fs).ConfigureAwait(false);
}

@ -362,6 +362,8 @@ namespace MediaBrowser.Server.Implementations.Providers
extension = "jpg";
}
extension = "." + extension.ToLower();
string path = null;
if (saveLocally)
@ -373,16 +375,14 @@ namespace MediaBrowser.Server.Implementations.Providers
if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(item.MetaLocation))
{
path = Path.Combine(item.MetaLocation, filename + extension.ToLower());
path = Path.Combine(item.MetaLocation, filename + extension);
}
}
filename += "." + extension.ToLower();
// None of the save local conditions passed, so store it in our internal folders
if (string.IsNullOrEmpty(path))
{
path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename);
path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename + extension);
}
return path;

Loading…
Cancel
Save