MovieDbProvider.cs 60 KB

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