MovieDbProvider.cs 66 KB

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