MovieDbProvider.cs 66 KB

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