2013-02-24 17:13:45 -07:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-03 22:43:06 -07:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-24 17:13:45 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-03-02 10:59:15 -07:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.Movies
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MovieProviderFromJson
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MovieProviderFromJson : MovieDbProvider
|
|
|
|
|
{
|
2013-03-03 22:43:06 -07:00
|
|
|
|
public MovieProviderFromJson(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient) :
|
|
|
|
|
base(logManager, configurationManager, jsonSerializer, httpClient)
|
2013-02-24 14:53:54 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [requires internet].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public override bool RequiresInternet
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override this to return the date that should be compared to the last refresh date
|
|
|
|
|
/// to determine if this provider should be re-fetched.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>DateTime.</returns>
|
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME));
|
|
|
|
|
return entry != null ? entry.Value.LastWriteTimeUtc : DateTime.MinValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
if (item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME))
|
|
|
|
|
{
|
|
|
|
|
return false; // don't read our file if 3rd party data exists
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME))
|
|
|
|
|
{
|
|
|
|
|
return false; // nothing to read
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Need to re-override to jump over intermediate implementation
|
|
|
|
|
return CompareDate(item) > providerInfo.LastRefreshed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the async.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
|
|
|
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
// Since we don't have anything truly async, and since deserializing can be expensive, create a task to force parallelism
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME));
|
|
|
|
|
if (entry.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// read in our saved meta and pass to processing function
|
|
|
|
|
var movieData = JsonSerializer.DeserializeFromFile<CompleteMovieData>(entry.Value.Path);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
ProcessMainInfo(item, movieData);
|
|
|
|
|
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|