MovieDbProvider.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Common.Net;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Entities.Movies;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.Logging;
  8. using MediaBrowser.Model.Net;
  9. using MediaBrowser.Model.Serialization;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Globalization;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Net;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.Controller.Providers.Movies
  21. {
  22. class MovieDbProviderException : ApplicationException
  23. {
  24. public MovieDbProviderException(string msg) : base(msg)
  25. {
  26. }
  27. }
  28. /// <summary>
  29. /// Class MovieDbProvider
  30. /// </summary>
  31. public class MovieDbProvider : BaseMetadataProvider, IDisposable
  32. {
  33. protected readonly IProviderManager ProviderManager;
  34. /// <summary>
  35. /// The movie db
  36. /// </summary>
  37. internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(4, 4);
  38. internal static MovieDbProvider Current { get; private set; }
  39. /// <summary>
  40. /// Gets the json serializer.
  41. /// </summary>
  42. /// <value>The json serializer.</value>
  43. protected IJsonSerializer JsonSerializer { get; private set; }
  44. /// <summary>
  45. /// Gets the HTTP client.
  46. /// </summary>
  47. /// <value>The HTTP client.</value>
  48. protected IHttpClient HttpClient { get; private set; }
  49. /// <summary>
  50. /// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
  51. /// </summary>
  52. /// <param name="logManager">The log manager.</param>
  53. /// <param name="configurationManager">The configuration manager.</param>
  54. /// <param name="jsonSerializer">The json serializer.</param>
  55. /// <param name="httpClient">The HTTP client.</param>
  56. /// <param name="providerManager">The provider manager.</param>
  57. public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IProviderManager providerManager)
  58. : base(logManager, configurationManager)
  59. {
  60. JsonSerializer = jsonSerializer;
  61. HttpClient = httpClient;
  62. ProviderManager = providerManager;
  63. Current = this;
  64. }
  65. /// <summary>
  66. /// Releases unmanaged and - optionally - managed resources.
  67. /// </summary>
  68. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  69. protected virtual void Dispose(bool dispose)
  70. {
  71. if (dispose)
  72. {
  73. MovieDbResourcePool.Dispose();
  74. }
  75. }
  76. /// <summary>
  77. /// Gets the priority.
  78. /// </summary>
  79. /// <value>The priority.</value>
  80. public override MetadataProviderPriority Priority
  81. {
  82. get { return MetadataProviderPriority.Second; }
  83. }
  84. /// <summary>
  85. /// Supportses the specified item.
  86. /// </summary>
  87. /// <param name="item">The item.</param>
  88. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  89. public override bool Supports(BaseItem item)
  90. {
  91. return item is Movie || item is BoxSet;
  92. }
  93. /// <summary>
  94. /// Gets a value indicating whether [requires internet].
  95. /// </summary>
  96. /// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
  97. public override bool RequiresInternet
  98. {
  99. get
  100. {
  101. return true;
  102. }
  103. }
  104. /// <summary>
  105. /// If we save locally, refresh if they delete something
  106. /// </summary>
  107. protected override bool RefreshOnFileSystemStampChange
  108. {
  109. get
  110. {
  111. return ConfigurationManager.Configuration.SaveLocalMeta;
  112. }
  113. }
  114. /// <summary>
  115. /// The _TMDB settings task
  116. /// </summary>
  117. private Task<TmdbSettingsResult> _tmdbSettingsTask;
  118. /// <summary>
  119. /// The _TMDB settings task initialized
  120. /// </summary>
  121. private bool _tmdbSettingsTaskInitialized;
  122. /// <summary>
  123. /// The _TMDB settings task sync lock
  124. /// </summary>
  125. private object _tmdbSettingsTaskSyncLock = new object();
  126. /// <summary>
  127. /// Gets the TMDB settings.
  128. /// </summary>
  129. /// <value>The TMDB settings.</value>
  130. public Task<TmdbSettingsResult> TmdbSettings
  131. {
  132. get
  133. {
  134. LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, () => GetTmdbSettings(JsonSerializer, HttpClient));
  135. return _tmdbSettingsTask;
  136. }
  137. }
  138. /// <summary>
  139. /// Gets the TMDB settings.
  140. /// </summary>
  141. /// <returns>Task{TmdbSettingsResult}.</returns>
  142. private static async Task<TmdbSettingsResult> GetTmdbSettings(IJsonSerializer jsonSerializer, IHttpClient httpClient)
  143. {
  144. try
  145. {
  146. using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), Current.MovieDbResourcePool, CancellationToken.None).ConfigureAwait(false))
  147. {
  148. return jsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
  149. }
  150. }
  151. catch (HttpException)
  152. {
  153. return new TmdbSettingsResult
  154. {
  155. images = new TmdbImageSettings
  156. {
  157. backdrop_sizes =
  158. new List<string>
  159. {
  160. "w380",
  161. "w780",
  162. "w1280",
  163. "original"
  164. },
  165. poster_sizes =
  166. new List<string>
  167. {
  168. "w92",
  169. "w154",
  170. "w185",
  171. "w342",
  172. "w500",
  173. "original"
  174. },
  175. profile_sizes =
  176. new List<string>
  177. {
  178. "w45",
  179. "w185",
  180. "h632",
  181. "original"
  182. },
  183. base_url = "http://cf2.imgobject.com/t/p/"
  184. }
  185. };
  186. }
  187. }
  188. /// <summary>
  189. /// The json provider
  190. /// </summary>
  191. protected MovieProviderFromJson JsonProvider;
  192. /// <summary>
  193. /// Sets the persisted last refresh date on the item for this provider.
  194. /// </summary>
  195. /// <param name="item">The item.</param>
  196. /// <param name="value">The value.</param>
  197. /// <param name="providerVersion">The provider version.</param>
  198. /// <param name="status">The status.</param>
  199. public override void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
  200. {
  201. base.SetLastRefreshed(item, value, providerVersion, status);
  202. if (ConfigurationManager.Configuration.SaveLocalMeta)
  203. {
  204. //in addition to ours, we need to set the last refreshed time for the local data provider
  205. //so it won't see the new files we download and process them all over again
  206. if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(LogManager, ConfigurationManager, JsonSerializer, HttpClient, ProviderManager);
  207. var data = item.ProviderData.GetValueOrDefault(JsonProvider.Id, new BaseProviderInfo { ProviderId = JsonProvider.Id });
  208. data.LastRefreshed = value;
  209. item.ProviderData[JsonProvider.Id] = data;
  210. }
  211. }
  212. private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
  213. private const string Search3 = @"http://api.themoviedb.org/3/search/movie?api_key={1}&query={0}&language={2}";
  214. private const string AltTitleSearch = @"http://api.themoviedb.org/3/movie/{0}/alternative_titles?api_key={1}&country={2}";
  215. private const string GetInfo3 = @"http://api.themoviedb.org/3/{3}/{0}?api_key={1}&language={2}";
  216. private const string CastInfo = @"http://api.themoviedb.org/3/movie/{0}/casts?api_key={1}";
  217. private const string ReleaseInfo = @"http://api.themoviedb.org/3/movie/{0}/releases?api_key={1}";
  218. private const string GetImages = @"http://api.themoviedb.org/3/{2}/{0}/images?api_key={1}";
  219. public static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669";
  220. static readonly Regex[] NameMatches = new[] {
  221. new Regex(@"(?<name>.*)\((?<year>\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year
  222. new Regex(@"(?<name>.*)") // last resort matches the whole string as the name
  223. };
  224. public const string LOCAL_META_FILE_NAME = "MBMovie.json";
  225. public const string ALT_META_FILE_NAME = "movie.xml";
  226. protected string ItemType = "movie";
  227. protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
  228. {
  229. if (item.DontFetchMeta) return false;
  230. if (ConfigurationManager.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo))
  231. {
  232. //If they deleted something from file system, chances are, this item was mis-identified the first time
  233. item.SetProviderId(MetadataProviders.Tmdb, null);
  234. Logger.Debug("MovieProvider reports file system stamp change...");
  235. return true;
  236. }
  237. if (providerInfo.LastRefreshStatus == ProviderRefreshStatus.CompletedWithErrors)
  238. {
  239. Logger.Debug("MovieProvider for {0} - last attempt had errors. Will try again.", item.Path);
  240. return true;
  241. }
  242. var downloadDate = providerInfo.LastRefreshed;
  243. if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
  244. {
  245. return false;
  246. }
  247. if (DateTime.Today.Subtract(item.DateCreated).TotalDays > 180 && downloadDate != DateTime.MinValue)
  248. return false; // don't trigger a refresh data for item that are more than 6 months old and have been refreshed before
  249. if (DateTime.Today.Subtract(downloadDate).TotalDays < ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days
  250. return false;
  251. if (HasAltMeta(item))
  252. return false; //never refresh if has meta from other source
  253. Logger.Debug("MovieDbProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + ConfigurationManager.Configuration.MetadataRefreshDays);
  254. return true;
  255. }
  256. /// <summary>
  257. /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
  258. /// </summary>
  259. /// <param name="item">The item.</param>
  260. /// <param name="force">if set to <c>true</c> [force].</param>
  261. /// <param name="cancellationToken">The cancellation token</param>
  262. /// <returns>Task{System.Boolean}.</returns>
  263. public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
  264. {
  265. if (HasAltMeta(item))
  266. {
  267. Logger.Info("MovieDbProvider - Not fetching because 3rd party meta exists for " + item.Name);
  268. SetLastRefreshed(item, DateTime.UtcNow);
  269. return true;
  270. }
  271. if (item.DontFetchMeta)
  272. {
  273. Logger.Info("MovieDbProvider - Not fetching because requested to ignore " + item.Name);
  274. return false;
  275. }
  276. cancellationToken.ThrowIfCancellationRequested();
  277. if (!ConfigurationManager.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item)))
  278. {
  279. try
  280. {
  281. await FetchMovieData(item, cancellationToken).ConfigureAwait(false);
  282. SetLastRefreshed(item, DateTime.UtcNow);
  283. }
  284. catch (MovieDbProviderException)
  285. {
  286. SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.CompletedWithErrors);
  287. }
  288. return true;
  289. }
  290. Logger.Debug("MovieDBProvider not fetching because local meta exists for " + item.Name);
  291. SetLastRefreshed(item, DateTime.UtcNow);
  292. return true;
  293. }
  294. /// <summary>
  295. /// Determines whether [has local meta] [the specified item].
  296. /// </summary>
  297. /// <param name="item">The item.</param>
  298. /// <returns><c>true</c> if [has local meta] [the specified item]; otherwise, <c>false</c>.</returns>
  299. private bool HasLocalMeta(BaseItem item)
  300. {
  301. //need at least the xml and folder.jpg/png or a movie.xml put in by someone else
  302. return item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME);
  303. }
  304. /// <summary>
  305. /// Determines whether [has alt meta] [the specified item].
  306. /// </summary>
  307. /// <param name="item">The item.</param>
  308. /// <returns><c>true</c> if [has alt meta] [the specified item]; otherwise, <c>false</c>.</returns>
  309. private bool HasAltMeta(BaseItem item)
  310. {
  311. return item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME);
  312. }
  313. /// <summary>
  314. /// Fetches the movie data.
  315. /// </summary>
  316. /// <param name="item">The item.</param>
  317. /// <param name="cancellationToken"></param>
  318. /// <returns>Task.</returns>
  319. private async Task FetchMovieData(BaseItem item, CancellationToken cancellationToken)
  320. {
  321. string id = item.GetProviderId(MetadataProviders.Tmdb) ?? await FindId(item, item.ProductionYear, cancellationToken).ConfigureAwait(false);
  322. if (id != null)
  323. {
  324. Logger.Debug("MovieDbProvider - getting movie info with id: " + id);
  325. cancellationToken.ThrowIfCancellationRequested();
  326. await FetchMovieData(item, id, cancellationToken).ConfigureAwait(false);
  327. }
  328. else
  329. {
  330. Logger.Info("MovieDBProvider could not find " + item.Name + ". Check name on themoviedb.org.");
  331. }
  332. }
  333. /// <summary>
  334. /// Parses the name.
  335. /// </summary>
  336. /// <param name="name">The name.</param>
  337. /// <param name="justName">Name of the just.</param>
  338. /// <param name="year">The year.</param>
  339. protected void ParseName(string name, out string justName, out int? year)
  340. {
  341. justName = null;
  342. year = null;
  343. foreach (var re in NameMatches)
  344. {
  345. Match m = re.Match(name);
  346. if (m.Success)
  347. {
  348. justName = m.Groups["name"].Value.Trim();
  349. string y = m.Groups["year"] != null ? m.Groups["year"].Value : null;
  350. int temp;
  351. year = Int32.TryParse(y, out temp) ? temp : (int?)null;
  352. break;
  353. }
  354. }
  355. }
  356. /// <summary>
  357. /// Finds the id.
  358. /// </summary>
  359. /// <param name="item">The item.</param>
  360. /// <param name="productionYear">The production year.</param>
  361. /// <param name="cancellationToken">The cancellation token</param>
  362. /// <returns>Task{System.String}.</returns>
  363. public async Task<string> FindId(BaseItem item, int? productionYear, CancellationToken cancellationToken)
  364. {
  365. string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty;
  366. var id = justName.GetAttributeValue("tmdbid");
  367. if (id != null)
  368. {
  369. Logger.Debug("Using tmdb id specified in path.");
  370. return id;
  371. }
  372. int? year;
  373. string name = item.Name;
  374. ParseName(name, out name, out year);
  375. if (year == null && productionYear != null)
  376. {
  377. year = productionYear;
  378. }
  379. Logger.Info("MovieDbProvider: Finding id for movie: " + name);
  380. string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
  381. //if we are a boxset - look at our first child
  382. var boxset = item as BoxSet;
  383. if (boxset != null)
  384. {
  385. if (!boxset.Children.IsEmpty)
  386. {
  387. var firstChild = boxset.Children.First();
  388. Logger.Debug("MovieDbProvider - Attempting to find boxset ID from: " + firstChild.Name);
  389. string childName;
  390. int? childYear;
  391. ParseName(firstChild.Name, out childName, out childYear);
  392. id = await GetBoxsetIdFromMovie(childName, childYear, language, cancellationToken).ConfigureAwait(false);
  393. if (id != null)
  394. {
  395. Logger.Info("MovieDbProvider - Found Boxset ID: " + id);
  396. }
  397. }
  398. return id;
  399. }
  400. //nope - search for it
  401. id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
  402. if (id == null)
  403. {
  404. //try in english if wasn't before
  405. if (language != "en")
  406. {
  407. id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
  408. }
  409. else
  410. {
  411. // try with dot and _ turned to space
  412. name = name.Replace(",", " ");
  413. name = name.Replace(".", " ");
  414. name = name.Replace(" ", " ");
  415. name = name.Replace("_", " ");
  416. name = name.Replace("-", "");
  417. id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
  418. if (id == null && language != "en")
  419. {
  420. //one more time, in english
  421. id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
  422. }
  423. if (id == null)
  424. {
  425. //last resort - try using the actual folder name
  426. id = await AttemptFindId(Path.GetFileName(item.ResolveArgs.Path), year, "en", cancellationToken).ConfigureAwait(false);
  427. }
  428. }
  429. }
  430. return id;
  431. }
  432. /// <summary>
  433. /// Attempts the find id.
  434. /// </summary>
  435. /// <param name="name">The name.</param>
  436. /// <param name="year">The year.</param>
  437. /// <param name="language">The language.</param>
  438. /// <param name="cancellationToken">The cancellation token</param>
  439. /// <returns>Task{System.String}.</returns>
  440. public virtual async Task<string> AttemptFindId(string name, int? year, string language, CancellationToken cancellationToken)
  441. {
  442. string url3 = string.Format(Search3, UrlEncode(name), ApiKey, language);
  443. TmdbMovieSearchResults searchResult = null;
  444. try
  445. {
  446. using (Stream json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  447. {
  448. searchResult = JsonSerializer.DeserializeFromStream<TmdbMovieSearchResults>(json);
  449. }
  450. }
  451. catch (HttpException)
  452. {
  453. }
  454. if (searchResult == null || searchResult.results.Count == 0)
  455. {
  456. //try replacing numbers
  457. foreach (var pair in ReplaceStartNumbers)
  458. {
  459. if (name.StartsWith(pair.Key))
  460. {
  461. name = name.Remove(0, pair.Key.Length);
  462. name = pair.Value + name;
  463. }
  464. }
  465. foreach (var pair in ReplaceEndNumbers)
  466. {
  467. if (name.EndsWith(pair.Key))
  468. {
  469. name = name.Remove(name.IndexOf(pair.Key), pair.Key.Length);
  470. name = name + pair.Value;
  471. }
  472. }
  473. Logger.Info("MovieDBProvider - No results. Trying replacement numbers: " + name);
  474. url3 = string.Format(Search3, UrlEncode(name), ApiKey, language);
  475. try
  476. {
  477. using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  478. {
  479. searchResult = JsonSerializer.DeserializeFromStream<TmdbMovieSearchResults>(json);
  480. }
  481. }
  482. catch (HttpException)
  483. {
  484. }
  485. }
  486. if (searchResult != null)
  487. {
  488. string compName = GetComparableName(name, Logger);
  489. foreach (var possible in searchResult.results)
  490. {
  491. string matchedName = null;
  492. string id = possible.id.ToString();
  493. string n = possible.title;
  494. if (GetComparableName(n, Logger) == compName)
  495. {
  496. matchedName = n;
  497. }
  498. else
  499. {
  500. n = possible.original_title;
  501. if (GetComparableName(n, Logger) == compName)
  502. {
  503. matchedName = n;
  504. }
  505. }
  506. Logger.Debug("MovieDbProvider - " + compName + " didn't match " + n);
  507. //if main title matches we don't have to look for alternatives
  508. if (matchedName == null)
  509. {
  510. //that title didn't match - look for alternatives
  511. url3 = string.Format(AltTitleSearch, id, ApiKey, ConfigurationManager.Configuration.MetadataCountryCode);
  512. try
  513. {
  514. using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  515. {
  516. var response = JsonSerializer.DeserializeFromStream<TmdbAltTitleResults>(json);
  517. if (response != null && response.titles != null)
  518. {
  519. foreach (var title in response.titles)
  520. {
  521. var t = GetComparableName(title.title, Logger);
  522. if (t == compName)
  523. {
  524. Logger.Debug("MovieDbProvider - " + compName +
  525. " matched " + t);
  526. matchedName = t;
  527. break;
  528. }
  529. Logger.Debug("MovieDbProvider - " + compName +
  530. " did not match " + t);
  531. }
  532. }
  533. }
  534. }
  535. catch (HttpException)
  536. {
  537. }
  538. }
  539. if (matchedName != null)
  540. {
  541. Logger.Debug("Match " + matchedName + " for " + name);
  542. if (year != null)
  543. {
  544. DateTime r;
  545. if (DateTime.TryParse(possible.release_date, out r))
  546. {
  547. if (Math.Abs(r.Year - year.Value) > 1) // allow a 1 year tolerance on release date
  548. {
  549. Logger.Debug("Result " + matchedName + " released on " + r + " did not match year " + year);
  550. continue;
  551. }
  552. }
  553. }
  554. //matched name and year
  555. return id;
  556. }
  557. }
  558. }
  559. return null;
  560. }
  561. /// <summary>
  562. /// URLs the encode.
  563. /// </summary>
  564. /// <param name="name">The name.</param>
  565. /// <returns>System.String.</returns>
  566. private static string UrlEncode(string name)
  567. {
  568. return WebUtility.UrlEncode(name);
  569. }
  570. /// <summary>
  571. /// Gets the boxset id from movie.
  572. /// </summary>
  573. /// <param name="name">The name.</param>
  574. /// <param name="year">The year.</param>
  575. /// <param name="language">The language.</param>
  576. /// <param name="cancellationToken">The cancellation token</param>
  577. /// <returns>Task{System.String}.</returns>
  578. protected async Task<string> GetBoxsetIdFromMovie(string name, int? year, string language, CancellationToken cancellationToken)
  579. {
  580. string id = null;
  581. string childId = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
  582. if (childId != null)
  583. {
  584. string url = string.Format(GetInfo3, childId, ApiKey, language, ItemType);
  585. try
  586. {
  587. using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  588. {
  589. var movieResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
  590. if (movieResult != null && movieResult.belongs_to_collection != null)
  591. {
  592. id = movieResult.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture);
  593. }
  594. else
  595. {
  596. Logger.Error("Unable to obtain boxset id.");
  597. }
  598. }
  599. }
  600. catch (HttpException)
  601. {
  602. }
  603. }
  604. return id;
  605. }
  606. /// <summary>
  607. /// Fetches the movie data.
  608. /// </summary>
  609. /// <param name="item">The item.</param>
  610. /// <param name="id">The id.</param>
  611. /// <param name="cancellationToken">The cancellation token</param>
  612. /// <returns>Task.</returns>
  613. protected async Task FetchMovieData(BaseItem item, string id, CancellationToken cancellationToken)
  614. {
  615. cancellationToken.ThrowIfCancellationRequested();
  616. if (String.IsNullOrEmpty(id))
  617. {
  618. Logger.Info("MoviedbProvider: Ignoring " + item.Name + " because ID forced blank.");
  619. return;
  620. }
  621. if (item.GetProviderId(MetadataProviders.Tmdb) == null) item.SetProviderId(MetadataProviders.Tmdb, id);
  622. var mainTask = FetchMainResult(item, id, cancellationToken);
  623. var castTask = FetchCastInfo(item, id, cancellationToken);
  624. var releaseTask = FetchReleaseInfo(item, id, cancellationToken);
  625. var imageTask = FetchImageInfo(item, id, cancellationToken);
  626. await Task.WhenAll(mainTask, castTask, releaseTask).ConfigureAwait(false);
  627. cancellationToken.ThrowIfCancellationRequested();
  628. var mainResult = mainTask.Result;
  629. if (mainResult == null) return;
  630. if (castTask.Result != null)
  631. {
  632. mainResult.cast = castTask.Result.cast;
  633. mainResult.crew = castTask.Result.crew;
  634. }
  635. if (releaseTask.Result != null)
  636. {
  637. mainResult.countries = releaseTask.Result.countries;
  638. }
  639. ProcessMainInfo(item, mainResult);
  640. await Task.WhenAll(imageTask).ConfigureAwait(false);
  641. cancellationToken.ThrowIfCancellationRequested();
  642. if (imageTask.Result != null)
  643. {
  644. await ProcessImages(item, imageTask.Result, cancellationToken).ConfigureAwait(false);
  645. }
  646. //and save locally
  647. if (ConfigurationManager.Configuration.SaveLocalMeta)
  648. {
  649. var ms = new MemoryStream();
  650. JsonSerializer.SerializeToStream(mainResult, ms);
  651. cancellationToken.ThrowIfCancellationRequested();
  652. await ProviderManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
  653. }
  654. }
  655. /// <summary>
  656. /// Fetches the main result.
  657. /// </summary>
  658. /// <param name="item">The item.</param>
  659. /// <param name="id">The id.</param>
  660. /// <param name="cancellationToken">The cancellation token</param>
  661. /// <returns>Task{CompleteMovieData}.</returns>
  662. protected async Task<CompleteMovieData> FetchMainResult(BaseItem item, string id, CancellationToken cancellationToken)
  663. {
  664. ItemType = item is BoxSet ? "collection" : "movie";
  665. string url = string.Format(GetInfo3, id, ApiKey, ConfigurationManager.Configuration.PreferredMetadataLanguage, ItemType);
  666. CompleteMovieData mainResult;
  667. cancellationToken.ThrowIfCancellationRequested();
  668. try
  669. {
  670. using (var json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  671. {
  672. mainResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
  673. }
  674. }
  675. catch (HttpException e)
  676. {
  677. if (e.IsTimedOut)
  678. {
  679. Logger.ErrorException("MovieDbProvider timed out attempting to retrieve main info for {0}", e, item.Path);
  680. throw new MovieDbProviderException("Timed out on main info");
  681. }
  682. if (e.StatusCode == HttpStatusCode.NotFound)
  683. {
  684. Logger.ErrorException("MovieDbProvider not found error attempting to retrieve main info for {0}", e, item.Path);
  685. throw new MovieDbProviderException("Not Found");
  686. }
  687. throw;
  688. }
  689. cancellationToken.ThrowIfCancellationRequested();
  690. if (mainResult != null && string.IsNullOrEmpty(mainResult.overview))
  691. {
  692. if (ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower() != "en")
  693. {
  694. Logger.Info("MovieDbProvider couldn't find meta for language " + ConfigurationManager.Configuration.PreferredMetadataLanguage + ". Trying English...");
  695. url = string.Format(GetInfo3, id, ApiKey, "en", ItemType);
  696. try
  697. {
  698. using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  699. {
  700. mainResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
  701. }
  702. }
  703. catch (HttpException)
  704. {
  705. }
  706. if (String.IsNullOrEmpty(mainResult.overview))
  707. {
  708. Logger.Error("MovieDbProvider - Unable to find information for " + item.Name + " (id:" + id + ")");
  709. return null;
  710. }
  711. }
  712. }
  713. return mainResult;
  714. }
  715. /// <summary>
  716. /// Fetches the cast info.
  717. /// </summary>
  718. /// <param name="item">The item.</param>
  719. /// <param name="id">The id.</param>
  720. /// <param name="cancellationToken">The cancellation token</param>
  721. /// <returns>Task{TmdbCastResult}.</returns>
  722. protected async Task<TmdbCastResult> FetchCastInfo(BaseItem item, string id, CancellationToken cancellationToken)
  723. {
  724. //get cast and crew info
  725. var url = string.Format(CastInfo, id, ApiKey);
  726. TmdbCastResult cast = null;
  727. cancellationToken.ThrowIfCancellationRequested();
  728. try
  729. {
  730. using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  731. {
  732. cast = JsonSerializer.DeserializeFromStream<TmdbCastResult>(json);
  733. }
  734. }
  735. catch (HttpException)
  736. {
  737. }
  738. return cast;
  739. }
  740. /// <summary>
  741. /// Fetches the release info.
  742. /// </summary>
  743. /// <param name="item">The item.</param>
  744. /// <param name="id">The id.</param>
  745. /// <param name="cancellationToken">The cancellation token</param>
  746. /// <returns>Task{TmdbReleasesResult}.</returns>
  747. protected async Task<TmdbReleasesResult> FetchReleaseInfo(BaseItem item, string id, CancellationToken cancellationToken)
  748. {
  749. var url = string.Format(ReleaseInfo, id, ApiKey);
  750. TmdbReleasesResult releases = null;
  751. cancellationToken.ThrowIfCancellationRequested();
  752. try
  753. {
  754. using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  755. {
  756. releases = JsonSerializer.DeserializeFromStream<TmdbReleasesResult>(json);
  757. }
  758. }
  759. catch (HttpException)
  760. {
  761. }
  762. return releases;
  763. }
  764. /// <summary>
  765. /// Fetches the image info.
  766. /// </summary>
  767. /// <param name="item">The item.</param>
  768. /// <param name="id">The id.</param>
  769. /// <param name="cancellationToken">The cancellation token</param>
  770. /// <returns>Task{TmdbImages}.</returns>
  771. protected async Task<TmdbImages> FetchImageInfo(BaseItem item, string id, CancellationToken cancellationToken)
  772. {
  773. //fetch images
  774. var url = string.Format(GetImages, id, ApiKey, ItemType);
  775. TmdbImages images = null;
  776. cancellationToken.ThrowIfCancellationRequested();
  777. try
  778. {
  779. using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
  780. {
  781. images = JsonSerializer.DeserializeFromStream<TmdbImages>(json);
  782. }
  783. }
  784. catch (HttpException)
  785. {
  786. }
  787. return images;
  788. }
  789. /// <summary>
  790. /// Processes the main info.
  791. /// </summary>
  792. /// <param name="movie">The movie.</param>
  793. /// <param name="movieData">The movie data.</param>
  794. protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
  795. {
  796. if (movie != null && movieData != null)
  797. {
  798. movie.Name = movieData.title ?? movieData.original_title ?? movie.Name;
  799. movie.Overview = movieData.overview;
  800. movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null;
  801. movie.HomePageUrl = movieData.homepage;
  802. movie.Budget = movieData.budget;
  803. if (!string.IsNullOrEmpty(movieData.tagline)) movie.AddTagline(movieData.tagline);
  804. movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id);
  805. float rating;
  806. string voteAvg = movieData.vote_average.ToString();
  807. string cultureStr = ConfigurationManager.Configuration.PreferredMetadataLanguage + "-" + ConfigurationManager.Configuration.MetadataCountryCode;
  808. CultureInfo culture;
  809. try
  810. {
  811. culture = new CultureInfo(cultureStr);
  812. }
  813. catch
  814. {
  815. culture = CultureInfo.CurrentCulture; //default to windows settings if other was invalid
  816. }
  817. Logger.Debug("Culture for numeric conversion is: " + culture.Name);
  818. if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, culture, out rating))
  819. movie.CommunityRating = rating;
  820. //release date and certification are retrieved based on configured country and we fall back on US if not there
  821. if (movieData.countries != null)
  822. {
  823. var ourRelease = movieData.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country();
  824. var usRelease = movieData.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country();
  825. movie.OfficialRating = ourRelease.certification ?? usRelease.certification;
  826. if (ourRelease.release_date > new DateTime(1900, 1, 1))
  827. {
  828. movie.PremiereDate = ourRelease.release_date;
  829. movie.ProductionYear = ourRelease.release_date.Year;
  830. }
  831. else
  832. {
  833. movie.PremiereDate = usRelease.release_date;
  834. movie.ProductionYear = usRelease.release_date.Year;
  835. }
  836. }
  837. else
  838. {
  839. //no specific country release info at all
  840. movie.PremiereDate = movieData.release_date;
  841. movie.ProductionYear = movieData.release_date.Year;
  842. }
  843. //if that didn't find a rating and we are a boxset, use the one from our first child
  844. if (movie.OfficialRating == null && movie is BoxSet)
  845. {
  846. var boxset = movie as BoxSet;
  847. Logger.Info("MovieDbProvider - Using rating of first child of boxset...");
  848. boxset.OfficialRating = !boxset.Children.IsEmpty ? boxset.Children.First().OfficialRating : null;
  849. }
  850. if (movie.RunTimeTicks == null && movieData.runtime > 0)
  851. movie.RunTimeTicks = TimeSpan.FromMinutes(movieData.runtime).Ticks;
  852. //studios
  853. if (movieData.production_companies != null)
  854. {
  855. //always clear so they don't double up
  856. movie.AddStudios(movieData.production_companies.Select(c => c.name));
  857. }
  858. //genres
  859. if (movieData.genres != null)
  860. {
  861. movie.AddGenres(movieData.genres.Select(g => g.name));
  862. }
  863. //Actors, Directors, Writers - all in People
  864. //actors come from cast
  865. if (movieData.cast != null)
  866. {
  867. foreach (var actor in movieData.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name, Role = actor.character, Type = PersonType.Actor });
  868. }
  869. //and the rest from crew
  870. if (movieData.crew != null)
  871. {
  872. foreach (var person in movieData.crew) movie.AddPerson(new PersonInfo { Name = person.name, Role = person.job, Type = person.department });
  873. }
  874. }
  875. }
  876. /// <summary>
  877. /// Processes the images.
  878. /// </summary>
  879. /// <param name="item">The item.</param>
  880. /// <param name="images">The images.</param>
  881. /// <param name="cancellationToken">The cancellation token</param>
  882. /// <returns>Task.</returns>
  883. protected virtual async Task ProcessImages(BaseItem item, TmdbImages images, CancellationToken cancellationToken)
  884. {
  885. cancellationToken.ThrowIfCancellationRequested();
  886. // poster
  887. if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage("folder")))
  888. {
  889. var tmdbSettings = await TmdbSettings.ConfigureAwait(false);
  890. var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize;
  891. // get highest rated poster for our language
  892. var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average);
  893. var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase));
  894. if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en"))
  895. {
  896. // couldn't find our specific language, find english (if that wasn't our language)
  897. poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase));
  898. }
  899. if (poster == null)
  900. {
  901. //still couldn't find it - try highest rated null one
  902. poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 == null);
  903. }
  904. if (poster == null)
  905. {
  906. //finally - just get the highest rated one
  907. poster = postersSortedByVote.FirstOrDefault();
  908. }
  909. if (poster != null)
  910. {
  911. try
  912. {
  913. item.PrimaryImagePath = await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
  914. }
  915. catch (HttpException)
  916. {
  917. }
  918. catch (IOException)
  919. {
  920. }
  921. }
  922. }
  923. cancellationToken.ThrowIfCancellationRequested();
  924. // backdrops
  925. if (images.backdrops != null && images.backdrops.Count > 0)
  926. {
  927. item.BackdropImagePaths = new List<string>();
  928. var tmdbSettings = await TmdbSettings.ConfigureAwait(false);
  929. var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize;
  930. //backdrops should be in order of rating. get first n ones
  931. var numToFetch = Math.Min(ConfigurationManager.Configuration.MaxBackdrops, images.backdrops.Count);
  932. for (var i = 0; i < numToFetch; i++)
  933. {
  934. var bdName = "backdrop" + (i == 0 ? "" : i.ToString());
  935. if (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage(bdName))
  936. {
  937. try
  938. {
  939. item.BackdropImagePaths.Add(await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
  940. }
  941. catch (HttpException)
  942. {
  943. }
  944. catch (IOException)
  945. {
  946. }
  947. }
  948. }
  949. }
  950. }
  951. /// <summary>
  952. /// The remove
  953. /// </summary>
  954. const string remove = "\"'!`?";
  955. // "Face/Off" support.
  956. /// <summary>
  957. /// The spacers
  958. /// </summary>
  959. const string spacers = "/,.:;\\(){}[]+-_=–*"; // (there are not actually two - in the they are different char codes)
  960. /// <summary>
  961. /// The replace start numbers
  962. /// </summary>
  963. static readonly Dictionary<string, string> ReplaceStartNumbers = new Dictionary<string, string> {
  964. {"1 ","one "},
  965. {"2 ","two "},
  966. {"3 ","three "},
  967. {"4 ","four "},
  968. {"5 ","five "},
  969. {"6 ","six "},
  970. {"7 ","seven "},
  971. {"8 ","eight "},
  972. {"9 ","nine "},
  973. {"10 ","ten "},
  974. {"11 ","eleven "},
  975. {"12 ","twelve "},
  976. {"13 ","thirteen "},
  977. {"100 ","one hundred "},
  978. {"101 ","one hundred one "}
  979. };
  980. /// <summary>
  981. /// The replace end numbers
  982. /// </summary>
  983. static readonly Dictionary<string, string> ReplaceEndNumbers = new Dictionary<string, string> {
  984. {" 1"," i"},
  985. {" 2"," ii"},
  986. {" 3"," iii"},
  987. {" 4"," iv"},
  988. {" 5"," v"},
  989. {" 6"," vi"},
  990. {" 7"," vii"},
  991. {" 8"," viii"},
  992. {" 9"," ix"},
  993. {" 10"," x"}
  994. };
  995. /// <summary>
  996. /// Gets the name of the comparable.
  997. /// </summary>
  998. /// <param name="name">The name.</param>
  999. /// <param name="logger">The logger.</param>
  1000. /// <returns>System.String.</returns>
  1001. internal static string GetComparableName(string name, ILogger logger)
  1002. {
  1003. name = name.ToLower();
  1004. name = name.Replace("á", "a");
  1005. name = name.Replace("é", "e");
  1006. name = name.Replace("í", "i");
  1007. name = name.Replace("ó", "o");
  1008. name = name.Replace("ú", "u");
  1009. name = name.Replace("ü", "u");
  1010. name = name.Replace("ñ", "n");
  1011. foreach (var pair in ReplaceStartNumbers)
  1012. {
  1013. if (name.StartsWith(pair.Key))
  1014. {
  1015. name = name.Remove(0, pair.Key.Length);
  1016. name = pair.Value + name;
  1017. logger.Info("MovieDbProvider - Replaced Start Numbers: " + name);
  1018. }
  1019. }
  1020. foreach (var pair in ReplaceEndNumbers)
  1021. {
  1022. if (name.EndsWith(pair.Key))
  1023. {
  1024. name = name.Remove(name.IndexOf(pair.Key), pair.Key.Length);
  1025. name = name + pair.Value;
  1026. logger.Info("MovieDbProvider - Replaced End Numbers: " + name);
  1027. }
  1028. }
  1029. name = name.Normalize(NormalizationForm.FormKD);
  1030. var sb = new StringBuilder();
  1031. foreach (var c in name)
  1032. {
  1033. if (c >= 0x2B0 && c <= 0x0333)
  1034. {
  1035. // skip char modifier and diacritics
  1036. }
  1037. else if (remove.IndexOf(c) > -1)
  1038. {
  1039. // skip chars we are removing
  1040. }
  1041. else if (spacers.IndexOf(c) > -1)
  1042. {
  1043. sb.Append(" ");
  1044. }
  1045. else if (c == '&')
  1046. {
  1047. sb.Append(" and ");
  1048. }
  1049. else
  1050. {
  1051. sb.Append(c);
  1052. }
  1053. }
  1054. name = sb.ToString();
  1055. name = name.Replace(", the", "");
  1056. name = name.Replace(" the ", " ");
  1057. name = name.Replace("the ", "");
  1058. string prev_name;
  1059. do
  1060. {
  1061. prev_name = name;
  1062. name = name.Replace(" ", " ");
  1063. } while (name.Length != prev_name.Length);
  1064. return name.Trim();
  1065. }
  1066. #region Result Objects
  1067. /// <summary>
  1068. /// Class TmdbMovieSearchResult
  1069. /// </summary>
  1070. protected class TmdbMovieSearchResult
  1071. {
  1072. /// <summary>
  1073. /// Gets or sets a value indicating whether this <see cref="TmdbMovieSearchResult" /> is adult.
  1074. /// </summary>
  1075. /// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
  1076. public bool adult { get; set; }
  1077. /// <summary>
  1078. /// Gets or sets the backdrop_path.
  1079. /// </summary>
  1080. /// <value>The backdrop_path.</value>
  1081. public string backdrop_path { get; set; }
  1082. /// <summary>
  1083. /// Gets or sets the id.
  1084. /// </summary>
  1085. /// <value>The id.</value>
  1086. public int id { get; set; }
  1087. /// <summary>
  1088. /// Gets or sets the original_title.
  1089. /// </summary>
  1090. /// <value>The original_title.</value>
  1091. public string original_title { get; set; }
  1092. /// <summary>
  1093. /// Gets or sets the release_date.
  1094. /// </summary>
  1095. /// <value>The release_date.</value>
  1096. public string release_date { get; set; }
  1097. /// <summary>
  1098. /// Gets or sets the poster_path.
  1099. /// </summary>
  1100. /// <value>The poster_path.</value>
  1101. public string poster_path { get; set; }
  1102. /// <summary>
  1103. /// Gets or sets the popularity.
  1104. /// </summary>
  1105. /// <value>The popularity.</value>
  1106. public double popularity { get; set; }
  1107. /// <summary>
  1108. /// Gets or sets the title.
  1109. /// </summary>
  1110. /// <value>The title.</value>
  1111. public string title { get; set; }
  1112. /// <summary>
  1113. /// Gets or sets the vote_average.
  1114. /// </summary>
  1115. /// <value>The vote_average.</value>
  1116. public double vote_average { get; set; }
  1117. /// <summary>
  1118. /// Gets or sets the vote_count.
  1119. /// </summary>
  1120. /// <value>The vote_count.</value>
  1121. public int vote_count { get; set; }
  1122. }
  1123. /// <summary>
  1124. /// Class TmdbMovieSearchResults
  1125. /// </summary>
  1126. protected class TmdbMovieSearchResults
  1127. {
  1128. /// <summary>
  1129. /// Gets or sets the page.
  1130. /// </summary>
  1131. /// <value>The page.</value>
  1132. public int page { get; set; }
  1133. /// <summary>
  1134. /// Gets or sets the results.
  1135. /// </summary>
  1136. /// <value>The results.</value>
  1137. public List<TmdbMovieSearchResult> results { get; set; }
  1138. /// <summary>
  1139. /// Gets or sets the total_pages.
  1140. /// </summary>
  1141. /// <value>The total_pages.</value>
  1142. public int total_pages { get; set; }
  1143. /// <summary>
  1144. /// Gets or sets the total_results.
  1145. /// </summary>
  1146. /// <value>The total_results.</value>
  1147. public int total_results { get; set; }
  1148. }
  1149. /// <summary>
  1150. /// Class BelongsToCollection
  1151. /// </summary>
  1152. protected class BelongsToCollection
  1153. {
  1154. /// <summary>
  1155. /// Gets or sets the id.
  1156. /// </summary>
  1157. /// <value>The id.</value>
  1158. public int id { get; set; }
  1159. /// <summary>
  1160. /// Gets or sets the name.
  1161. /// </summary>
  1162. /// <value>The name.</value>
  1163. public string name { get; set; }
  1164. /// <summary>
  1165. /// Gets or sets the poster_path.
  1166. /// </summary>
  1167. /// <value>The poster_path.</value>
  1168. public string poster_path { get; set; }
  1169. /// <summary>
  1170. /// Gets or sets the backdrop_path.
  1171. /// </summary>
  1172. /// <value>The backdrop_path.</value>
  1173. public string backdrop_path { get; set; }
  1174. }
  1175. /// <summary>
  1176. /// Class Genre
  1177. /// </summary>
  1178. protected class Genre
  1179. {
  1180. /// <summary>
  1181. /// Gets or sets the id.
  1182. /// </summary>
  1183. /// <value>The id.</value>
  1184. public int id { get; set; }
  1185. /// <summary>
  1186. /// Gets or sets the name.
  1187. /// </summary>
  1188. /// <value>The name.</value>
  1189. public string name { get; set; }
  1190. }
  1191. /// <summary>
  1192. /// Class ProductionCompany
  1193. /// </summary>
  1194. protected class ProductionCompany
  1195. {
  1196. /// <summary>
  1197. /// Gets or sets the name.
  1198. /// </summary>
  1199. /// <value>The name.</value>
  1200. public string name { get; set; }
  1201. /// <summary>
  1202. /// Gets or sets the id.
  1203. /// </summary>
  1204. /// <value>The id.</value>
  1205. public int id { get; set; }
  1206. }
  1207. /// <summary>
  1208. /// Class ProductionCountry
  1209. /// </summary>
  1210. protected class ProductionCountry
  1211. {
  1212. /// <summary>
  1213. /// Gets or sets the iso_3166_1.
  1214. /// </summary>
  1215. /// <value>The iso_3166_1.</value>
  1216. public string iso_3166_1 { get; set; }
  1217. /// <summary>
  1218. /// Gets or sets the name.
  1219. /// </summary>
  1220. /// <value>The name.</value>
  1221. public string name { get; set; }
  1222. }
  1223. /// <summary>
  1224. /// Class SpokenLanguage
  1225. /// </summary>
  1226. protected class SpokenLanguage
  1227. {
  1228. /// <summary>
  1229. /// Gets or sets the iso_639_1.
  1230. /// </summary>
  1231. /// <value>The iso_639_1.</value>
  1232. public string iso_639_1 { get; set; }
  1233. /// <summary>
  1234. /// Gets or sets the name.
  1235. /// </summary>
  1236. /// <value>The name.</value>
  1237. public string name { get; set; }
  1238. }
  1239. /// <summary>
  1240. /// Class Cast
  1241. /// </summary>
  1242. protected class Cast
  1243. {
  1244. /// <summary>
  1245. /// Gets or sets the id.
  1246. /// </summary>
  1247. /// <value>The id.</value>
  1248. public int id { get; set; }
  1249. /// <summary>
  1250. /// Gets or sets the name.
  1251. /// </summary>
  1252. /// <value>The name.</value>
  1253. public string name { get; set; }
  1254. /// <summary>
  1255. /// Gets or sets the character.
  1256. /// </summary>
  1257. /// <value>The character.</value>
  1258. public string character { get; set; }
  1259. /// <summary>
  1260. /// Gets or sets the order.
  1261. /// </summary>
  1262. /// <value>The order.</value>
  1263. public int order { get; set; }
  1264. /// <summary>
  1265. /// Gets or sets the profile_path.
  1266. /// </summary>
  1267. /// <value>The profile_path.</value>
  1268. public string profile_path { get; set; }
  1269. }
  1270. /// <summary>
  1271. /// Class Crew
  1272. /// </summary>
  1273. protected class Crew
  1274. {
  1275. /// <summary>
  1276. /// Gets or sets the id.
  1277. /// </summary>
  1278. /// <value>The id.</value>
  1279. public int id { get; set; }
  1280. /// <summary>
  1281. /// Gets or sets the name.
  1282. /// </summary>
  1283. /// <value>The name.</value>
  1284. public string name { get; set; }
  1285. /// <summary>
  1286. /// Gets or sets the department.
  1287. /// </summary>
  1288. /// <value>The department.</value>
  1289. public string department { get; set; }
  1290. /// <summary>
  1291. /// Gets or sets the job.
  1292. /// </summary>
  1293. /// <value>The job.</value>
  1294. public string job { get; set; }
  1295. /// <summary>
  1296. /// Gets or sets the profile_path.
  1297. /// </summary>
  1298. /// <value>The profile_path.</value>
  1299. public object profile_path { get; set; }
  1300. }
  1301. /// <summary>
  1302. /// Class Country
  1303. /// </summary>
  1304. protected class Country
  1305. {
  1306. /// <summary>
  1307. /// Gets or sets the iso_3166_1.
  1308. /// </summary>
  1309. /// <value>The iso_3166_1.</value>
  1310. public string iso_3166_1 { get; set; }
  1311. /// <summary>
  1312. /// Gets or sets the certification.
  1313. /// </summary>
  1314. /// <value>The certification.</value>
  1315. public string certification { get; set; }
  1316. /// <summary>
  1317. /// Gets or sets the release_date.
  1318. /// </summary>
  1319. /// <value>The release_date.</value>
  1320. public DateTime release_date { get; set; }
  1321. }
  1322. //protected class TmdbMovieResult
  1323. //{
  1324. // public bool adult { get; set; }
  1325. // public string backdrop_path { get; set; }
  1326. // public int belongs_to_collection { get; set; }
  1327. // public int budget { get; set; }
  1328. // public List<Genre> genres { get; set; }
  1329. // public string homepage { get; set; }
  1330. // public int id { get; set; }
  1331. // public string imdb_id { get; set; }
  1332. // public string original_title { get; set; }
  1333. // public string overview { get; set; }
  1334. // public double popularity { get; set; }
  1335. // public string poster_path { get; set; }
  1336. // public List<ProductionCompany> production_companies { get; set; }
  1337. // public List<ProductionCountry> production_countries { get; set; }
  1338. // public string release_date { get; set; }
  1339. // public int revenue { get; set; }
  1340. // public int runtime { get; set; }
  1341. // public List<SpokenLanguage> spoken_languages { get; set; }
  1342. // public string tagline { get; set; }
  1343. // public string title { get; set; }
  1344. // public double vote_average { get; set; }
  1345. // public int vote_count { get; set; }
  1346. //}
  1347. /// <summary>
  1348. /// Class TmdbTitle
  1349. /// </summary>
  1350. protected class TmdbTitle
  1351. {
  1352. /// <summary>
  1353. /// Gets or sets the iso_3166_1.
  1354. /// </summary>
  1355. /// <value>The iso_3166_1.</value>
  1356. public string iso_3166_1 { get; set; }
  1357. /// <summary>
  1358. /// Gets or sets the title.
  1359. /// </summary>
  1360. /// <value>The title.</value>
  1361. public string title { get; set; }
  1362. }
  1363. /// <summary>
  1364. /// Class TmdbAltTitleResults
  1365. /// </summary>
  1366. protected class TmdbAltTitleResults
  1367. {
  1368. /// <summary>
  1369. /// Gets or sets the id.
  1370. /// </summary>
  1371. /// <value>The id.</value>
  1372. public int id { get; set; }
  1373. /// <summary>
  1374. /// Gets or sets the titles.
  1375. /// </summary>
  1376. /// <value>The titles.</value>
  1377. public List<TmdbTitle> titles { get; set; }
  1378. }
  1379. /// <summary>
  1380. /// Class TmdbCastResult
  1381. /// </summary>
  1382. protected class TmdbCastResult
  1383. {
  1384. /// <summary>
  1385. /// Gets or sets the id.
  1386. /// </summary>
  1387. /// <value>The id.</value>
  1388. public int id { get; set; }
  1389. /// <summary>
  1390. /// Gets or sets the cast.
  1391. /// </summary>
  1392. /// <value>The cast.</value>
  1393. public List<Cast> cast { get; set; }
  1394. /// <summary>
  1395. /// Gets or sets the crew.
  1396. /// </summary>
  1397. /// <value>The crew.</value>
  1398. public List<Crew> crew { get; set; }
  1399. }
  1400. /// <summary>
  1401. /// Class TmdbReleasesResult
  1402. /// </summary>
  1403. protected class TmdbReleasesResult
  1404. {
  1405. /// <summary>
  1406. /// Gets or sets the id.
  1407. /// </summary>
  1408. /// <value>The id.</value>
  1409. public int id { get; set; }
  1410. /// <summary>
  1411. /// Gets or sets the countries.
  1412. /// </summary>
  1413. /// <value>The countries.</value>
  1414. public List<Country> countries { get; set; }
  1415. }
  1416. /// <summary>
  1417. /// Class TmdbImage
  1418. /// </summary>
  1419. protected class TmdbImage
  1420. {
  1421. /// <summary>
  1422. /// Gets or sets the file_path.
  1423. /// </summary>
  1424. /// <value>The file_path.</value>
  1425. public string file_path { get; set; }
  1426. /// <summary>
  1427. /// Gets or sets the width.
  1428. /// </summary>
  1429. /// <value>The width.</value>
  1430. public int width { get; set; }
  1431. /// <summary>
  1432. /// Gets or sets the height.
  1433. /// </summary>
  1434. /// <value>The height.</value>
  1435. public int height { get; set; }
  1436. /// <summary>
  1437. /// Gets or sets the iso_639_1.
  1438. /// </summary>
  1439. /// <value>The iso_639_1.</value>
  1440. public string iso_639_1 { get; set; }
  1441. /// <summary>
  1442. /// Gets or sets the aspect_ratio.
  1443. /// </summary>
  1444. /// <value>The aspect_ratio.</value>
  1445. public double aspect_ratio { get; set; }
  1446. /// <summary>
  1447. /// Gets or sets the vote_average.
  1448. /// </summary>
  1449. /// <value>The vote_average.</value>
  1450. public double vote_average { get; set; }
  1451. /// <summary>
  1452. /// Gets or sets the vote_count.
  1453. /// </summary>
  1454. /// <value>The vote_count.</value>
  1455. public int vote_count { get; set; }
  1456. }
  1457. /// <summary>
  1458. /// Class TmdbImages
  1459. /// </summary>
  1460. protected class TmdbImages
  1461. {
  1462. /// <summary>
  1463. /// Gets or sets the id.
  1464. /// </summary>
  1465. /// <value>The id.</value>
  1466. public int id { get; set; }
  1467. /// <summary>
  1468. /// Gets or sets the backdrops.
  1469. /// </summary>
  1470. /// <value>The backdrops.</value>
  1471. public List<TmdbImage> backdrops { get; set; }
  1472. /// <summary>
  1473. /// Gets or sets the posters.
  1474. /// </summary>
  1475. /// <value>The posters.</value>
  1476. public List<TmdbImage> posters { get; set; }
  1477. }
  1478. /// <summary>
  1479. /// Class CompleteMovieData
  1480. /// </summary>
  1481. protected class CompleteMovieData
  1482. {
  1483. public bool adult { get; set; }
  1484. public string backdrop_path { get; set; }
  1485. public BelongsToCollection belongs_to_collection { get; set; }
  1486. public int budget { get; set; }
  1487. public List<Genre> genres { get; set; }
  1488. public string homepage { get; set; }
  1489. public int id { get; set; }
  1490. public string imdb_id { get; set; }
  1491. public string original_title { get; set; }
  1492. public string overview { get; set; }
  1493. public double popularity { get; set; }
  1494. public string poster_path { get; set; }
  1495. public List<ProductionCompany> production_companies { get; set; }
  1496. public List<ProductionCountry> production_countries { get; set; }
  1497. public DateTime release_date { get; set; }
  1498. public int revenue { get; set; }
  1499. public int runtime { get; set; }
  1500. public List<SpokenLanguage> spoken_languages { get; set; }
  1501. public string tagline { get; set; }
  1502. public string title { get; set; }
  1503. public double vote_average { get; set; }
  1504. public int vote_count { get; set; }
  1505. public List<Country> countries { get; set; }
  1506. public List<Cast> cast { get; set; }
  1507. public List<Crew> crew { get; set; }
  1508. }
  1509. public class TmdbImageSettings
  1510. {
  1511. public List<string> backdrop_sizes { get; set; }
  1512. public string base_url { get; set; }
  1513. public List<string> poster_sizes { get; set; }
  1514. public List<string> profile_sizes { get; set; }
  1515. }
  1516. public class TmdbSettingsResult
  1517. {
  1518. public TmdbImageSettings images { get; set; }
  1519. }
  1520. #endregion
  1521. public void Dispose()
  1522. {
  1523. Dispose(true);
  1524. }
  1525. }
  1526. }