BaseItem.cs 48 KB

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