MovieDbProvider.cs 66 KB

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