2
0

BaseItem.cs 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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.Name))
  223. {
  224. sb.Append(file.Name);
  225. }
  226. foreach (var file in ResolveArgs.MetadataFiles.OrderBy(f => f.Name))
  227. {
  228. sb.Append(file.Name);
  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(FileSystemInfo 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(FileSystemInfo 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. if (UseParentPathToCreateResolveArgs)
  297. {
  298. path = System.IO.Path.GetDirectoryName(path);
  299. }
  300. pathInfo = pathInfo ?? FileSystem.GetFileSystemInfo(path);
  301. if (pathInfo == null || !pathInfo.Exists)
  302. {
  303. throw new IOException("Unable to retrieve file system info for " + path);
  304. }
  305. var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths)
  306. {
  307. FileInfo = pathInfo,
  308. Path = path,
  309. Parent = Parent
  310. };
  311. // Gather child folder and files
  312. if (args.IsDirectory)
  313. {
  314. var isPhysicalRoot = args.IsPhysicalRoot;
  315. // When resolving the root, we need it's grandchildren (children of user views)
  316. var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
  317. args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
  318. }
  319. //update our dates
  320. EntityResolutionHelper.EnsureDates(this, args);
  321. return args;
  322. }
  323. /// <summary>
  324. /// 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
  325. /// original ones.
  326. /// </summary>
  327. /// <value><c>true</c> if [use parent path to create resolve args]; otherwise, <c>false</c>.</value>
  328. [IgnoreDataMember]
  329. protected virtual bool UseParentPathToCreateResolveArgs
  330. {
  331. get
  332. {
  333. return false;
  334. }
  335. }
  336. /// <summary>
  337. /// Gets or sets the name of the forced sort.
  338. /// </summary>
  339. /// <value>The name of the forced sort.</value>
  340. public string ForcedSortName { get; set; }
  341. private string _sortName;
  342. /// <summary>
  343. /// Gets or sets the name of the sort.
  344. /// </summary>
  345. /// <value>The name of the sort.</value>
  346. [IgnoreDataMember]
  347. public string SortName
  348. {
  349. get
  350. {
  351. return ForcedSortName ?? _sortName ?? (_sortName = CreateSortName());
  352. }
  353. }
  354. /// <summary>
  355. /// Creates the name of the sort.
  356. /// </summary>
  357. /// <returns>System.String.</returns>
  358. protected virtual string CreateSortName()
  359. {
  360. if (Name == null) return null; //some items may not have name filled in properly
  361. var sortable = Name.Trim().ToLower();
  362. sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
  363. sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
  364. foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
  365. {
  366. var searchLower = search.ToLower();
  367. // Remove from beginning if a space follows
  368. if (sortable.StartsWith(searchLower + " "))
  369. {
  370. sortable = sortable.Remove(0, searchLower.Length + 1);
  371. }
  372. // Remove from middle if surrounded by spaces
  373. sortable = sortable.Replace(" " + searchLower + " ", " ");
  374. // Remove from end if followed by a space
  375. if (sortable.EndsWith(" " + searchLower))
  376. {
  377. sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
  378. }
  379. }
  380. return sortable;
  381. }
  382. /// <summary>
  383. /// Gets or sets the parent.
  384. /// </summary>
  385. /// <value>The parent.</value>
  386. [IgnoreDataMember]
  387. public Folder Parent { get; set; }
  388. /// <summary>
  389. /// Gets the collection folder parent.
  390. /// </summary>
  391. /// <value>The collection folder parent.</value>
  392. [IgnoreDataMember]
  393. public Folder CollectionFolder
  394. {
  395. get
  396. {
  397. if (this is AggregateFolder)
  398. {
  399. return null;
  400. }
  401. if (IsFolder)
  402. {
  403. var iCollectionFolder = this as ICollectionFolder;
  404. if (iCollectionFolder != null)
  405. {
  406. return (Folder)this;
  407. }
  408. }
  409. var parent = Parent;
  410. while (parent != null)
  411. {
  412. var iCollectionFolder = parent as ICollectionFolder;
  413. if (iCollectionFolder != null)
  414. {
  415. return parent;
  416. }
  417. parent = parent.Parent;
  418. }
  419. return null;
  420. }
  421. }
  422. /// <summary>
  423. /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
  424. /// </summary>
  425. /// <value>The premiere date.</value>
  426. public DateTime? PremiereDate { get; set; }
  427. /// <summary>
  428. /// Gets or sets the end date.
  429. /// </summary>
  430. /// <value>The end date.</value>
  431. public DateTime? EndDate { get; set; }
  432. /// <summary>
  433. /// Gets or sets the display type of the media.
  434. /// </summary>
  435. /// <value>The display type of the media.</value>
  436. public virtual string DisplayMediaType { get; set; }
  437. /// <summary>
  438. /// Gets or sets the backdrop image paths.
  439. /// </summary>
  440. /// <value>The backdrop image paths.</value>
  441. public List<string> BackdropImagePaths { get; set; }
  442. /// <summary>
  443. /// Gets or sets the screenshot image paths.
  444. /// </summary>
  445. /// <value>The screenshot image paths.</value>
  446. public List<string> ScreenshotImagePaths { get; set; }
  447. /// <summary>
  448. /// Gets or sets the official rating.
  449. /// </summary>
  450. /// <value>The official rating.</value>
  451. public virtual string OfficialRating { get; set; }
  452. /// <summary>
  453. /// Gets or sets the custom rating.
  454. /// </summary>
  455. /// <value>The custom rating.</value>
  456. public virtual string CustomRating { get; set; }
  457. /// <summary>
  458. /// Gets or sets the language.
  459. /// </summary>
  460. /// <value>The language.</value>
  461. public string Language { get; set; }
  462. /// <summary>
  463. /// Gets or sets the overview.
  464. /// </summary>
  465. /// <value>The overview.</value>
  466. public string Overview { get; set; }
  467. /// <summary>
  468. /// Gets or sets the taglines.
  469. /// </summary>
  470. /// <value>The taglines.</value>
  471. public List<string> Taglines { get; set; }
  472. /// <summary>
  473. /// Gets or sets the people.
  474. /// </summary>
  475. /// <value>The people.</value>
  476. public List<PersonInfo> People { get; set; }
  477. /// <summary>
  478. /// Override this if you need to combine/collapse person information
  479. /// </summary>
  480. /// <value>All people.</value>
  481. [IgnoreDataMember]
  482. public virtual IEnumerable<PersonInfo> AllPeople
  483. {
  484. get { return People; }
  485. }
  486. /// <summary>
  487. /// Gets or sets the studios.
  488. /// </summary>
  489. /// <value>The studios.</value>
  490. public virtual List<string> Studios { get; set; }
  491. /// <summary>
  492. /// Gets or sets the genres.
  493. /// </summary>
  494. /// <value>The genres.</value>
  495. public virtual List<string> Genres { get; set; }
  496. /// <summary>
  497. /// Gets or sets the home page URL.
  498. /// </summary>
  499. /// <value>The home page URL.</value>
  500. public string HomePageUrl { get; set; }
  501. /// <summary>
  502. /// Gets or sets the budget.
  503. /// </summary>
  504. /// <value>The budget.</value>
  505. public double? Budget { get; set; }
  506. /// <summary>
  507. /// Gets or sets the revenue.
  508. /// </summary>
  509. /// <value>The revenue.</value>
  510. public double? Revenue { get; set; }
  511. /// <summary>
  512. /// Gets or sets the production locations.
  513. /// </summary>
  514. /// <value>The production locations.</value>
  515. public List<string> ProductionLocations { get; set; }
  516. /// <summary>
  517. /// Gets or sets the critic rating.
  518. /// </summary>
  519. /// <value>The critic rating.</value>
  520. public float? CriticRating { get; set; }
  521. /// <summary>
  522. /// Gets or sets the critic rating summary.
  523. /// </summary>
  524. /// <value>The critic rating summary.</value>
  525. public string CriticRatingSummary { get; set; }
  526. /// <summary>
  527. /// Gets or sets the community rating.
  528. /// </summary>
  529. /// <value>The community rating.</value>
  530. public float? CommunityRating { get; set; }
  531. /// <summary>
  532. /// Gets or sets the run time ticks.
  533. /// </summary>
  534. /// <value>The run time ticks.</value>
  535. public long? RunTimeTicks { get; set; }
  536. /// <summary>
  537. /// Gets or sets the aspect ratio.
  538. /// </summary>
  539. /// <value>The aspect ratio.</value>
  540. public string AspectRatio { get; set; }
  541. /// <summary>
  542. /// Gets or sets the production year.
  543. /// </summary>
  544. /// <value>The production year.</value>
  545. public virtual int? ProductionYear { get; set; }
  546. /// <summary>
  547. /// If the item is part of a series, this is it's number in the series.
  548. /// This could be episode number, album track number, etc.
  549. /// </summary>
  550. /// <value>The index number.</value>
  551. public int? IndexNumber { get; set; }
  552. /// <summary>
  553. /// For an episode this could be the season number, or for a song this could be the disc number.
  554. /// </summary>
  555. /// <value>The parent index number.</value>
  556. public int? ParentIndexNumber { get; set; }
  557. /// <summary>
  558. /// Gets or sets the critic reviews.
  559. /// </summary>
  560. /// <value>The critic reviews.</value>
  561. public List<ItemReview> CriticReviews { get; set; }
  562. /// <summary>
  563. /// The _local trailers
  564. /// </summary>
  565. private List<Trailer> _localTrailers;
  566. /// <summary>
  567. /// The _local trailers initialized
  568. /// </summary>
  569. private bool _localTrailersInitialized;
  570. /// <summary>
  571. /// The _local trailers sync lock
  572. /// </summary>
  573. private object _localTrailersSyncLock = new object();
  574. /// <summary>
  575. /// Gets the local trailers.
  576. /// </summary>
  577. /// <value>The local trailers.</value>
  578. [IgnoreDataMember]
  579. public List<Trailer> LocalTrailers
  580. {
  581. get
  582. {
  583. LazyInitializer.EnsureInitialized(ref _localTrailers, ref _localTrailersInitialized, ref _localTrailersSyncLock, LoadLocalTrailers);
  584. return _localTrailers;
  585. }
  586. private set
  587. {
  588. _localTrailers = value;
  589. if (value == null)
  590. {
  591. _localTrailersInitialized = false;
  592. }
  593. }
  594. }
  595. private List<Audio.Audio> _themeSongs;
  596. private bool _themeSongsInitialized;
  597. private object _themeSongsSyncLock = new object();
  598. [IgnoreDataMember]
  599. public List<Audio.Audio> ThemeSongs
  600. {
  601. get
  602. {
  603. LazyInitializer.EnsureInitialized(ref _themeSongs, ref _themeSongsInitialized, ref _themeSongsSyncLock, LoadThemeSongs);
  604. return _themeSongs;
  605. }
  606. private set
  607. {
  608. _themeSongs = value;
  609. if (value == null)
  610. {
  611. _themeSongsInitialized = false;
  612. }
  613. }
  614. }
  615. /// <summary>
  616. /// Loads local trailers from the file system
  617. /// </summary>
  618. /// <returns>List{Video}.</returns>
  619. private List<Trailer> LoadLocalTrailers()
  620. {
  621. ItemResolveArgs resolveArgs;
  622. try
  623. {
  624. resolveArgs = ResolveArgs;
  625. }
  626. catch (IOException ex)
  627. {
  628. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  629. return new List<Trailer>();
  630. }
  631. if (!resolveArgs.IsDirectory)
  632. {
  633. return new List<Trailer>();
  634. }
  635. var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName);
  636. // Path doesn't exist. No biggie
  637. if (folder == null)
  638. {
  639. return new List<Trailer>();
  640. }
  641. IEnumerable<FileSystemInfo> files;
  642. try
  643. {
  644. files = new DirectoryInfo(folder.FullName).EnumerateFiles();
  645. }
  646. catch (IOException ex)
  647. {
  648. Logger.ErrorException("Error loading trailers for {0}", ex, Name);
  649. return new List<Trailer>();
  650. }
  651. return LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
  652. {
  653. // Try to retrieve it from the db. If we don't find it, use the resolved version
  654. var dbItem = LibraryManager.RetrieveItem(video.Id) as Trailer;
  655. if (dbItem != null)
  656. {
  657. dbItem.ResolveArgs = video.ResolveArgs;
  658. video = dbItem;
  659. }
  660. return video;
  661. }).ToList();
  662. }
  663. /// <summary>
  664. /// Loads the theme songs.
  665. /// </summary>
  666. /// <returns>List{Audio.Audio}.</returns>
  667. private List<Audio.Audio> LoadThemeSongs()
  668. {
  669. ItemResolveArgs resolveArgs;
  670. try
  671. {
  672. resolveArgs = ResolveArgs;
  673. }
  674. catch (IOException ex)
  675. {
  676. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  677. return new List<Audio.Audio>();
  678. }
  679. if (!resolveArgs.IsDirectory)
  680. {
  681. return new List<Audio.Audio>();
  682. }
  683. var folder = resolveArgs.GetFileSystemEntryByName(ThemeSongsFolderName);
  684. // Path doesn't exist. No biggie
  685. if (folder == null)
  686. {
  687. return new List<Audio.Audio>();
  688. }
  689. IEnumerable<FileSystemInfo> files;
  690. try
  691. {
  692. files = new DirectoryInfo(folder.FullName).EnumerateFiles();
  693. }
  694. catch (IOException ex)
  695. {
  696. Logger.ErrorException("Error loading theme songs for {0}", ex, Name);
  697. return new List<Audio.Audio>();
  698. }
  699. return LibraryManager.ResolvePaths<Audio.Audio>(files, null).Select(audio =>
  700. {
  701. // Try to retrieve it from the db. If we don't find it, use the resolved version
  702. var dbItem = LibraryManager.RetrieveItem(audio.Id) as Audio.Audio;
  703. if (dbItem != null)
  704. {
  705. dbItem.ResolveArgs = audio.ResolveArgs;
  706. audio = dbItem;
  707. }
  708. return audio;
  709. }).ToList();
  710. }
  711. /// <summary>
  712. /// Overrides the base implementation to refresh metadata for local trailers
  713. /// </summary>
  714. /// <param name="cancellationToken">The cancellation token.</param>
  715. /// <param name="forceSave">if set to <c>true</c> [is new item].</param>
  716. /// <param name="forceRefresh">if set to <c>true</c> [force].</param>
  717. /// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
  718. /// <param name="resetResolveArgs">if set to <c>true</c> [reset resolve args].</param>
  719. /// <returns>true if a provider reports we changed</returns>
  720. public virtual async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
  721. {
  722. if (resetResolveArgs)
  723. {
  724. ResolveArgs = null;
  725. }
  726. // Lazy load these again
  727. LocalTrailers = null;
  728. ThemeSongs = null;
  729. // Refresh for the item
  730. var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
  731. cancellationToken.ThrowIfCancellationRequested();
  732. // Refresh metadata for local trailers
  733. var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
  734. var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
  735. cancellationToken.ThrowIfCancellationRequested();
  736. // Await the trailer tasks
  737. await Task.WhenAll(trailerTasks).ConfigureAwait(false);
  738. await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
  739. cancellationToken.ThrowIfCancellationRequested();
  740. // Get the result from the item task
  741. var changed = await itemRefreshTask.ConfigureAwait(false);
  742. if (changed || forceSave)
  743. {
  744. cancellationToken.ThrowIfCancellationRequested();
  745. await LibraryManager.SaveItem(this, cancellationToken).ConfigureAwait(false);
  746. }
  747. return changed;
  748. }
  749. /// <summary>
  750. /// Clear out all metadata properties. Extend for sub-classes.
  751. /// </summary>
  752. public virtual void ClearMetaValues()
  753. {
  754. Images = null;
  755. ForcedSortName = null;
  756. PremiereDate = null;
  757. BackdropImagePaths = null;
  758. OfficialRating = null;
  759. CustomRating = null;
  760. Overview = null;
  761. Taglines = null;
  762. Language = null;
  763. Studios = null;
  764. Genres = null;
  765. CommunityRating = null;
  766. RunTimeTicks = null;
  767. AspectRatio = null;
  768. ProductionYear = null;
  769. ProviderIds = null;
  770. DisplayMediaType = GetType().Name;
  771. ResolveArgs = null;
  772. }
  773. /// <summary>
  774. /// Gets or sets the trailer URL.
  775. /// </summary>
  776. /// <value>The trailer URL.</value>
  777. public List<string> TrailerUrls { get; set; }
  778. /// <summary>
  779. /// Gets or sets the provider ids.
  780. /// </summary>
  781. /// <value>The provider ids.</value>
  782. public Dictionary<string, string> ProviderIds { get; set; }
  783. /// <summary>
  784. /// Override this to false if class should be ignored for indexing purposes
  785. /// </summary>
  786. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  787. [IgnoreDataMember]
  788. public virtual bool IncludeInIndex
  789. {
  790. get { return true; }
  791. }
  792. /// <summary>
  793. /// Override this to true if class should be grouped under a container in indicies
  794. /// The container class should be defined via IndexContainer
  795. /// </summary>
  796. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  797. [IgnoreDataMember]
  798. public virtual bool GroupInIndex
  799. {
  800. get { return false; }
  801. }
  802. /// <summary>
  803. /// Override this to return the folder that should be used to construct a container
  804. /// for this item in an index. GroupInIndex should be true as well.
  805. /// </summary>
  806. /// <value>The index container.</value>
  807. [IgnoreDataMember]
  808. public virtual Folder IndexContainer
  809. {
  810. get { return null; }
  811. }
  812. /// <summary>
  813. /// Gets the user data key.
  814. /// </summary>
  815. /// <returns>System.String.</returns>
  816. public virtual string GetUserDataKey()
  817. {
  818. return Id.ToString();
  819. }
  820. /// <summary>
  821. /// Determines if a given user has access to this item
  822. /// </summary>
  823. /// <param name="user">The user.</param>
  824. /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
  825. /// <exception cref="System.ArgumentNullException"></exception>
  826. public bool IsParentalAllowed(User user)
  827. {
  828. if (user == null)
  829. {
  830. throw new ArgumentNullException("user");
  831. }
  832. if (user.Configuration.MaxParentalRating == null)
  833. {
  834. return true;
  835. }
  836. return Ratings.Level(CustomRating ?? OfficialRating) <= user.Configuration.MaxParentalRating.Value;
  837. }
  838. /// <summary>
  839. /// Determines if this folder should be visible to a given user.
  840. /// Default is just parental allowed. Can be overridden for more functionality.
  841. /// </summary>
  842. /// <param name="user">The user.</param>
  843. /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
  844. /// <exception cref="System.ArgumentNullException">user</exception>
  845. public virtual bool IsVisible(User user)
  846. {
  847. if (user == null)
  848. {
  849. throw new ArgumentNullException("user");
  850. }
  851. return IsParentalAllowed(user);
  852. }
  853. /// <summary>
  854. /// Finds the particular item by searching through our parents and, if not found there, loading from repo
  855. /// </summary>
  856. /// <param name="id">The id.</param>
  857. /// <returns>BaseItem.</returns>
  858. /// <exception cref="System.ArgumentException"></exception>
  859. protected BaseItem FindParentItem(Guid id)
  860. {
  861. if (id == Guid.Empty)
  862. {
  863. throw new ArgumentException();
  864. }
  865. var parent = Parent;
  866. while (parent != null && !parent.IsRoot)
  867. {
  868. if (parent.Id == id) return parent;
  869. parent = parent.Parent;
  870. }
  871. //not found - load from repo
  872. return LibraryManager.RetrieveItem(id);
  873. }
  874. /// <summary>
  875. /// Gets a value indicating whether this instance is folder.
  876. /// </summary>
  877. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  878. [IgnoreDataMember]
  879. public virtual bool IsFolder
  880. {
  881. get
  882. {
  883. return false;
  884. }
  885. }
  886. /// <summary>
  887. /// Determine if we have changed vs the passed in copy
  888. /// </summary>
  889. /// <param name="copy">The copy.</param>
  890. /// <returns><c>true</c> if the specified copy has changed; otherwise, <c>false</c>.</returns>
  891. /// <exception cref="System.ArgumentNullException"></exception>
  892. public virtual bool HasChanged(BaseItem copy)
  893. {
  894. if (copy == null)
  895. {
  896. throw new ArgumentNullException();
  897. }
  898. var changed = copy.DateModified != DateModified;
  899. if (changed)
  900. {
  901. Logger.Debug(Name + " changed - original creation: " + DateCreated + " new creation: " + copy.DateCreated + " original modified: " + DateModified + " new modified: " + copy.DateModified);
  902. }
  903. return changed;
  904. }
  905. /// <summary>
  906. /// Determines if the item is considered new based on user settings
  907. /// </summary>
  908. /// <returns><c>true</c> if [is recently added] [the specified user]; otherwise, <c>false</c>.</returns>
  909. /// <exception cref="System.ArgumentNullException"></exception>
  910. public bool IsRecentlyAdded()
  911. {
  912. return (DateTime.UtcNow - DateCreated).TotalDays < ConfigurationManager.Configuration.RecentItemDays;
  913. }
  914. /// <summary>
  915. /// Adds people to the item
  916. /// </summary>
  917. /// <param name="people">The people.</param>
  918. /// <exception cref="System.ArgumentNullException"></exception>
  919. public void AddPeople(IEnumerable<PersonInfo> people)
  920. {
  921. if (people == null)
  922. {
  923. throw new ArgumentNullException();
  924. }
  925. foreach (var person in people)
  926. {
  927. AddPerson(person);
  928. }
  929. }
  930. /// <summary>
  931. /// Adds a person to the item
  932. /// </summary>
  933. /// <param name="person">The person.</param>
  934. /// <exception cref="System.ArgumentNullException"></exception>
  935. public void AddPerson(PersonInfo person)
  936. {
  937. if (person == null)
  938. {
  939. throw new ArgumentNullException("person");
  940. }
  941. if (string.IsNullOrWhiteSpace(person.Name))
  942. {
  943. throw new ArgumentNullException();
  944. }
  945. if (People == null)
  946. {
  947. People = new List<PersonInfo> { person };
  948. return;
  949. }
  950. // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
  951. if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  952. {
  953. var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase));
  954. if (existing != null)
  955. {
  956. existing.Type = PersonType.GuestStar;
  957. return;
  958. }
  959. }
  960. if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
  961. {
  962. // Only add actors if there isn't an existing one of type Actor or GuestStar
  963. 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))))
  964. {
  965. People.Add(person);
  966. }
  967. }
  968. else
  969. {
  970. // Check for dupes based on the combination of Name and Type
  971. if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(person.Type, StringComparison.OrdinalIgnoreCase)))
  972. {
  973. People.Add(person);
  974. }
  975. }
  976. }
  977. /// <summary>
  978. /// Adds studios to the item
  979. /// </summary>
  980. /// <param name="studios">The studios.</param>
  981. /// <exception cref="System.ArgumentNullException"></exception>
  982. public void AddStudios(IEnumerable<string> studios)
  983. {
  984. if (studios == null)
  985. {
  986. throw new ArgumentNullException();
  987. }
  988. foreach (var name in studios)
  989. {
  990. AddStudio(name);
  991. }
  992. }
  993. /// <summary>
  994. /// Adds a studio to the item
  995. /// </summary>
  996. /// <param name="name">The name.</param>
  997. /// <exception cref="System.ArgumentNullException"></exception>
  998. public void AddStudio(string name)
  999. {
  1000. if (string.IsNullOrWhiteSpace(name))
  1001. {
  1002. throw new ArgumentNullException("name");
  1003. }
  1004. if (Studios == null)
  1005. {
  1006. Studios = new List<string>();
  1007. }
  1008. if (!Studios.Contains(name, StringComparer.OrdinalIgnoreCase))
  1009. {
  1010. Studios.Add(name);
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// Adds a tagline to the item
  1015. /// </summary>
  1016. /// <param name="name">The name.</param>
  1017. /// <exception cref="System.ArgumentNullException"></exception>
  1018. public void AddTagline(string name)
  1019. {
  1020. if (string.IsNullOrWhiteSpace(name))
  1021. {
  1022. throw new ArgumentNullException("name");
  1023. }
  1024. if (Taglines == null)
  1025. {
  1026. Taglines = new List<string>();
  1027. }
  1028. if (!Taglines.Contains(name, StringComparer.OrdinalIgnoreCase))
  1029. {
  1030. Taglines.Add(name);
  1031. }
  1032. }
  1033. /// <summary>
  1034. /// Adds a TrailerUrl to the item
  1035. /// </summary>
  1036. /// <param name="url">The URL.</param>
  1037. /// <exception cref="System.ArgumentNullException"></exception>
  1038. public void AddTrailerUrl(string url)
  1039. {
  1040. if (string.IsNullOrWhiteSpace(url))
  1041. {
  1042. throw new ArgumentNullException("url");
  1043. }
  1044. if (TrailerUrls == null)
  1045. {
  1046. TrailerUrls = new List<string>();
  1047. }
  1048. if (!TrailerUrls.Contains(url, StringComparer.OrdinalIgnoreCase))
  1049. {
  1050. TrailerUrls.Add(url);
  1051. }
  1052. }
  1053. /// <summary>
  1054. /// Adds a genre to the item
  1055. /// </summary>
  1056. /// <param name="name">The name.</param>
  1057. /// <exception cref="System.ArgumentNullException"></exception>
  1058. public void AddGenre(string name)
  1059. {
  1060. if (string.IsNullOrWhiteSpace(name))
  1061. {
  1062. throw new ArgumentNullException("name");
  1063. }
  1064. if (Genres == null)
  1065. {
  1066. Genres = new List<string>();
  1067. }
  1068. if (!Genres.Contains(name, StringComparer.OrdinalIgnoreCase))
  1069. {
  1070. Genres.Add(name);
  1071. }
  1072. }
  1073. /// <summary>
  1074. /// Adds the production location.
  1075. /// </summary>
  1076. /// <param name="location">The location.</param>
  1077. /// <exception cref="System.ArgumentNullException">location</exception>
  1078. public void AddProductionLocation(string location)
  1079. {
  1080. if (string.IsNullOrWhiteSpace(location))
  1081. {
  1082. throw new ArgumentNullException("location");
  1083. }
  1084. if (ProductionLocations == null)
  1085. {
  1086. ProductionLocations = new List<string>();
  1087. }
  1088. if (!ProductionLocations.Contains(location, StringComparer.OrdinalIgnoreCase))
  1089. {
  1090. ProductionLocations.Add(location);
  1091. }
  1092. }
  1093. /// <summary>
  1094. /// Adds genres to the item
  1095. /// </summary>
  1096. /// <param name="genres">The genres.</param>
  1097. /// <exception cref="System.ArgumentNullException"></exception>
  1098. public void AddGenres(IEnumerable<string> genres)
  1099. {
  1100. if (genres == null)
  1101. {
  1102. throw new ArgumentNullException();
  1103. }
  1104. foreach (var name in genres)
  1105. {
  1106. AddGenre(name);
  1107. }
  1108. }
  1109. /// <summary>
  1110. /// Marks the item as either played or unplayed
  1111. /// </summary>
  1112. /// <param name="user">The user.</param>
  1113. /// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
  1114. /// <param name="userManager">The user manager.</param>
  1115. /// <returns>Task.</returns>
  1116. /// <exception cref="System.ArgumentNullException"></exception>
  1117. public virtual async Task SetPlayedStatus(User user, bool wasPlayed, IUserDataRepository userManager)
  1118. {
  1119. if (user == null)
  1120. {
  1121. throw new ArgumentNullException();
  1122. }
  1123. var key = GetUserDataKey();
  1124. var data = await userManager.GetUserData(user.Id, key).ConfigureAwait(false);
  1125. if (wasPlayed)
  1126. {
  1127. data.PlayCount = Math.Max(data.PlayCount, 1);
  1128. if (!data.LastPlayedDate.HasValue)
  1129. {
  1130. data.LastPlayedDate = DateTime.UtcNow;
  1131. }
  1132. }
  1133. else
  1134. {
  1135. //I think it is okay to do this here.
  1136. // if this is only called when a user is manually forcing something to un-played
  1137. // then it probably is what we want to do...
  1138. data.PlayCount = 0;
  1139. data.PlaybackPositionTicks = 0;
  1140. data.LastPlayedDate = null;
  1141. }
  1142. data.Played = wasPlayed;
  1143. await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
  1144. }
  1145. /// <summary>
  1146. /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
  1147. /// </summary>
  1148. /// <returns>Task.</returns>
  1149. public virtual Task ChangedExternally()
  1150. {
  1151. return RefreshMetadata(CancellationToken.None);
  1152. }
  1153. /// <summary>
  1154. /// Finds a parent of a given type
  1155. /// </summary>
  1156. /// <typeparam name="T"></typeparam>
  1157. /// <returns>``0.</returns>
  1158. public T FindParent<T>()
  1159. where T : Folder
  1160. {
  1161. var parent = Parent;
  1162. while (parent != null)
  1163. {
  1164. var result = parent as T;
  1165. if (result != null)
  1166. {
  1167. return result;
  1168. }
  1169. parent = parent.Parent;
  1170. }
  1171. return null;
  1172. }
  1173. /// <summary>
  1174. /// Gets an image
  1175. /// </summary>
  1176. /// <param name="type">The type.</param>
  1177. /// <returns>System.String.</returns>
  1178. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1179. public string GetImage(ImageType type)
  1180. {
  1181. if (type == ImageType.Backdrop)
  1182. {
  1183. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1184. }
  1185. if (type == ImageType.Screenshot)
  1186. {
  1187. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1188. }
  1189. if (Images == null)
  1190. {
  1191. return null;
  1192. }
  1193. string val;
  1194. Images.TryGetValue(type, out val);
  1195. return val;
  1196. }
  1197. /// <summary>
  1198. /// Gets an image
  1199. /// </summary>
  1200. /// <param name="type">The type.</param>
  1201. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  1202. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1203. public bool HasImage(ImageType type)
  1204. {
  1205. if (type == ImageType.Backdrop)
  1206. {
  1207. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1208. }
  1209. if (type == ImageType.Screenshot)
  1210. {
  1211. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1212. }
  1213. return !string.IsNullOrEmpty(GetImage(type));
  1214. }
  1215. /// <summary>
  1216. /// Sets an image
  1217. /// </summary>
  1218. /// <param name="type">The type.</param>
  1219. /// <param name="path">The path.</param>
  1220. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1221. public void SetImage(ImageType type, string path)
  1222. {
  1223. if (type == ImageType.Backdrop)
  1224. {
  1225. throw new ArgumentException("Backdrops should be accessed using Item.Backdrops");
  1226. }
  1227. if (type == ImageType.Screenshot)
  1228. {
  1229. throw new ArgumentException("Screenshots should be accessed using Item.Screenshots");
  1230. }
  1231. var typeKey = type;
  1232. // If it's null remove the key from the dictionary
  1233. if (string.IsNullOrEmpty(path))
  1234. {
  1235. if (Images != null)
  1236. {
  1237. if (Images.ContainsKey(typeKey))
  1238. {
  1239. Images.Remove(typeKey);
  1240. }
  1241. }
  1242. }
  1243. else
  1244. {
  1245. // Ensure it exists
  1246. if (Images == null)
  1247. {
  1248. Images = new Dictionary<ImageType, string>();
  1249. }
  1250. Images[typeKey] = path;
  1251. }
  1252. }
  1253. /// <summary>
  1254. /// Deletes the image.
  1255. /// </summary>
  1256. /// <param name="type">The type.</param>
  1257. /// <returns>Task.</returns>
  1258. public async Task DeleteImage(ImageType type)
  1259. {
  1260. if (!HasImage(type))
  1261. {
  1262. return;
  1263. }
  1264. // Delete the source file
  1265. File.Delete(GetImage(type));
  1266. // Remove it from the item
  1267. SetImage(type, null);
  1268. // Refresh metadata
  1269. await RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
  1270. }
  1271. }
  1272. }