BaseItem.cs 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.IO;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.Localization;
  6. using MediaBrowser.Controller.Persistence;
  7. using MediaBrowser.Controller.Providers;
  8. using MediaBrowser.Controller.Resolvers;
  9. using MediaBrowser.Model.Entities;
  10. using MediaBrowser.Model.Logging;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.Serialization;
  16. using System.Text;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. namespace MediaBrowser.Controller.Entities
  20. {
  21. /// <summary>
  22. /// Class BaseItem
  23. /// </summary>
  24. public abstract class BaseItem : IHasProviderIds
  25. {
  26. protected BaseItem()
  27. {
  28. Genres = new List<string>();
  29. TrailerUrls = new List<string>();
  30. Studios = new List<string>();
  31. People = new List<PersonInfo>();
  32. CriticReviews = new List<ItemReview>();
  33. }
  34. /// <summary>
  35. /// The trailer folder name
  36. /// </summary>
  37. public const string TrailerFolderName = "trailers";
  38. public const string ThemeSongsFolderName = "theme-music";
  39. /// <summary>
  40. /// Gets or sets the name.
  41. /// </summary>
  42. /// <value>The name.</value>
  43. public virtual string Name { get; set; }
  44. /// <summary>
  45. /// Gets or sets the id.
  46. /// </summary>
  47. /// <value>The id.</value>
  48. public virtual Guid Id { get; set; }
  49. /// <summary>
  50. /// Gets or sets the path.
  51. /// </summary>
  52. /// <value>The path.</value>
  53. public virtual string Path { get; set; }
  54. /// <summary>
  55. /// Gets or sets the type of the location.
  56. /// </summary>
  57. /// <value>The type of the location.</value>
  58. public virtual LocationType LocationType
  59. {
  60. get
  61. {
  62. if (string.IsNullOrEmpty(Path))
  63. {
  64. return LocationType.Virtual;
  65. }
  66. return System.IO.Path.IsPathRooted(Path) ? LocationType.FileSystem : LocationType.Remote;
  67. }
  68. }
  69. /// <summary>
  70. /// This is just a helper for convenience
  71. /// </summary>
  72. /// <value>The primary image path.</value>
  73. [IgnoreDataMember]
  74. public string PrimaryImagePath
  75. {
  76. get { return GetImage(ImageType.Primary); }
  77. set { SetImage(ImageType.Primary, value); }
  78. }
  79. /// <summary>
  80. /// Gets or sets the images.
  81. /// </summary>
  82. /// <value>The images.</value>
  83. public virtual Dictionary<ImageType, string> Images { get; set; }
  84. /// <summary>
  85. /// Gets or sets the date created.
  86. /// </summary>
  87. /// <value>The date created.</value>
  88. public DateTime DateCreated { get; set; }
  89. /// <summary>
  90. /// Gets or sets the date modified.
  91. /// </summary>
  92. /// <value>The date modified.</value>
  93. public DateTime DateModified { get; set; }
  94. /// <summary>
  95. /// The logger
  96. /// </summary>
  97. public static ILogger Logger { get; set; }
  98. public static ILibraryManager LibraryManager { get; set; }
  99. public static IServerConfigurationManager ConfigurationManager { get; set; }
  100. public static IProviderManager ProviderManager { get; set; }
  101. /// <summary>
  102. /// Returns a <see cref="System.String" /> that represents this instance.
  103. /// </summary>
  104. /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
  105. public override string ToString()
  106. {
  107. return Name;
  108. }
  109. /// <summary>
  110. /// Returns true if this item should not attempt to fetch metadata
  111. /// </summary>
  112. /// <value><c>true</c> if [dont fetch meta]; otherwise, <c>false</c>.</value>
  113. [IgnoreDataMember]
  114. public virtual bool DontFetchMeta
  115. {
  116. get
  117. {
  118. if (Path != null)
  119. {
  120. return Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1;
  121. }
  122. return false;
  123. }
  124. }
  125. /// <summary>
  126. /// Determines whether the item has a saved local image of the specified name (jpg or png).
  127. /// </summary>
  128. /// <param name="name">The name.</param>
  129. /// <returns><c>true</c> if [has local image] [the specified item]; otherwise, <c>false</c>.</returns>
  130. /// <exception cref="System.ArgumentNullException">name</exception>
  131. public bool HasLocalImage(string name)
  132. {
  133. if (string.IsNullOrEmpty(name))
  134. {
  135. throw new ArgumentNullException("name");
  136. }
  137. return ResolveArgs.ContainsMetaFileByName(name + ".jpg") ||
  138. ResolveArgs.ContainsMetaFileByName(name + ".png");
  139. }
  140. /// <summary>
  141. /// Should be overridden to return the proper folder where metadata lives
  142. /// </summary>
  143. /// <value>The meta location.</value>
  144. [IgnoreDataMember]
  145. public virtual string MetaLocation
  146. {
  147. get
  148. {
  149. return Path ?? "";
  150. }
  151. }
  152. /// <summary>
  153. /// The _provider data
  154. /// </summary>
  155. private Dictionary<Guid, BaseProviderInfo> _providerData;
  156. /// <summary>
  157. /// Holds persistent data for providers like last refresh date.
  158. /// Providers can use this to determine if they need to refresh.
  159. /// The BaseProviderInfo class can be extended to hold anything a provider may need.
  160. /// Keyed by a unique provider ID.
  161. /// </summary>
  162. /// <value>The provider data.</value>
  163. public Dictionary<Guid, BaseProviderInfo> ProviderData
  164. {
  165. get
  166. {
  167. return _providerData ?? (_providerData = new Dictionary<Guid, BaseProviderInfo>());
  168. }
  169. set
  170. {
  171. _providerData = value;
  172. }
  173. }
  174. /// <summary>
  175. /// The _file system stamp
  176. /// </summary>
  177. private Guid? _fileSystemStamp;
  178. /// <summary>
  179. /// Gets a directory stamp, in the form of a string, that can be used for
  180. /// comparison purposes to determine if the file system entries for this item have changed.
  181. /// </summary>
  182. /// <value>The file system stamp.</value>
  183. [IgnoreDataMember]
  184. public Guid FileSystemStamp
  185. {
  186. get
  187. {
  188. if (!_fileSystemStamp.HasValue)
  189. {
  190. _fileSystemStamp = GetFileSystemStamp();
  191. }
  192. return _fileSystemStamp.Value;
  193. }
  194. }
  195. /// <summary>
  196. /// Gets the type of the media.
  197. /// </summary>
  198. /// <value>The type of the media.</value>
  199. [IgnoreDataMember]
  200. public virtual string MediaType
  201. {
  202. get
  203. {
  204. return null;
  205. }
  206. }
  207. /// <summary>
  208. /// Gets a directory stamp, in the form of a string, that can be used for
  209. /// comparison purposes to determine if the file system entries for this item have changed.
  210. /// </summary>
  211. /// <returns>Guid.</returns>
  212. private Guid GetFileSystemStamp()
  213. {
  214. // If there's no path or the item is a file, there's nothing to do
  215. if (LocationType != LocationType.FileSystem || !ResolveArgs.IsDirectory)
  216. {
  217. return Guid.Empty;
  218. }
  219. var sb = new StringBuilder();
  220. // Record the name of each file
  221. // Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order
  222. foreach (var file in ResolveArgs.FileSystemChildren.OrderBy(f => f.cFileName))
  223. {
  224. sb.Append(file.cFileName);
  225. }
  226. foreach (var file in ResolveArgs.MetadataFiles.OrderBy(f => f.cFileName))
  227. {
  228. sb.Append(file.cFileName);
  229. }
  230. return sb.ToString().GetMD5();
  231. }
  232. /// <summary>
  233. /// The _resolve args
  234. /// </summary>
  235. private ItemResolveArgs _resolveArgs;
  236. /// <summary>
  237. /// The _resolve args initialized
  238. /// </summary>
  239. private bool _resolveArgsInitialized;
  240. /// <summary>
  241. /// The _resolve args sync lock
  242. /// </summary>
  243. private object _resolveArgsSyncLock = new object();
  244. /// <summary>
  245. /// We attach these to the item so that we only ever have to hit the file system once
  246. /// (this includes the children of the containing folder)
  247. /// Use ResolveArgs.FileSystemDictionary to check for the existence of files instead of File.Exists
  248. /// </summary>
  249. /// <value>The resolve args.</value>
  250. [IgnoreDataMember]
  251. public ItemResolveArgs ResolveArgs
  252. {
  253. get
  254. {
  255. try
  256. {
  257. LazyInitializer.EnsureInitialized(ref _resolveArgs, ref _resolveArgsInitialized, ref _resolveArgsSyncLock, () => CreateResolveArgs());
  258. }
  259. catch (IOException ex)
  260. {
  261. Logger.ErrorException("Error creating resolve args for ", ex, Path);
  262. throw;
  263. }
  264. return _resolveArgs;
  265. }
  266. set
  267. {
  268. _resolveArgs = value;
  269. _resolveArgsInitialized = value != null;
  270. // Null this out so that it can be lazy loaded again
  271. _fileSystemStamp = null;
  272. }
  273. }
  274. /// <summary>
  275. /// Resets the resolve args.
  276. /// </summary>
  277. /// <param name="pathInfo">The path info.</param>
  278. public void ResetResolveArgs(WIN32_FIND_DATA? pathInfo)
  279. {
  280. ResolveArgs = CreateResolveArgs(pathInfo);
  281. }
  282. /// <summary>
  283. /// Creates ResolveArgs on demand
  284. /// </summary>
  285. /// <param name="pathInfo">The path info.</param>
  286. /// <returns>ItemResolveArgs.</returns>
  287. /// <exception cref="System.IO.IOException">Unable to retrieve file system info for + path</exception>
  288. protected internal virtual ItemResolveArgs CreateResolveArgs(WIN32_FIND_DATA? pathInfo = null)
  289. {
  290. var path = Path;
  291. // non file-system entries will not have a path
  292. if (LocationType != LocationType.FileSystem || string.IsNullOrEmpty(path))
  293. {
  294. return new ItemResolveArgs(ConfigurationManager.ApplicationPaths)
  295. {
  296. FileInfo = new WIN32_FIND_DATA()
  297. };
  298. }
  299. if (UseParentPathToCreateResolveArgs)
  300. {
  301. path = System.IO.Path.GetDirectoryName(path);
  302. }
  303. pathInfo = pathInfo ?? FileSystem.GetFileData(path);
  304. if (!pathInfo.HasValue)
  305. {
  306. throw new IOException("Unable to retrieve file system info for " + path);
  307. }
  308. var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths)
  309. {
  310. FileInfo = pathInfo.Value,
  311. Path = path,
  312. Parent = Parent
  313. };
  314. // Gather child folder and files
  315. if (args.IsDirectory)
  316. {
  317. var isPhysicalRoot = args.IsPhysicalRoot;
  318. // When resolving the root, we need it's grandchildren (children of user views)
  319. var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
  320. args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
  321. }
  322. //update our dates
  323. EntityResolutionHelper.EnsureDates(this, args);
  324. return args;
  325. }
  326. /// <summary>
  327. /// Some subclasses will stop resolving at a directory and point their Path to a file within. This will help ensure the on-demand resolve args are identical to the
  328. /// original ones.
  329. /// </summary>
  330. /// <value><c>true</c> if [use parent path to create resolve args]; otherwise, <c>false</c>.</value>
  331. [IgnoreDataMember]
  332. protected virtual bool UseParentPathToCreateResolveArgs
  333. {
  334. get
  335. {
  336. return false;
  337. }
  338. }
  339. /// <summary>
  340. /// Gets or sets the name of the forced sort.
  341. /// </summary>
  342. /// <value>The name of the forced sort.</value>
  343. public string ForcedSortName { get; set; }
  344. private string _sortName;
  345. /// <summary>
  346. /// Gets or sets the name of the sort.
  347. /// </summary>
  348. /// <value>The name of the sort.</value>
  349. [IgnoreDataMember]
  350. public string SortName
  351. {
  352. get
  353. {
  354. return ForcedSortName ?? _sortName ?? (_sortName = CreateSortName());
  355. }
  356. }
  357. /// <summary>
  358. /// Creates the name of the sort.
  359. /// </summary>
  360. /// <returns>System.String.</returns>
  361. protected virtual string CreateSortName()
  362. {
  363. if (Name == null) return null; //some items may not have name filled in properly
  364. var sortable = Name.Trim().ToLower();
  365. sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
  366. sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
  367. foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
  368. {
  369. var searchLower = search.ToLower();
  370. // Remove from beginning if a space follows
  371. if (sortable.StartsWith(searchLower + " "))
  372. {
  373. sortable = sortable.Remove(0, searchLower.Length + 1);
  374. }
  375. // Remove from middle if surrounded by spaces
  376. sortable = sortable.Replace(" " + searchLower + " ", " ");
  377. // Remove from end if followed by a space
  378. if (sortable.EndsWith(" " + searchLower))
  379. {
  380. sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
  381. }
  382. }
  383. return sortable;
  384. }
  385. /// <summary>
  386. /// Gets or sets the parent.
  387. /// </summary>
  388. /// <value>The parent.</value>
  389. [IgnoreDataMember]
  390. public Folder Parent { get; set; }
  391. /// <summary>
  392. /// Gets the collection folder parent.
  393. /// </summary>
  394. /// <value>The collection folder parent.</value>
  395. [IgnoreDataMember]
  396. public Folder CollectionFolder
  397. {
  398. get
  399. {
  400. if (this is AggregateFolder)
  401. {
  402. return null;
  403. }
  404. if (IsFolder)
  405. {
  406. var iCollectionFolder = this as ICollectionFolder;
  407. if (iCollectionFolder != null)
  408. {
  409. return (Folder)this;
  410. }
  411. }
  412. var parent = Parent;
  413. while (parent != null)
  414. {
  415. var iCollectionFolder = parent as ICollectionFolder;
  416. if (iCollectionFolder != null)
  417. {
  418. return parent;
  419. }
  420. parent = parent.Parent;
  421. }
  422. return null;
  423. }
  424. }
  425. /// <summary>
  426. /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
  427. /// </summary>
  428. /// <value>The premiere date.</value>
  429. public DateTime? PremiereDate { get; set; }
  430. /// <summary>
  431. /// Gets or sets the end date.
  432. /// </summary>
  433. /// <value>The end date.</value>
  434. public DateTime? EndDate { get; set; }
  435. /// <summary>
  436. /// Gets or sets the display type of the media.
  437. /// </summary>
  438. /// <value>The display type of the media.</value>
  439. public virtual string DisplayMediaType { get; set; }
  440. /// <summary>
  441. /// Gets or sets the backdrop image paths.
  442. /// </summary>
  443. /// <value>The backdrop image paths.</value>
  444. public List<string> BackdropImagePaths { get; set; }
  445. /// <summary>
  446. /// Gets or sets the screenshot image paths.
  447. /// </summary>
  448. /// <value>The screenshot image paths.</value>
  449. public List<string> ScreenshotImagePaths { get; set; }
  450. /// <summary>
  451. /// Gets or sets the official rating.
  452. /// </summary>
  453. /// <value>The official rating.</value>
  454. public virtual string OfficialRating { get; set; }
  455. /// <summary>
  456. /// Gets or sets the custom rating.
  457. /// </summary>
  458. /// <value>The custom rating.</value>
  459. public virtual string CustomRating { get; set; }
  460. /// <summary>
  461. /// Gets or sets the language.
  462. /// </summary>
  463. /// <value>The language.</value>
  464. public string Language { get; set; }
  465. /// <summary>
  466. /// Gets or sets the overview.
  467. /// </summary>
  468. /// <value>The overview.</value>
  469. public string Overview { get; set; }
  470. /// <summary>
  471. /// Gets or sets the taglines.
  472. /// </summary>
  473. /// <value>The taglines.</value>
  474. public List<string> Taglines { get; set; }
  475. /// <summary>
  476. /// Gets or sets the people.
  477. /// </summary>
  478. /// <value>The people.</value>
  479. public List<PersonInfo> People { get; set; }
  480. /// <summary>
  481. /// Override this if you need to combine/collapse person information
  482. /// </summary>
  483. /// <value>All people.</value>
  484. [IgnoreDataMember]
  485. public virtual IEnumerable<PersonInfo> AllPeople
  486. {
  487. get { return People; }
  488. }
  489. /// <summary>
  490. /// Gets or sets the studios.
  491. /// </summary>
  492. /// <value>The studios.</value>
  493. public virtual List<string> Studios { get; set; }
  494. /// <summary>
  495. /// Gets or sets the genres.
  496. /// </summary>
  497. /// <value>The genres.</value>
  498. public virtual List<string> Genres { get; set; }
  499. /// <summary>
  500. /// Gets or sets the home page URL.
  501. /// </summary>
  502. /// <value>The home page URL.</value>
  503. public string HomePageUrl { get; set; }
  504. /// <summary>
  505. /// Gets or sets the budget.
  506. /// </summary>
  507. /// <value>The budget.</value>
  508. public double? Budget { get; set; }
  509. /// <summary>
  510. /// Gets or sets the revenue.
  511. /// </summary>
  512. /// <value>The revenue.</value>
  513. public double? Revenue { get; set; }
  514. /// <summary>
  515. /// Gets or sets the production locations.
  516. /// </summary>
  517. /// <value>The production locations.</value>
  518. public List<string> ProductionLocations { get; set; }
  519. /// <summary>
  520. /// Gets or sets the critic rating.
  521. /// </summary>
  522. /// <value>The critic rating.</value>
  523. public float? CriticRating { get; set; }
  524. /// <summary>
  525. /// Gets or sets the critic rating summary.
  526. /// </summary>
  527. /// <value>The critic rating summary.</value>
  528. public string CriticRatingSummary { get; set; }
  529. /// <summary>
  530. /// Gets or sets the community rating.
  531. /// </summary>
  532. /// <value>The community rating.</value>
  533. public float? CommunityRating { get; set; }
  534. /// <summary>
  535. /// Gets or sets the run time ticks.
  536. /// </summary>
  537. /// <value>The run time ticks.</value>
  538. public long? RunTimeTicks { get; set; }
  539. /// <summary>
  540. /// Gets or sets the aspect ratio.
  541. /// </summary>
  542. /// <value>The aspect ratio.</value>
  543. public string AspectRatio { get; set; }
  544. /// <summary>
  545. /// Gets or sets the production year.
  546. /// </summary>
  547. /// <value>The production year.</value>
  548. public virtual int? ProductionYear { get; set; }
  549. /// <summary>
  550. /// If the item is part of a series, this is it's number in the series.
  551. /// This could be episode number, album track number, etc.
  552. /// </summary>
  553. /// <value>The index number.</value>
  554. public int? IndexNumber { get; set; }
  555. /// <summary>
  556. /// For an episode this could be the season number, or for a song this could be the disc number.
  557. /// </summary>
  558. /// <value>The parent index number.</value>
  559. public int? ParentIndexNumber { get; set; }
  560. /// <summary>
  561. /// Gets or sets the critic reviews.
  562. /// </summary>
  563. /// <value>The critic reviews.</value>
  564. public List<ItemReview> CriticReviews { get; set; }
  565. /// <summary>
  566. /// The _local trailers
  567. /// </summary>
  568. private List<Trailer> _localTrailers;
  569. /// <summary>
  570. /// The _local trailers initialized
  571. /// </summary>
  572. private bool _localTrailersInitialized;
  573. /// <summary>
  574. /// The _local trailers sync lock
  575. /// </summary>
  576. private object _localTrailersSyncLock = new object();
  577. /// <summary>
  578. /// Gets the local trailers.
  579. /// </summary>
  580. /// <value>The local trailers.</value>
  581. [IgnoreDataMember]
  582. public List<Trailer> LocalTrailers
  583. {
  584. get
  585. {
  586. LazyInitializer.EnsureInitialized(ref _localTrailers, ref _localTrailersInitialized, ref _localTrailersSyncLock, LoadLocalTrailers);
  587. return _localTrailers;
  588. }
  589. private set
  590. {
  591. _localTrailers = value;
  592. if (value == null)
  593. {
  594. _localTrailersInitialized = false;
  595. }
  596. }
  597. }
  598. private List<Audio.Audio> _themeSongs;
  599. private bool _themeSongsInitialized;
  600. private object _themeSongsSyncLock = new object();
  601. [IgnoreDataMember]
  602. public List<Audio.Audio> ThemeSongs
  603. {
  604. get
  605. {
  606. LazyInitializer.EnsureInitialized(ref _themeSongs, ref _themeSongsInitialized, ref _themeSongsSyncLock, LoadThemeSongs);
  607. return _themeSongs;
  608. }
  609. private set
  610. {
  611. _themeSongs = value;
  612. if (value == null)
  613. {
  614. _themeSongsInitialized = false;
  615. }
  616. }
  617. }
  618. /// <summary>
  619. /// Loads local trailers from the file system
  620. /// </summary>
  621. /// <returns>List{Video}.</returns>
  622. private List<Trailer> LoadLocalTrailers()
  623. {
  624. ItemResolveArgs resolveArgs;
  625. try
  626. {
  627. resolveArgs = ResolveArgs;
  628. }
  629. catch (IOException ex)
  630. {
  631. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  632. return new List<Trailer>();
  633. }
  634. if (!resolveArgs.IsDirectory)
  635. {
  636. return new List<Trailer>();
  637. }
  638. var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName);
  639. // Path doesn't exist. No biggie
  640. if (folder == null)
  641. {
  642. return new List<Trailer>();
  643. }
  644. IEnumerable<WIN32_FIND_DATA> files;
  645. try
  646. {
  647. files = FileSystem.GetFiles(folder.Value.Path);
  648. }
  649. catch (IOException ex)
  650. {
  651. Logger.ErrorException("Error loading trailers for {0}", ex, Name);
  652. return new List<Trailer>();
  653. }
  654. return LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
  655. {
  656. // Try to retrieve it from the db. If we don't find it, use the resolved version
  657. var dbItem = LibraryManager.RetrieveItem(video.Id) as Trailer;
  658. if (dbItem != null)
  659. {
  660. dbItem.ResolveArgs = video.ResolveArgs;
  661. video = dbItem;
  662. }
  663. return video;
  664. }).ToList();
  665. }
  666. /// <summary>
  667. /// Loads the theme songs.
  668. /// </summary>
  669. /// <returns>List{Audio.Audio}.</returns>
  670. private List<Audio.Audio> LoadThemeSongs()
  671. {
  672. ItemResolveArgs resolveArgs;
  673. try
  674. {
  675. resolveArgs = ResolveArgs;
  676. }
  677. catch (IOException ex)
  678. {
  679. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  680. return new List<Audio.Audio>();
  681. }
  682. if (!resolveArgs.IsDirectory)
  683. {
  684. return new List<Audio.Audio>();
  685. }
  686. var folder = resolveArgs.GetFileSystemEntryByName(ThemeSongsFolderName);
  687. // Path doesn't exist. No biggie
  688. if (folder == null)
  689. {
  690. return new List<Audio.Audio>();
  691. }
  692. IEnumerable<WIN32_FIND_DATA> files;
  693. try
  694. {
  695. files = FileSystem.GetFiles(folder.Value.Path);
  696. }
  697. catch (IOException ex)
  698. {
  699. Logger.ErrorException("Error loading theme songs for {0}", ex, Name);
  700. return new List<Audio.Audio>();
  701. }
  702. return LibraryManager.ResolvePaths<Audio.Audio>(files, null).Select(audio =>
  703. {
  704. // Try to retrieve it from the db. If we don't find it, use the resolved version
  705. var dbItem = LibraryManager.RetrieveItem(audio.Id) as Audio.Audio;
  706. if (dbItem != null)
  707. {
  708. dbItem.ResolveArgs = audio.ResolveArgs;
  709. audio = dbItem;
  710. }
  711. return audio;
  712. }).ToList();
  713. }
  714. /// <summary>
  715. /// Overrides the base implementation to refresh metadata for local trailers
  716. /// </summary>
  717. /// <param name="cancellationToken">The cancellation token.</param>
  718. /// <param name="forceSave">if set to <c>true</c> [is new item].</param>
  719. /// <param name="forceRefresh">if set to <c>true</c> [force].</param>
  720. /// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
  721. /// <param name="resetResolveArgs">if set to <c>true</c> [reset resolve args].</param>
  722. /// <returns>true if a provider reports we changed</returns>
  723. public virtual async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
  724. {
  725. if (resetResolveArgs)
  726. {
  727. ResolveArgs = null;
  728. }
  729. // Lazy load these again
  730. LocalTrailers = null;
  731. ThemeSongs = null;
  732. // Refresh for the item
  733. var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
  734. cancellationToken.ThrowIfCancellationRequested();
  735. // Refresh metadata for local trailers
  736. var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
  737. var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
  738. cancellationToken.ThrowIfCancellationRequested();
  739. // Await the trailer tasks
  740. await Task.WhenAll(trailerTasks).ConfigureAwait(false);
  741. await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
  742. cancellationToken.ThrowIfCancellationRequested();
  743. // Get the result from the item task
  744. var changed = await itemRefreshTask.ConfigureAwait(false);
  745. if (changed || forceSave)
  746. {
  747. cancellationToken.ThrowIfCancellationRequested();
  748. await LibraryManager.SaveItem(this, cancellationToken).ConfigureAwait(false);
  749. }
  750. return changed;
  751. }
  752. /// <summary>
  753. /// Clear out all metadata properties. Extend for sub-classes.
  754. /// </summary>
  755. public virtual void ClearMetaValues()
  756. {
  757. Images = null;
  758. ForcedSortName = null;
  759. PremiereDate = null;
  760. BackdropImagePaths = null;
  761. OfficialRating = null;
  762. CustomRating = null;
  763. Overview = null;
  764. Taglines = null;
  765. Language = null;
  766. Studios = null;
  767. Genres = null;
  768. CommunityRating = null;
  769. RunTimeTicks = null;
  770. AspectRatio = null;
  771. ProductionYear = null;
  772. ProviderIds = null;
  773. DisplayMediaType = GetType().Name;
  774. ResolveArgs = null;
  775. }
  776. /// <summary>
  777. /// Gets or sets the trailer URL.
  778. /// </summary>
  779. /// <value>The trailer URL.</value>
  780. public List<string> TrailerUrls { get; set; }
  781. /// <summary>
  782. /// Gets or sets the provider ids.
  783. /// </summary>
  784. /// <value>The provider ids.</value>
  785. public Dictionary<string, string> ProviderIds { get; set; }
  786. /// <summary>
  787. /// Override this to false if class should be ignored for indexing purposes
  788. /// </summary>
  789. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  790. [IgnoreDataMember]
  791. public virtual bool IncludeInIndex
  792. {
  793. get { return true; }
  794. }
  795. /// <summary>
  796. /// Override this to true if class should be grouped under a container in indicies
  797. /// The container class should be defined via IndexContainer
  798. /// </summary>
  799. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  800. [IgnoreDataMember]
  801. public virtual bool GroupInIndex
  802. {
  803. get { return false; }
  804. }
  805. /// <summary>
  806. /// Override this to return the folder that should be used to construct a container
  807. /// for this item in an index. GroupInIndex should be true as well.
  808. /// </summary>
  809. /// <value>The index container.</value>
  810. [IgnoreDataMember]
  811. public virtual Folder IndexContainer
  812. {
  813. get { return null; }
  814. }
  815. /// <summary>
  816. /// Gets the user data key.
  817. /// </summary>
  818. /// <returns>System.String.</returns>
  819. public virtual string GetUserDataKey()
  820. {
  821. return Id.ToString();
  822. }
  823. /// <summary>
  824. /// Determines if a given user has access to this item
  825. /// </summary>
  826. /// <param name="user">The user.</param>
  827. /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
  828. /// <exception cref="System.ArgumentNullException"></exception>
  829. public bool IsParentalAllowed(User user)
  830. {
  831. if (user == null)
  832. {
  833. throw new ArgumentNullException("user");
  834. }
  835. if (user.Configuration.MaxParentalRating == null)
  836. {
  837. return true;
  838. }
  839. return Ratings.Level(CustomRating ?? OfficialRating) <= user.Configuration.MaxParentalRating.Value;
  840. }
  841. /// <summary>
  842. /// Determines if this folder should be visible to a given user.
  843. /// Default is just parental allowed. Can be overridden for more functionality.
  844. /// </summary>
  845. /// <param name="user">The user.</param>
  846. /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
  847. /// <exception cref="System.ArgumentNullException">user</exception>
  848. public virtual bool IsVisible(User user)
  849. {
  850. if (user == null)
  851. {
  852. throw new ArgumentNullException("user");
  853. }
  854. return IsParentalAllowed(user);
  855. }
  856. /// <summary>
  857. /// Finds the particular item by searching through our parents and, if not found there, loading from repo
  858. /// </summary>
  859. /// <param name="id">The id.</param>
  860. /// <returns>BaseItem.</returns>
  861. /// <exception cref="System.ArgumentException"></exception>
  862. protected BaseItem FindParentItem(Guid id)
  863. {
  864. if (id == Guid.Empty)
  865. {
  866. throw new ArgumentException();
  867. }
  868. var parent = Parent;
  869. while (parent != null && !parent.IsRoot)
  870. {
  871. if (parent.Id == id) return parent;
  872. parent = parent.Parent;
  873. }
  874. //not found - load from repo
  875. return LibraryManager.RetrieveItem(id);
  876. }
  877. /// <summary>
  878. /// Gets a value indicating whether this instance is folder.
  879. /// </summary>
  880. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  881. [IgnoreDataMember]
  882. public virtual bool IsFolder
  883. {
  884. get
  885. {
  886. return false;
  887. }
  888. }
  889. /// <summary>
  890. /// Determine if we have changed vs the passed in copy
  891. /// </summary>
  892. /// <param name="copy">The copy.</param>
  893. /// <returns><c>true</c> if the specified copy has changed; otherwise, <c>false</c>.</returns>
  894. /// <exception cref="System.ArgumentNullException"></exception>
  895. public virtual bool HasChanged(BaseItem copy)
  896. {
  897. if (copy == null)
  898. {
  899. throw new ArgumentNullException();
  900. }
  901. var changed = copy.DateModified != DateModified;
  902. if (changed)
  903. {
  904. Logger.Debug(Name + " changed - original creation: " + DateCreated + " new creation: " + copy.DateCreated + " original modified: " + DateModified + " new modified: " + copy.DateModified);
  905. }
  906. return changed;
  907. }
  908. /// <summary>
  909. /// Determines if the item is considered new based on user settings
  910. /// </summary>
  911. /// <returns><c>true</c> if [is recently added] [the specified user]; otherwise, <c>false</c>.</returns>
  912. /// <exception cref="System.ArgumentNullException"></exception>
  913. public bool IsRecentlyAdded()
  914. {
  915. return (DateTime.UtcNow - DateCreated).TotalDays < ConfigurationManager.Configuration.RecentItemDays;
  916. }
  917. /// <summary>
  918. /// Adds people to the item
  919. /// </summary>
  920. /// <param name="people">The people.</param>
  921. /// <exception cref="System.ArgumentNullException"></exception>
  922. public void AddPeople(IEnumerable<PersonInfo> people)
  923. {
  924. if (people == null)
  925. {
  926. throw new ArgumentNullException();
  927. }
  928. foreach (var person in people)
  929. {
  930. AddPerson(person);
  931. }
  932. }
  933. /// <summary>
  934. /// Adds a person to the item
  935. /// </summary>
  936. /// <param name="person">The person.</param>
  937. /// <exception cref="System.ArgumentNullException"></exception>
  938. public void AddPerson(PersonInfo person)
  939. {
  940. if (person == null)
  941. {
  942. throw new ArgumentNullException("person");
  943. }
  944. if (string.IsNullOrWhiteSpace(person.Name))
  945. {
  946. throw new ArgumentNullException();
  947. }
  948. if (People == null)
  949. {
  950. People = new List<PersonInfo> { person };
  951. return;
  952. }
  953. // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
  954. if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  955. {
  956. var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase));
  957. if (existing != null)
  958. {
  959. existing.Type = PersonType.GuestStar;
  960. return;
  961. }
  962. }
  963. if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
  964. {
  965. // Only add actors if there isn't an existing one of type Actor or GuestStar
  966. if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase) || p.Type.Equals(PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))))
  967. {
  968. People.Add(person);
  969. }
  970. }
  971. else
  972. {
  973. // Check for dupes based on the combination of Name and Type
  974. if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(person.Type, StringComparison.OrdinalIgnoreCase)))
  975. {
  976. People.Add(person);
  977. }
  978. }
  979. }
  980. /// <summary>
  981. /// Adds studios to the item
  982. /// </summary>
  983. /// <param name="studios">The studios.</param>
  984. /// <exception cref="System.ArgumentNullException"></exception>
  985. public void AddStudios(IEnumerable<string> studios)
  986. {
  987. if (studios == null)
  988. {
  989. throw new ArgumentNullException();
  990. }
  991. foreach (var name in studios)
  992. {
  993. AddStudio(name);
  994. }
  995. }
  996. /// <summary>
  997. /// Adds a studio to the item
  998. /// </summary>
  999. /// <param name="name">The name.</param>
  1000. /// <exception cref="System.ArgumentNullException"></exception>
  1001. public void AddStudio(string name)
  1002. {
  1003. if (string.IsNullOrWhiteSpace(name))
  1004. {
  1005. throw new ArgumentNullException("name");
  1006. }
  1007. if (Studios == null)
  1008. {
  1009. Studios = new List<string>();
  1010. }
  1011. if (!Studios.Contains(name, StringComparer.OrdinalIgnoreCase))
  1012. {
  1013. Studios.Add(name);
  1014. }
  1015. }
  1016. /// <summary>
  1017. /// Adds a tagline to the item
  1018. /// </summary>
  1019. /// <param name="name">The name.</param>
  1020. /// <exception cref="System.ArgumentNullException"></exception>
  1021. public void AddTagline(string name)
  1022. {
  1023. if (string.IsNullOrWhiteSpace(name))
  1024. {
  1025. throw new ArgumentNullException("name");
  1026. }
  1027. if (Taglines == null)
  1028. {
  1029. Taglines = new List<string>();
  1030. }
  1031. if (!Taglines.Contains(name, StringComparer.OrdinalIgnoreCase))
  1032. {
  1033. Taglines.Add(name);
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// Adds a TrailerUrl to the item
  1038. /// </summary>
  1039. /// <param name="url">The URL.</param>
  1040. /// <exception cref="System.ArgumentNullException"></exception>
  1041. public void AddTrailerUrl(string url)
  1042. {
  1043. if (string.IsNullOrWhiteSpace(url))
  1044. {
  1045. throw new ArgumentNullException("url");
  1046. }
  1047. if (TrailerUrls == null)
  1048. {
  1049. TrailerUrls = new List<string>();
  1050. }
  1051. if (!TrailerUrls.Contains(url, StringComparer.OrdinalIgnoreCase))
  1052. {
  1053. TrailerUrls.Add(url);
  1054. }
  1055. }
  1056. /// <summary>
  1057. /// Adds a genre to the item
  1058. /// </summary>
  1059. /// <param name="name">The name.</param>
  1060. /// <exception cref="System.ArgumentNullException"></exception>
  1061. public void AddGenre(string name)
  1062. {
  1063. if (string.IsNullOrWhiteSpace(name))
  1064. {
  1065. throw new ArgumentNullException("name");
  1066. }
  1067. if (Genres == null)
  1068. {
  1069. Genres = new List<string>();
  1070. }
  1071. if (!Genres.Contains(name, StringComparer.OrdinalIgnoreCase))
  1072. {
  1073. Genres.Add(name);
  1074. }
  1075. }
  1076. /// <summary>
  1077. /// Adds the production location.
  1078. /// </summary>
  1079. /// <param name="location">The location.</param>
  1080. /// <exception cref="System.ArgumentNullException">location</exception>
  1081. public void AddProductionLocation(string location)
  1082. {
  1083. if (string.IsNullOrWhiteSpace(location))
  1084. {
  1085. throw new ArgumentNullException("location");
  1086. }
  1087. if (ProductionLocations == null)
  1088. {
  1089. ProductionLocations = new List<string>();
  1090. }
  1091. if (!ProductionLocations.Contains(location, StringComparer.OrdinalIgnoreCase))
  1092. {
  1093. ProductionLocations.Add(location);
  1094. }
  1095. }
  1096. /// <summary>
  1097. /// Adds genres to the item
  1098. /// </summary>
  1099. /// <param name="genres">The genres.</param>
  1100. /// <exception cref="System.ArgumentNullException"></exception>
  1101. public void AddGenres(IEnumerable<string> genres)
  1102. {
  1103. if (genres == null)
  1104. {
  1105. throw new ArgumentNullException();
  1106. }
  1107. foreach (var name in genres)
  1108. {
  1109. AddGenre(name);
  1110. }
  1111. }
  1112. /// <summary>
  1113. /// Marks the item as either played or unplayed
  1114. /// </summary>
  1115. /// <param name="user">The user.</param>
  1116. /// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
  1117. /// <param name="userManager">The user manager.</param>
  1118. /// <returns>Task.</returns>
  1119. /// <exception cref="System.ArgumentNullException"></exception>
  1120. public virtual async Task SetPlayedStatus(User user, bool wasPlayed, IUserDataRepository userManager)
  1121. {
  1122. if (user == null)
  1123. {
  1124. throw new ArgumentNullException();
  1125. }
  1126. var key = GetUserDataKey();
  1127. var data = await userManager.GetUserData(user.Id, key).ConfigureAwait(false);
  1128. if (wasPlayed)
  1129. {
  1130. data.PlayCount = Math.Max(data.PlayCount, 1);
  1131. if (!data.LastPlayedDate.HasValue)
  1132. {
  1133. data.LastPlayedDate = DateTime.UtcNow;
  1134. }
  1135. }
  1136. else
  1137. {
  1138. //I think it is okay to do this here.
  1139. // if this is only called when a user is manually forcing something to un-played
  1140. // then it probably is what we want to do...
  1141. data.PlayCount = 0;
  1142. data.PlaybackPositionTicks = 0;
  1143. data.LastPlayedDate = null;
  1144. }
  1145. data.Played = wasPlayed;
  1146. await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
  1147. }
  1148. /// <summary>
  1149. /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
  1150. /// </summary>
  1151. /// <returns>Task.</returns>
  1152. public virtual Task ChangedExternally()
  1153. {
  1154. return RefreshMetadata(CancellationToken.None);
  1155. }
  1156. /// <summary>
  1157. /// Finds a parent of a given type
  1158. /// </summary>
  1159. /// <typeparam name="T"></typeparam>
  1160. /// <returns>``0.</returns>
  1161. public T FindParent<T>()
  1162. where T : Folder
  1163. {
  1164. var parent = Parent;
  1165. while (parent != null)
  1166. {
  1167. var result = parent as T;
  1168. if (result != null)
  1169. {
  1170. return result;
  1171. }
  1172. parent = parent.Parent;
  1173. }
  1174. return null;
  1175. }
  1176. /// <summary>
  1177. /// Gets an image
  1178. /// </summary>
  1179. /// <param name="type">The type.</param>
  1180. /// <returns>System.String.</returns>
  1181. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1182. public string GetImage(ImageType type)
  1183. {
  1184. if (type == ImageType.Backdrop)
  1185. {
  1186. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1187. }
  1188. if (type == ImageType.Screenshot)
  1189. {
  1190. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1191. }
  1192. if (Images == null)
  1193. {
  1194. return null;
  1195. }
  1196. string val;
  1197. Images.TryGetValue(type, out val);
  1198. return val;
  1199. }
  1200. /// <summary>
  1201. /// Gets an image
  1202. /// </summary>
  1203. /// <param name="type">The type.</param>
  1204. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  1205. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1206. public bool HasImage(ImageType type)
  1207. {
  1208. if (type == ImageType.Backdrop)
  1209. {
  1210. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1211. }
  1212. if (type == ImageType.Screenshot)
  1213. {
  1214. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1215. }
  1216. return !string.IsNullOrEmpty(GetImage(type));
  1217. }
  1218. /// <summary>
  1219. /// Sets an image
  1220. /// </summary>
  1221. /// <param name="type">The type.</param>
  1222. /// <param name="path">The path.</param>
  1223. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1224. public void SetImage(ImageType type, string path)
  1225. {
  1226. if (type == ImageType.Backdrop)
  1227. {
  1228. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1229. }
  1230. if (type == ImageType.Screenshot)
  1231. {
  1232. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1233. }
  1234. var typeKey = type;
  1235. // If it's null remove the key from the dictionary
  1236. if (string.IsNullOrEmpty(path))
  1237. {
  1238. if (Images != null)
  1239. {
  1240. if (Images.ContainsKey(typeKey))
  1241. {
  1242. Images.Remove(typeKey);
  1243. }
  1244. }
  1245. }
  1246. else
  1247. {
  1248. // Ensure it exists
  1249. if (Images == null)
  1250. {
  1251. Images = new Dictionary<ImageType, string>();
  1252. }
  1253. Images[typeKey] = path;
  1254. }
  1255. }
  1256. /// <summary>
  1257. /// Deletes the image.
  1258. /// </summary>
  1259. /// <param name="type">The type.</param>
  1260. /// <returns>Task.</returns>
  1261. public async Task DeleteImage(ImageType type)
  1262. {
  1263. if (!HasImage(type))
  1264. {
  1265. return;
  1266. }
  1267. // Delete the source file
  1268. File.Delete(GetImage(type));
  1269. // Remove it from the item
  1270. SetImage(type, null);
  1271. // Refresh metadata
  1272. await RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
  1273. }
  1274. }
  1275. }