2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Net;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using System.Net;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.Movies
|
|
|
|
|
{
|
|
|
|
|
class MovieDbProviderException : ApplicationException
|
|
|
|
|
{
|
2013-04-13 18:02:30 +00:00
|
|
|
|
public MovieDbProviderException(string msg)
|
|
|
|
|
: base(msg)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MovieDbProvider
|
|
|
|
|
/// </summary>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public class MovieDbProvider : BaseMetadataProvider, IDisposable
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-04-22 15:26:56 +00:00
|
|
|
|
protected static CultureInfo EnUs = new CultureInfo("en-US");
|
|
|
|
|
|
2013-03-08 05:08:27 +00:00
|
|
|
|
protected readonly IProviderManager ProviderManager;
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The movie db
|
|
|
|
|
/// </summary>
|
2013-05-06 18:10:44 +00:00
|
|
|
|
internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(2, 2);
|
2013-03-04 05:43:06 +00:00
|
|
|
|
|
|
|
|
|
internal static MovieDbProvider Current { get; private set; }
|
|
|
|
|
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the json serializer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The json serializer.</value>
|
|
|
|
|
protected IJsonSerializer JsonSerializer { get; private set; }
|
|
|
|
|
|
2013-02-25 00:13:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the HTTP client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The HTTP client.</value>
|
|
|
|
|
protected IHttpClient HttpClient { get; private set; }
|
|
|
|
|
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
|
|
|
|
|
/// </summary>
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
2013-02-25 00:13:45 +00:00
|
|
|
|
/// <param name="httpClient">The HTTP client.</param>
|
2013-04-10 15:56:36 +00:00
|
|
|
|
/// <param name="providerManager">The provider manager.</param>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IProviderManager providerManager)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
2013-02-24 21:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
JsonSerializer = jsonSerializer;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
HttpClient = httpClient;
|
2013-03-08 05:08:27 +00:00
|
|
|
|
ProviderManager = providerManager;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
Current = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Releases unmanaged and - optionally - managed resources.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
protected virtual void Dispose(bool dispose)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (dispose)
|
|
|
|
|
{
|
|
|
|
|
MovieDbResourcePool.Dispose();
|
|
|
|
|
}
|
2013-02-24 21:53:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.Second; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
2013-05-06 15:37:02 +00:00
|
|
|
|
var trailer = item as Trailer;
|
|
|
|
|
|
|
|
|
|
if (trailer != null)
|
|
|
|
|
{
|
|
|
|
|
return !trailer.IsLocalTrailer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Don't support local trailers
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return item is Movie || item is BoxSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If we save locally, refresh if they delete something
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override bool RefreshOnFileSystemStampChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-03-04 05:43:06 +00:00
|
|
|
|
return ConfigurationManager.Configuration.SaveLocalMeta;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected override bool RefreshOnVersionChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "2";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _TMDB settings task
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Task<TmdbSettingsResult> _tmdbSettingsTask;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _TMDB settings task initialized
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool _tmdbSettingsTaskInitialized;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _TMDB settings task sync lock
|
|
|
|
|
/// </summary>
|
|
|
|
|
private object _tmdbSettingsTaskSyncLock = new object();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the TMDB settings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The TMDB settings.</value>
|
|
|
|
|
public Task<TmdbSettingsResult> TmdbSettings
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-02-25 00:13:45 +00:00
|
|
|
|
LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, () => GetTmdbSettings(JsonSerializer, HttpClient));
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return _tmdbSettingsTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the TMDB settings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Task{TmdbSettingsResult}.</returns>
|
2013-02-25 00:13:45 +00:00
|
|
|
|
private static async Task<TmdbSettingsResult> GetTmdbSettings(IJsonSerializer jsonSerializer, IHttpClient httpClient)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (var json = await httpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = string.Format(TmdbConfigUrl, ApiKey),
|
|
|
|
|
CancellationToken = CancellationToken.None,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-24 21:53:54 +00:00
|
|
|
|
return jsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-27 04:19:05 +00:00
|
|
|
|
catch (HttpException)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return new TmdbSettingsResult
|
|
|
|
|
{
|
|
|
|
|
images = new TmdbImageSettings
|
|
|
|
|
{
|
|
|
|
|
backdrop_sizes =
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"w380",
|
|
|
|
|
"w780",
|
|
|
|
|
"w1280",
|
|
|
|
|
"original"
|
|
|
|
|
},
|
|
|
|
|
poster_sizes =
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"w92",
|
|
|
|
|
"w154",
|
|
|
|
|
"w185",
|
|
|
|
|
"w342",
|
|
|
|
|
"w500",
|
|
|
|
|
"original"
|
|
|
|
|
},
|
|
|
|
|
profile_sizes =
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"w45",
|
|
|
|
|
"w185",
|
|
|
|
|
"h632",
|
|
|
|
|
"original"
|
|
|
|
|
},
|
|
|
|
|
base_url = "http://cf2.imgobject.com/t/p/"
|
|
|
|
|
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
};
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The json provider
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected MovieProviderFromJson JsonProvider;
|
2013-03-03 16:05:17 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the persisted last refresh date on the item for this provider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
/// <param name="providerVersion">The provider version.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <param name="status">The status.</param>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public override void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-03-08 05:08:27 +00:00
|
|
|
|
base.SetLastRefreshed(item, value, providerVersion, status);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-06 15:37:02 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
//in addition to ours, we need to set the last refreshed time for the local data provider
|
|
|
|
|
//so it won't see the new files we download and process them all over again
|
2013-03-08 05:08:27 +00:00
|
|
|
|
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(LogManager, ConfigurationManager, JsonSerializer, HttpClient, ProviderManager);
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
|
|
|
|
BaseProviderInfo data;
|
|
|
|
|
|
|
|
|
|
if (!item.ProviderData.TryGetValue(JsonProvider.Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
data.LastRefreshed = value;
|
|
|
|
|
item.ProviderData[JsonProvider.Id] = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
|
|
|
|
|
private const string Search3 = @"http://api.themoviedb.org/3/search/movie?api_key={1}&query={0}&language={2}";
|
|
|
|
|
private const string AltTitleSearch = @"http://api.themoviedb.org/3/movie/{0}/alternative_titles?api_key={1}&country={2}";
|
2013-05-06 22:52:13 +00:00
|
|
|
|
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords";
|
|
|
|
|
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images";
|
|
|
|
|
|
2013-05-04 04:15:39 +00:00
|
|
|
|
internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669";
|
|
|
|
|
internal static string AcceptHeader = "application/json,image/*";
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
static readonly Regex[] NameMatches = new[] {
|
|
|
|
|
new Regex(@"(?<name>.*)\((?<year>\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year
|
|
|
|
|
new Regex(@"(?<name>.*)") // last resort matches the whole string as the name
|
|
|
|
|
};
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public const string LOCAL_META_FILE_NAME = "tmdb3.json";
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public const string ALT_META_FILE_NAME = "movie.xml";
|
|
|
|
|
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
if (item.DontFetchMeta) return false;
|
|
|
|
|
|
2013-05-06 15:37:02 +00:00
|
|
|
|
if (item.LocationType == LocationType.FileSystem &&
|
|
|
|
|
ConfigurationManager.Configuration.SaveLocalMeta &&
|
|
|
|
|
HasFileSystemStampChanged(item, providerInfo))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
//If they deleted something from file system, chances are, this item was mis-identified the first time
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, null);
|
|
|
|
|
Logger.Debug("MovieProvider reports file system stamp change...");
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 04:38:03 +00:00
|
|
|
|
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Debug("MovieProvider for {0} - last attempt had errors. Will try again.", item.Path);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
if (RefreshOnVersionChange && !String.Equals(ProviderVersion, providerInfo.ProviderVersion))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
var downloadDate = providerInfo.LastRefreshed;
|
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
if (DateTime.Today.Subtract(downloadDate).TotalDays < ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (HasAltMeta(item))
|
|
|
|
|
return false; //never refresh if has meta from other source
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (HasAltMeta(item))
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("MovieDbProvider - Not fetching because 3rd party meta exists for " + item.Name);
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (item.DontFetchMeta)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("MovieDbProvider - Not fetching because requested to ignore " + item.Name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
if (!ConfigurationManager.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item)))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await FetchMovieData(item, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
}
|
2013-02-27 04:19:05 +00:00
|
|
|
|
catch (MovieDbProviderException)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.CompletedWithErrors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
Logger.Debug("MovieDBProvider not fetching because local meta exists for " + item.Name);
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [has local meta] [the specified item].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if [has local meta] [the specified item]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
private bool HasLocalMeta(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
//need at least the xml and folder.jpg/png or a movie.xml put in by someone else
|
2013-05-06 15:37:02 +00:00
|
|
|
|
return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [has alt meta] [the specified item].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if [has alt meta] [the specified item]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
private bool HasAltMeta(BaseItem item)
|
|
|
|
|
{
|
2013-05-06 15:37:02 +00:00
|
|
|
|
return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the movie data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
private async Task FetchMovieData(BaseItem item, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
string id = item.GetProviderId(MetadataProviders.Tmdb) ?? await FindId(item, item.ProductionYear, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
if (id != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("MovieDbProvider - getting movie info with id: " + id);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
await FetchMovieData(item, id, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("MovieDBProvider could not find " + item.Name + ". Check name on themoviedb.org.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses the name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <param name="justName">Name of the just.</param>
|
|
|
|
|
/// <param name="year">The year.</param>
|
|
|
|
|
protected void ParseName(string name, out string justName, out int? year)
|
|
|
|
|
{
|
|
|
|
|
justName = null;
|
|
|
|
|
year = null;
|
|
|
|
|
foreach (var re in NameMatches)
|
|
|
|
|
{
|
|
|
|
|
Match m = re.Match(name);
|
|
|
|
|
if (m.Success)
|
|
|
|
|
{
|
|
|
|
|
justName = m.Groups["name"].Value.Trim();
|
|
|
|
|
string y = m.Groups["year"] != null ? m.Groups["year"].Value : null;
|
|
|
|
|
int temp;
|
|
|
|
|
year = Int32.TryParse(y, out temp) ? temp : (int?)null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="productionYear">The production year.</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.String}.</returns>
|
|
|
|
|
public async Task<string> FindId(BaseItem item, int? productionYear, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2013-05-06 15:37:02 +00:00
|
|
|
|
string id = null;
|
|
|
|
|
|
|
|
|
|
if (item.LocationType == LocationType.FileSystem)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 15:37:02 +00:00
|
|
|
|
string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty;
|
|
|
|
|
id = justName.GetAttributeValue("tmdbid");
|
|
|
|
|
if (id != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Using tmdb id specified in path.");
|
|
|
|
|
return id;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int? year;
|
|
|
|
|
string name = item.Name;
|
|
|
|
|
ParseName(name, out name, out year);
|
|
|
|
|
|
|
|
|
|
if (year == null && productionYear != null)
|
|
|
|
|
{
|
|
|
|
|
year = productionYear;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Info("MovieDbProvider: Finding id for movie: " + name);
|
2013-03-04 05:43:06 +00:00
|
|
|
|
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
//if we are a boxset - look at our first child
|
|
|
|
|
var boxset = item as BoxSet;
|
|
|
|
|
if (boxset != null)
|
|
|
|
|
{
|
2013-05-03 04:10:11 +00:00
|
|
|
|
var firstChild = boxset.Children.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (firstChild != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Debug("MovieDbProvider - Attempting to find boxset ID from: " + firstChild.Name);
|
|
|
|
|
string childName;
|
|
|
|
|
int? childYear;
|
|
|
|
|
ParseName(firstChild.Name, out childName, out childYear);
|
|
|
|
|
id = await GetBoxsetIdFromMovie(childName, childYear, language, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
if (id != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("MovieDbProvider - Found Boxset ID: " + id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
//nope - search for it
|
|
|
|
|
id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
|
|
|
|
//try in english if wasn't before
|
|
|
|
|
if (language != "en")
|
|
|
|
|
{
|
|
|
|
|
id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// try with dot and _ turned to space
|
2013-05-06 18:10:44 +00:00
|
|
|
|
var originalName = name;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
name = name.Replace(",", " ");
|
|
|
|
|
name = name.Replace(".", " ");
|
|
|
|
|
name = name.Replace("_", " ");
|
|
|
|
|
name = name.Replace("-", "");
|
2013-05-06 18:10:44 +00:00
|
|
|
|
|
|
|
|
|
// Search again if the new name is different
|
|
|
|
|
if (!string.Equals(name, originalName))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 18:10:44 +00:00
|
|
|
|
id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (id == null && language != "en")
|
|
|
|
|
{
|
|
|
|
|
//one more time, in english
|
|
|
|
|
id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-06 18:10:44 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-06 18:10:44 +00:00
|
|
|
|
|
2013-05-06 17:35:51 +00:00
|
|
|
|
if (id == null && item.LocationType == LocationType.FileSystem)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
//last resort - try using the actual folder name
|
2013-05-06 18:10:44 +00:00
|
|
|
|
var pathName = Path.GetFileName(item.ResolveArgs.Path);
|
|
|
|
|
|
|
|
|
|
// Only search if it's a name we haven't already tried.
|
|
|
|
|
if (!string.Equals(pathName, name, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
&& !string.Equals(pathName, originalName, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
id = await AttemptFindId(pathName, year, "en", cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-06 18:10:44 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts the find id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <param name="year">The year.</param>
|
|
|
|
|
/// <param name="language">The language.</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.String}.</returns>
|
|
|
|
|
public virtual async Task<string> AttemptFindId(string name, int? year, string language, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
string url3 = string.Format(Search3, UrlEncode(name), ApiKey, language);
|
|
|
|
|
TmdbMovieSearchResults searchResult = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (Stream json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url3,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
searchResult = JsonSerializer.DeserializeFromStream<TmdbMovieSearchResults>(json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
if (searchResult == null || searchResult.results.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//try replacing numbers
|
|
|
|
|
foreach (var pair in ReplaceStartNumbers)
|
|
|
|
|
{
|
|
|
|
|
if (name.StartsWith(pair.Key))
|
|
|
|
|
{
|
|
|
|
|
name = name.Remove(0, pair.Key.Length);
|
|
|
|
|
name = pair.Value + name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var pair in ReplaceEndNumbers)
|
|
|
|
|
{
|
|
|
|
|
if (name.EndsWith(pair.Key))
|
|
|
|
|
{
|
|
|
|
|
name = name.Remove(name.IndexOf(pair.Key), pair.Key.Length);
|
|
|
|
|
name = name + pair.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Logger.Info("MovieDBProvider - No results. Trying replacement numbers: " + name);
|
|
|
|
|
url3 = string.Format(Search3, UrlEncode(name), ApiKey, language);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (var json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url3,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
searchResult = JsonSerializer.DeserializeFromStream<TmdbMovieSearchResults>(json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (searchResult != null)
|
|
|
|
|
{
|
|
|
|
|
string compName = GetComparableName(name, Logger);
|
|
|
|
|
foreach (var possible in searchResult.results)
|
|
|
|
|
{
|
|
|
|
|
string matchedName = null;
|
2013-04-22 15:26:56 +00:00
|
|
|
|
string id = possible.id.ToString(CultureInfo.InvariantCulture);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
string n = possible.title;
|
|
|
|
|
if (GetComparableName(n, Logger) == compName)
|
|
|
|
|
{
|
|
|
|
|
matchedName = n;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
n = possible.original_title;
|
|
|
|
|
if (GetComparableName(n, Logger) == compName)
|
|
|
|
|
{
|
|
|
|
|
matchedName = n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Debug("MovieDbProvider - " + compName + " didn't match " + n);
|
|
|
|
|
//if main title matches we don't have to look for alternatives
|
|
|
|
|
if (matchedName == null)
|
|
|
|
|
{
|
|
|
|
|
//that title didn't match - look for alternatives
|
2013-03-04 05:43:06 +00:00
|
|
|
|
url3 = string.Format(AltTitleSearch, id, ApiKey, ConfigurationManager.Configuration.MetadataCountryCode);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (var json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url3,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
var response = JsonSerializer.DeserializeFromStream<TmdbAltTitleResults>(json);
|
|
|
|
|
|
|
|
|
|
if (response != null && response.titles != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var title in response.titles)
|
|
|
|
|
{
|
|
|
|
|
var t = GetComparableName(title.title, Logger);
|
|
|
|
|
if (t == compName)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("MovieDbProvider - " + compName +
|
|
|
|
|
" matched " + t);
|
|
|
|
|
matchedName = t;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Logger.Debug("MovieDbProvider - " + compName +
|
|
|
|
|
" did not match " + t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (matchedName != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Match " + matchedName + " for " + name);
|
|
|
|
|
if (year != null)
|
|
|
|
|
{
|
|
|
|
|
DateTime r;
|
|
|
|
|
|
2013-04-22 15:26:56 +00:00
|
|
|
|
//These dates are always in this exact format
|
|
|
|
|
if (DateTime.TryParseExact(possible.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (Math.Abs(r.Year - year.Value) > 1) // allow a 1 year tolerance on release date
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Result " + matchedName + " released on " + r + " did not match year " + year);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//matched name and year
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// URLs the encode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
private static string UrlEncode(string name)
|
|
|
|
|
{
|
|
|
|
|
return WebUtility.UrlEncode(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the boxset id from movie.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <param name="year">The year.</param>
|
|
|
|
|
/// <param name="language">The language.</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.String}.</returns>
|
|
|
|
|
protected async Task<string> GetBoxsetIdFromMovie(string name, int? year, string language, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
string id = null;
|
|
|
|
|
string childId = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
if (childId != null)
|
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
string url = string.Format(GetMovieInfo3, childId, ApiKey, language);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (Stream json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
var movieResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
|
|
|
|
|
|
|
|
|
|
if (movieResult != null && movieResult.belongs_to_collection != null)
|
|
|
|
|
{
|
2013-03-03 16:05:17 +00:00
|
|
|
|
id = movieResult.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error("Unable to obtain boxset id.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the movie data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="id">The id.</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
protected async Task FetchMovieData(BaseItem item, string id, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("MoviedbProvider: Ignoring " + item.Name + " because ID forced blank.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (item.GetProviderId(MetadataProviders.Tmdb) == null) item.SetProviderId(MetadataProviders.Tmdb, id);
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
var mainResult = await FetchMainResult(item, id, cancellationToken).ConfigureAwait(false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
if (mainResult == null) return;
|
|
|
|
|
|
|
|
|
|
ProcessMainInfo(item, mainResult);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
//and save locally
|
2013-05-06 15:37:02 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
var ms = new MemoryStream();
|
|
|
|
|
JsonSerializer.SerializeToStream(mainResult, ms);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-03-08 05:08:27 +00:00
|
|
|
|
await ProviderManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the main result.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="id">The id.</param>
|
2013-03-03 16:05:17 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{CompleteMovieData}.</returns>
|
|
|
|
|
protected async Task<CompleteMovieData> FetchMainResult(BaseItem item, string id, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
var baseUrl = item is BoxSet ? GetBoxSetInfo3 : GetMovieInfo3;
|
|
|
|
|
|
|
|
|
|
string url = string.Format(baseUrl, id, ApiKey, ConfigurationManager.Configuration.PreferredMetadataLanguage);
|
2013-03-03 16:05:17 +00:00
|
|
|
|
CompleteMovieData mainResult;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (var json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
mainResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException e)
|
|
|
|
|
{
|
|
|
|
|
if (e.IsTimedOut)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("MovieDbProvider timed out attempting to retrieve main info for {0}", e, item.Path);
|
|
|
|
|
throw new MovieDbProviderException("Timed out on main info");
|
|
|
|
|
}
|
|
|
|
|
if (e.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("MovieDbProvider not found error attempting to retrieve main info for {0}", e, item.Path);
|
|
|
|
|
throw new MovieDbProviderException("Not Found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (mainResult != null && string.IsNullOrEmpty(mainResult.overview))
|
|
|
|
|
{
|
2013-03-04 05:43:06 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower() != "en")
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-03-04 05:43:06 +00:00
|
|
|
|
Logger.Info("MovieDbProvider couldn't find meta for language " + ConfigurationManager.Configuration.PreferredMetadataLanguage + ". Trying English...");
|
2013-05-06 22:52:13 +00:00
|
|
|
|
|
|
|
|
|
url = string.Format(baseUrl, id, ApiKey, "en");
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-05-04 04:15:39 +00:00
|
|
|
|
using (Stream json = await HttpClient.Get(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = url,
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
ResourcePool = Current.MovieDbResourcePool,
|
2013-05-06 19:31:57 +00:00
|
|
|
|
AcceptHeader = AcceptHeader,
|
|
|
|
|
EnableResponseCache = true
|
2013-05-04 04:15:39 +00:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
mainResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(mainResult.overview))
|
|
|
|
|
{
|
|
|
|
|
Logger.Error("MovieDbProvider - Unable to find information for " + item.Name + " (id:" + id + ")");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mainResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processes the main info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="movie">The movie.</param>
|
|
|
|
|
/// <param name="movieData">The movie data.</param>
|
|
|
|
|
protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
|
|
|
|
|
{
|
|
|
|
|
if (movie != null && movieData != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
movie.Name = movieData.title ?? movieData.original_title ?? movie.Name;
|
|
|
|
|
movie.Overview = movieData.overview;
|
|
|
|
|
movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null;
|
2013-04-12 14:13:47 +00:00
|
|
|
|
movie.HomePageUrl = movieData.homepage;
|
|
|
|
|
movie.Budget = movieData.budget;
|
2013-04-18 13:54:38 +00:00
|
|
|
|
movie.Revenue = movieData.revenue;
|
2013-04-12 14:13:47 +00:00
|
|
|
|
|
2013-04-28 05:44:45 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(movieData.tagline))
|
|
|
|
|
{
|
|
|
|
|
movie.Taglines.Clear();
|
|
|
|
|
movie.AddTagline(movieData.tagline);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id);
|
2013-05-07 03:20:51 +00:00
|
|
|
|
|
|
|
|
|
if (movieData.belongs_to_collection != null)
|
|
|
|
|
{
|
|
|
|
|
movie.SetProviderId(MetadataProviders.TmdbCollection, movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
float rating;
|
2013-04-22 15:26:56 +00:00
|
|
|
|
string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
//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
|
|
|
|
|
if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
movie.CommunityRating = rating;
|
|
|
|
|
|
|
|
|
|
//release date and certification are retrieved based on configured country and we fall back on US if not there
|
2013-05-06 22:52:13 +00:00
|
|
|
|
if (movieData.releases != null && movieData.releases.countries != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country();
|
|
|
|
|
var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
movie.OfficialRating = ourRelease.certification ?? usRelease.certification;
|
2013-05-06 22:52:13 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
if (ourRelease.release_date > new DateTime(1900, 1, 1))
|
|
|
|
|
{
|
2013-05-07 03:00:24 +00:00
|
|
|
|
if (ourRelease.release_date.Year != 1)
|
|
|
|
|
{
|
|
|
|
|
movie.PremiereDate = ourRelease.release_date.ToUniversalTime();
|
|
|
|
|
movie.ProductionYear = ourRelease.release_date.Year;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-07 03:00:24 +00:00
|
|
|
|
if (usRelease.release_date.Year != 1)
|
|
|
|
|
{
|
|
|
|
|
movie.PremiereDate = usRelease.release_date.ToUniversalTime();
|
|
|
|
|
movie.ProductionYear = usRelease.release_date.Year;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-07 03:00:24 +00:00
|
|
|
|
if (movieData.release_date.Year != 1)
|
|
|
|
|
{
|
|
|
|
|
//no specific country release info at all
|
|
|
|
|
movie.PremiereDate = movieData.release_date.ToUniversalTime();
|
|
|
|
|
movie.ProductionYear = movieData.release_date.Year;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if that didn't find a rating and we are a boxset, use the one from our first child
|
|
|
|
|
if (movie.OfficialRating == null && movie is BoxSet)
|
|
|
|
|
{
|
|
|
|
|
var boxset = movie as BoxSet;
|
|
|
|
|
Logger.Info("MovieDbProvider - Using rating of first child of boxset...");
|
2013-05-03 04:10:11 +00:00
|
|
|
|
|
|
|
|
|
var firstChild = boxset.Children.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 13:06:01 +00:00
|
|
|
|
//if (movie.RunTimeTicks == null && movieData.runtime > 0)
|
|
|
|
|
// movie.RunTimeTicks = TimeSpan.FromMinutes(movieData.runtime).Ticks;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
//studios
|
|
|
|
|
if (movieData.production_companies != null)
|
|
|
|
|
{
|
2013-04-28 05:44:45 +00:00
|
|
|
|
movie.Studios.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var studio in movieData.production_companies.Select(c => c.name))
|
|
|
|
|
{
|
|
|
|
|
movie.AddStudio(studio);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//genres
|
|
|
|
|
if (movieData.genres != null)
|
|
|
|
|
{
|
2013-04-28 05:44:45 +00:00
|
|
|
|
movie.Genres.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var genre in movieData.genres.Select(g => g.name))
|
|
|
|
|
{
|
|
|
|
|
movie.AddGenre(genre);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 05:44:45 +00:00
|
|
|
|
movie.People.Clear();
|
2013-05-06 22:52:13 +00:00
|
|
|
|
movie.Tags.Clear();
|
2013-04-28 05:44:45 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
//Actors, Directors, Writers - all in People
|
|
|
|
|
//actors come from cast
|
2013-05-06 22:52:13 +00:00
|
|
|
|
if (movieData.casts != null && movieData.casts.cast != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name, Role = actor.character, Type = PersonType.Actor });
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-06 22:52:13 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
//and the rest from crew
|
2013-05-06 22:52:13 +00:00
|
|
|
|
if (movieData.casts != null && movieData.casts.crew != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
foreach (var person in movieData.casts.crew) movie.AddPerson(new PersonInfo { Name = person.name, Role = person.job, Type = person.department });
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
if (movieData.keywords != null && movieData.keywords.keywords != null)
|
|
|
|
|
{
|
|
|
|
|
movie.Tags = movieData.keywords.keywords.Select(i => i.name).ToList();
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The remove
|
|
|
|
|
/// </summary>
|
|
|
|
|
const string remove = "\"'!`?";
|
|
|
|
|
// "Face/Off" support.
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The spacers
|
|
|
|
|
/// </summary>
|
|
|
|
|
const string spacers = "/,.:;\\(){}[]+-_=–*"; // (there are not actually two - in the they are different char codes)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The replace start numbers
|
|
|
|
|
/// </summary>
|
|
|
|
|
static readonly Dictionary<string, string> ReplaceStartNumbers = new Dictionary<string, string> {
|
|
|
|
|
{"1 ","one "},
|
|
|
|
|
{"2 ","two "},
|
|
|
|
|
{"3 ","three "},
|
|
|
|
|
{"4 ","four "},
|
|
|
|
|
{"5 ","five "},
|
|
|
|
|
{"6 ","six "},
|
|
|
|
|
{"7 ","seven "},
|
|
|
|
|
{"8 ","eight "},
|
|
|
|
|
{"9 ","nine "},
|
|
|
|
|
{"10 ","ten "},
|
|
|
|
|
{"11 ","eleven "},
|
|
|
|
|
{"12 ","twelve "},
|
|
|
|
|
{"13 ","thirteen "},
|
|
|
|
|
{"100 ","one hundred "},
|
|
|
|
|
{"101 ","one hundred one "}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The replace end numbers
|
|
|
|
|
/// </summary>
|
|
|
|
|
static readonly Dictionary<string, string> ReplaceEndNumbers = new Dictionary<string, string> {
|
|
|
|
|
{" 1"," i"},
|
|
|
|
|
{" 2"," ii"},
|
|
|
|
|
{" 3"," iii"},
|
|
|
|
|
{" 4"," iv"},
|
|
|
|
|
{" 5"," v"},
|
|
|
|
|
{" 6"," vi"},
|
|
|
|
|
{" 7"," vii"},
|
|
|
|
|
{" 8"," viii"},
|
|
|
|
|
{" 9"," ix"},
|
|
|
|
|
{" 10"," x"}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the comparable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
internal static string GetComparableName(string name, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
name = name.ToLower();
|
|
|
|
|
name = name.Replace("á", "a");
|
|
|
|
|
name = name.Replace("é", "e");
|
|
|
|
|
name = name.Replace("í", "i");
|
|
|
|
|
name = name.Replace("ó", "o");
|
|
|
|
|
name = name.Replace("ú", "u");
|
|
|
|
|
name = name.Replace("ü", "u");
|
|
|
|
|
name = name.Replace("ñ", "n");
|
|
|
|
|
foreach (var pair in ReplaceStartNumbers)
|
|
|
|
|
{
|
|
|
|
|
if (name.StartsWith(pair.Key))
|
|
|
|
|
{
|
|
|
|
|
name = name.Remove(0, pair.Key.Length);
|
|
|
|
|
name = pair.Value + name;
|
|
|
|
|
logger.Info("MovieDbProvider - Replaced Start Numbers: " + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var pair in ReplaceEndNumbers)
|
|
|
|
|
{
|
|
|
|
|
if (name.EndsWith(pair.Key))
|
|
|
|
|
{
|
|
|
|
|
name = name.Remove(name.IndexOf(pair.Key), pair.Key.Length);
|
|
|
|
|
name = name + pair.Value;
|
|
|
|
|
logger.Info("MovieDbProvider - Replaced End Numbers: " + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
name = name.Normalize(NormalizationForm.FormKD);
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
foreach (var c in name)
|
|
|
|
|
{
|
2013-03-03 16:05:17 +00:00
|
|
|
|
if (c >= 0x2B0 && c <= 0x0333)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
// skip char modifier and diacritics
|
|
|
|
|
}
|
|
|
|
|
else if (remove.IndexOf(c) > -1)
|
|
|
|
|
{
|
|
|
|
|
// skip chars we are removing
|
|
|
|
|
}
|
|
|
|
|
else if (spacers.IndexOf(c) > -1)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(" ");
|
|
|
|
|
}
|
|
|
|
|
else if (c == '&')
|
|
|
|
|
{
|
|
|
|
|
sb.Append(" and ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
name = sb.ToString();
|
|
|
|
|
name = name.Replace(", the", "");
|
|
|
|
|
name = name.Replace(" the ", " ");
|
|
|
|
|
name = name.Replace("the ", "");
|
|
|
|
|
|
|
|
|
|
string prev_name;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
prev_name = name;
|
|
|
|
|
name = name.Replace(" ", " ");
|
|
|
|
|
} while (name.Length != prev_name.Length);
|
|
|
|
|
|
|
|
|
|
return name.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Result Objects
|
|
|
|
|
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class TmdbTitle
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected class TmdbTitle
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the iso_3166_1.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The iso_3166_1.</value>
|
|
|
|
|
public string iso_3166_1 { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the title.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The title.</value>
|
|
|
|
|
public string title { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class TmdbAltTitleResults
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected class TmdbAltTitleResults
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the titles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The titles.</value>
|
|
|
|
|
public List<TmdbTitle> titles { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class TmdbMovieSearchResult
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected class TmdbMovieSearchResult
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this <see cref="TmdbMovieSearchResult" /> is adult.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool adult { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the backdrop_path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The backdrop_path.</value>
|
|
|
|
|
public string backdrop_path { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the original_title.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The original_title.</value>
|
|
|
|
|
public string original_title { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the release_date.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The release_date.</value>
|
|
|
|
|
public string release_date { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the poster_path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The poster_path.</value>
|
|
|
|
|
public string poster_path { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the popularity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The popularity.</value>
|
|
|
|
|
public double popularity { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the title.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The title.</value>
|
|
|
|
|
public string title { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the vote_average.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The vote_average.</value>
|
|
|
|
|
public double vote_average { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the vote_count.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The vote_count.</value>
|
|
|
|
|
public int vote_count { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class TmdbMovieSearchResults
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected class TmdbMovieSearchResults
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the page.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The page.</value>
|
|
|
|
|
public int page { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the results.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The results.</value>
|
|
|
|
|
public List<TmdbMovieSearchResult> results { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the total_pages.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The total_pages.</value>
|
|
|
|
|
public int total_pages { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the total_results.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The total_results.</value>
|
|
|
|
|
public int total_results { get; set; }
|
|
|
|
|
}
|
2013-05-06 22:52:13 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
protected class BelongsToCollection
|
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string poster_path { get; set; }
|
|
|
|
|
public string backdrop_path { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected class GenreItem
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class ProductionCompany
|
|
|
|
|
{
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class ProductionCountry
|
|
|
|
|
{
|
|
|
|
|
public string iso_3166_1 { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class SpokenLanguage
|
|
|
|
|
{
|
|
|
|
|
public string iso_639_1 { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class Cast
|
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string character { get; set; }
|
|
|
|
|
public int order { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public int cast_id { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public string profile_path { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class Crew
|
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string department { get; set; }
|
|
|
|
|
public string job { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public string profile_path { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected class Casts
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public List<Cast> cast { get; set; }
|
|
|
|
|
public List<Crew> crew { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected class Country
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
public string iso_3166_1 { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public string certification { get; set; }
|
|
|
|
|
public DateTime release_date { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected class Releases
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public List<Country> countries { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 22:52:13 +00:00
|
|
|
|
protected class Keyword
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public string name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class Keywords
|
|
|
|
|
{
|
|
|
|
|
public List<Keyword> keywords { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class CompleteMovieData
|
|
|
|
|
{
|
|
|
|
|
public bool adult { get; set; }
|
|
|
|
|
public string backdrop_path { get; set; }
|
|
|
|
|
public BelongsToCollection belongs_to_collection { get; set; }
|
|
|
|
|
public int budget { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public List<GenreItem> genres { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public string homepage { get; set; }
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public string imdb_id { get; set; }
|
|
|
|
|
public string original_title { get; set; }
|
|
|
|
|
public string overview { get; set; }
|
|
|
|
|
public double popularity { get; set; }
|
|
|
|
|
public string poster_path { get; set; }
|
|
|
|
|
public List<ProductionCompany> production_companies { get; set; }
|
|
|
|
|
public List<ProductionCountry> production_countries { get; set; }
|
|
|
|
|
public DateTime release_date { get; set; }
|
|
|
|
|
public int revenue { get; set; }
|
|
|
|
|
public int runtime { get; set; }
|
|
|
|
|
public List<SpokenLanguage> spoken_languages { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public string status { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public string tagline { get; set; }
|
|
|
|
|
public string title { get; set; }
|
|
|
|
|
public double vote_average { get; set; }
|
|
|
|
|
public int vote_count { get; set; }
|
2013-05-06 22:52:13 +00:00
|
|
|
|
public Casts casts { get; set; }
|
|
|
|
|
public Releases releases { get; set; }
|
|
|
|
|
public Keywords keywords { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TmdbImageSettings
|
|
|
|
|
{
|
|
|
|
|
public List<string> backdrop_sizes { get; set; }
|
|
|
|
|
public string base_url { get; set; }
|
|
|
|
|
public List<string> poster_sizes { get; set; }
|
|
|
|
|
public List<string> profile_sizes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TmdbSettingsResult
|
|
|
|
|
{
|
|
|
|
|
public TmdbImageSettings images { get; set; }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2013-03-08 05:08:27 +00:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|