MovieDbProvider.cs 65 KB

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