BaseItem.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.Channels;
  3. using MediaBrowser.Controller.Collections;
  4. using MediaBrowser.Controller.Configuration;
  5. using MediaBrowser.Controller.Drawing;
  6. using MediaBrowser.Controller.Library;
  7. using MediaBrowser.Controller.LiveTv;
  8. using MediaBrowser.Controller.Localization;
  9. using MediaBrowser.Controller.Persistence;
  10. using MediaBrowser.Controller.Providers;
  11. using MediaBrowser.Model.Configuration;
  12. using MediaBrowser.Model.Dto;
  13. using MediaBrowser.Model.Entities;
  14. using MediaBrowser.Model.Library;
  15. using MediaBrowser.Model.Logging;
  16. using MediaBrowser.Model.Users;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Globalization;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Runtime.Serialization;
  23. using System.Text;
  24. using System.Threading;
  25. using System.Threading.Tasks;
  26. using CommonIO;
  27. using MediaBrowser.Controller.Sorting;
  28. using MediaBrowser.Model.LiveTv;
  29. namespace MediaBrowser.Controller.Entities
  30. {
  31. /// <summary>
  32. /// Class BaseItem
  33. /// </summary>
  34. public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData, IHasMetadata, IHasLookupInfo<ItemLookupInfo>
  35. {
  36. protected BaseItem()
  37. {
  38. Tags = new List<string>();
  39. Genres = new List<string>();
  40. Studios = new List<string>();
  41. ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  42. LockedFields = new List<MetadataFields>();
  43. ImageInfos = new List<ItemImageInfo>();
  44. }
  45. public static readonly char[] SlugReplaceChars = { '?', '/', '&' };
  46. public static char SlugChar = '-';
  47. /// <summary>
  48. /// The supported image extensions
  49. /// </summary>
  50. public static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".tbn", ".gif" };
  51. public static readonly List<string> SupportedImageExtensionsList = SupportedImageExtensions.ToList();
  52. /// <summary>
  53. /// The trailer folder name
  54. /// </summary>
  55. public static string TrailerFolderName = "trailers";
  56. public static string ThemeSongsFolderName = "theme-music";
  57. public static string ThemeSongFilename = "theme";
  58. public static string ThemeVideosFolderName = "backdrops";
  59. [IgnoreDataMember]
  60. public string PreferredMetadataCountryCode { get; set; }
  61. [IgnoreDataMember]
  62. public string PreferredMetadataLanguage { get; set; }
  63. public List<ItemImageInfo> ImageInfos { get; set; }
  64. /// <summary>
  65. /// Gets or sets the channel identifier.
  66. /// </summary>
  67. /// <value>The channel identifier.</value>
  68. [IgnoreDataMember]
  69. public string ChannelId { get; set; }
  70. [IgnoreDataMember]
  71. public virtual bool SupportsAddingToPlaylist
  72. {
  73. get
  74. {
  75. return false;
  76. }
  77. }
  78. [IgnoreDataMember]
  79. public virtual bool AlwaysScanInternalMetadataPath
  80. {
  81. get { return false; }
  82. }
  83. /// <summary>
  84. /// Gets a value indicating whether this instance is in mixed folder.
  85. /// </summary>
  86. /// <value><c>true</c> if this instance is in mixed folder; otherwise, <c>false</c>.</value>
  87. [IgnoreDataMember]
  88. public bool IsInMixedFolder { get; set; }
  89. [IgnoreDataMember]
  90. public virtual bool SupportsRemoteImageDownloading
  91. {
  92. get
  93. {
  94. return true;
  95. }
  96. }
  97. private string _name;
  98. /// <summary>
  99. /// Gets or sets the name.
  100. /// </summary>
  101. /// <value>The name.</value>
  102. [IgnoreDataMember]
  103. public virtual string Name
  104. {
  105. get
  106. {
  107. return _name;
  108. }
  109. set
  110. {
  111. _name = value;
  112. // lazy load this again
  113. _sortName = null;
  114. }
  115. }
  116. [IgnoreDataMember]
  117. public string SlugName
  118. {
  119. get
  120. {
  121. var name = Name;
  122. if (string.IsNullOrWhiteSpace(name))
  123. {
  124. return string.Empty;
  125. }
  126. return SlugReplaceChars.Aggregate(name, (current, c) => current.Replace(c, SlugChar));
  127. }
  128. }
  129. public string OriginalTitle { get; set; }
  130. /// <summary>
  131. /// Gets or sets the id.
  132. /// </summary>
  133. /// <value>The id.</value>
  134. [IgnoreDataMember]
  135. public Guid Id { get; set; }
  136. /// <summary>
  137. /// Gets or sets a value indicating whether this instance is hd.
  138. /// </summary>
  139. /// <value><c>true</c> if this instance is hd; otherwise, <c>false</c>.</value>
  140. [IgnoreDataMember]
  141. public bool? IsHD { get; set; }
  142. /// <summary>
  143. /// Gets or sets the audio.
  144. /// </summary>
  145. /// <value>The audio.</value>
  146. [IgnoreDataMember]
  147. public ProgramAudio? Audio { get; set; }
  148. /// <summary>
  149. /// Return the id that should be used to key display prefs for this item.
  150. /// Default is based on the type for everything except actual generic folders.
  151. /// </summary>
  152. /// <value>The display prefs id.</value>
  153. [IgnoreDataMember]
  154. public virtual Guid DisplayPreferencesId
  155. {
  156. get
  157. {
  158. var thisType = GetType();
  159. return thisType == typeof(Folder) ? Id : thisType.FullName.GetMD5();
  160. }
  161. }
  162. /// <summary>
  163. /// Gets or sets the path.
  164. /// </summary>
  165. /// <value>The path.</value>
  166. [IgnoreDataMember]
  167. public virtual string Path { get; set; }
  168. [IgnoreDataMember]
  169. public bool IsOffline { get; set; }
  170. [IgnoreDataMember]
  171. public virtual SourceType SourceType { get; set; }
  172. /// <summary>
  173. /// Returns the folder containing the item.
  174. /// If the item is a folder, it returns the folder itself
  175. /// </summary>
  176. [IgnoreDataMember]
  177. public virtual string ContainingFolderPath
  178. {
  179. get
  180. {
  181. if (IsFolder)
  182. {
  183. return Path;
  184. }
  185. return System.IO.Path.GetDirectoryName(Path);
  186. }
  187. }
  188. /// <summary>
  189. /// Gets or sets the name of the service.
  190. /// </summary>
  191. /// <value>The name of the service.</value>
  192. [IgnoreDataMember]
  193. public string ServiceName { get; set; }
  194. /// <summary>
  195. /// If this content came from an external service, the id of the content on that service
  196. /// </summary>
  197. [IgnoreDataMember]
  198. public string ExternalId
  199. {
  200. get { return this.GetProviderId("ProviderExternalId"); }
  201. set
  202. {
  203. this.SetProviderId("ProviderExternalId", value);
  204. }
  205. }
  206. /// <summary>
  207. /// Gets or sets the etag.
  208. /// </summary>
  209. /// <value>The etag.</value>
  210. [IgnoreDataMember]
  211. public string ExternalEtag { get; set; }
  212. [IgnoreDataMember]
  213. public virtual bool IsHidden
  214. {
  215. get
  216. {
  217. return false;
  218. }
  219. }
  220. [IgnoreDataMember]
  221. public virtual bool IsOwnedItem
  222. {
  223. get
  224. {
  225. // Local trailer, special feature, theme video, etc.
  226. // An item that belongs to another item but is not part of the Parent-Child tree
  227. return !IsFolder && ParentId == Guid.Empty && LocationType == LocationType.FileSystem;
  228. }
  229. }
  230. /// <summary>
  231. /// Gets or sets the type of the location.
  232. /// </summary>
  233. /// <value>The type of the location.</value>
  234. [IgnoreDataMember]
  235. public virtual LocationType LocationType
  236. {
  237. get
  238. {
  239. if (IsOffline)
  240. {
  241. return LocationType.Offline;
  242. }
  243. if (string.IsNullOrWhiteSpace(Path))
  244. {
  245. if (SourceType == SourceType.Channel)
  246. {
  247. return LocationType.Remote;
  248. }
  249. return LocationType.Virtual;
  250. }
  251. return FileSystem.IsPathFile(Path) ? LocationType.FileSystem : LocationType.Remote;
  252. }
  253. }
  254. [IgnoreDataMember]
  255. public virtual bool SupportsLocalMetadata
  256. {
  257. get
  258. {
  259. if (SourceType == SourceType.Channel)
  260. {
  261. return false;
  262. }
  263. var locationType = LocationType;
  264. return locationType != LocationType.Remote && locationType != LocationType.Virtual;
  265. }
  266. }
  267. [IgnoreDataMember]
  268. public virtual string FileNameWithoutExtension
  269. {
  270. get
  271. {
  272. if (LocationType == LocationType.FileSystem)
  273. {
  274. return System.IO.Path.GetFileNameWithoutExtension(Path);
  275. }
  276. return null;
  277. }
  278. }
  279. [IgnoreDataMember]
  280. public virtual bool EnableAlphaNumericSorting
  281. {
  282. get
  283. {
  284. return true;
  285. }
  286. }
  287. private List<Tuple<StringBuilder, bool>> GetSortChunks(string s1)
  288. {
  289. var list = new List<Tuple<StringBuilder, bool>>();
  290. int thisMarker = 0, thisNumericChunk = 0;
  291. while (thisMarker < s1.Length)
  292. {
  293. if (thisMarker >= s1.Length)
  294. {
  295. break;
  296. }
  297. char thisCh = s1[thisMarker];
  298. StringBuilder thisChunk = new StringBuilder();
  299. while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || SortHelper.InChunk(thisCh, thisChunk[0])))
  300. {
  301. thisChunk.Append(thisCh);
  302. thisMarker++;
  303. if (thisMarker < s1.Length)
  304. {
  305. thisCh = s1[thisMarker];
  306. }
  307. }
  308. var isNumeric = thisChunk.Length > 0 && char.IsDigit(thisChunk[0]);
  309. list.Add(new Tuple<StringBuilder, bool>(thisChunk, isNumeric));
  310. }
  311. return list;
  312. }
  313. /// <summary>
  314. /// This is just a helper for convenience
  315. /// </summary>
  316. /// <value>The primary image path.</value>
  317. [IgnoreDataMember]
  318. public string PrimaryImagePath
  319. {
  320. get { return this.GetImagePath(ImageType.Primary); }
  321. }
  322. public virtual bool IsInternetMetadataEnabled()
  323. {
  324. return ConfigurationManager.Configuration.EnableInternetProviders;
  325. }
  326. public virtual bool CanDelete()
  327. {
  328. if (SourceType == SourceType.Channel)
  329. {
  330. return false;
  331. }
  332. var locationType = LocationType;
  333. return locationType != LocationType.Remote &&
  334. locationType != LocationType.Virtual;
  335. }
  336. public virtual bool IsAuthorizedToDelete(User user)
  337. {
  338. return user.Policy.EnableContentDeletion;
  339. }
  340. public bool CanDelete(User user)
  341. {
  342. return CanDelete() && IsAuthorizedToDelete(user);
  343. }
  344. public virtual bool CanDownload()
  345. {
  346. return false;
  347. }
  348. public virtual bool IsAuthorizedToDownload(User user)
  349. {
  350. return user.Policy.EnableContentDownloading;
  351. }
  352. public bool CanDownload(User user)
  353. {
  354. return CanDownload() && IsAuthorizedToDownload(user);
  355. }
  356. /// <summary>
  357. /// Gets or sets the date created.
  358. /// </summary>
  359. /// <value>The date created.</value>
  360. [IgnoreDataMember]
  361. public DateTime DateCreated { get; set; }
  362. /// <summary>
  363. /// Gets or sets the date modified.
  364. /// </summary>
  365. /// <value>The date modified.</value>
  366. [IgnoreDataMember]
  367. public DateTime DateModified { get; set; }
  368. [IgnoreDataMember]
  369. public DateTime DateLastSaved { get; set; }
  370. [IgnoreDataMember]
  371. public DateTime DateLastRefreshed { get; set; }
  372. [IgnoreDataMember]
  373. public DateTime? DateModifiedDuringLastRefresh { get; set; }
  374. /// <summary>
  375. /// The logger
  376. /// </summary>
  377. public static ILogger Logger { get; set; }
  378. public static ILibraryManager LibraryManager { get; set; }
  379. public static IServerConfigurationManager ConfigurationManager { get; set; }
  380. public static IProviderManager ProviderManager { get; set; }
  381. public static ILocalizationManager LocalizationManager { get; set; }
  382. public static IItemRepository ItemRepository { get; set; }
  383. public static IFileSystem FileSystem { get; set; }
  384. public static IUserDataManager UserDataManager { get; set; }
  385. public static ILiveTvManager LiveTvManager { get; set; }
  386. public static IChannelManager ChannelManager { get; set; }
  387. public static ICollectionManager CollectionManager { get; set; }
  388. public static IImageProcessor ImageProcessor { get; set; }
  389. public static IMediaSourceManager MediaSourceManager { get; set; }
  390. /// <summary>
  391. /// Returns a <see cref="System.String" /> that represents this instance.
  392. /// </summary>
  393. /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
  394. public override string ToString()
  395. {
  396. return Name;
  397. }
  398. [IgnoreDataMember]
  399. public bool IsLocked { get; set; }
  400. /// <summary>
  401. /// Gets or sets the locked fields.
  402. /// </summary>
  403. /// <value>The locked fields.</value>
  404. [IgnoreDataMember]
  405. public List<MetadataFields> LockedFields { get; set; }
  406. /// <summary>
  407. /// Gets the type of the media.
  408. /// </summary>
  409. /// <value>The type of the media.</value>
  410. [IgnoreDataMember]
  411. public virtual string MediaType
  412. {
  413. get
  414. {
  415. return null;
  416. }
  417. }
  418. [IgnoreDataMember]
  419. public virtual IEnumerable<string> PhysicalLocations
  420. {
  421. get
  422. {
  423. var locationType = LocationType;
  424. if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
  425. {
  426. return new string[] { };
  427. }
  428. return new[] { Path };
  429. }
  430. }
  431. private string _forcedSortName;
  432. /// <summary>
  433. /// Gets or sets the name of the forced sort.
  434. /// </summary>
  435. /// <value>The name of the forced sort.</value>
  436. [IgnoreDataMember]
  437. public string ForcedSortName
  438. {
  439. get { return _forcedSortName; }
  440. set { _forcedSortName = value; _sortName = null; }
  441. }
  442. private string _sortName;
  443. /// <summary>
  444. /// Gets the name of the sort.
  445. /// </summary>
  446. /// <value>The name of the sort.</value>
  447. [IgnoreDataMember]
  448. public string SortName
  449. {
  450. get
  451. {
  452. if (_sortName == null)
  453. {
  454. if (!string.IsNullOrWhiteSpace(ForcedSortName))
  455. {
  456. // Need the ToLower because that's what CreateSortName does
  457. _sortName = ModifySortChunks(ForcedSortName).ToLower();
  458. }
  459. else
  460. {
  461. _sortName = CreateSortName();
  462. }
  463. }
  464. return _sortName;
  465. }
  466. set
  467. {
  468. _sortName = value;
  469. }
  470. }
  471. public string GetInternalMetadataPath()
  472. {
  473. var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath;
  474. return GetInternalMetadataPath(basePath);
  475. }
  476. protected virtual string GetInternalMetadataPath(string basePath)
  477. {
  478. if (SourceType == SourceType.Channel)
  479. {
  480. return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
  481. }
  482. var idString = Id.ToString("N");
  483. basePath = System.IO.Path.Combine(basePath, "library");
  484. return System.IO.Path.Combine(basePath, idString.Substring(0, 2), idString);
  485. }
  486. /// <summary>
  487. /// Creates the name of the sort.
  488. /// </summary>
  489. /// <returns>System.String.</returns>
  490. protected virtual string CreateSortName()
  491. {
  492. if (Name == null) return null; //some items may not have name filled in properly
  493. if (!EnableAlphaNumericSorting)
  494. {
  495. return Name.TrimStart();
  496. }
  497. var sortable = Name.Trim().ToLower();
  498. sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
  499. sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
  500. foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
  501. {
  502. var searchLower = search.ToLower();
  503. // Remove from beginning if a space follows
  504. if (sortable.StartsWith(searchLower + " "))
  505. {
  506. sortable = sortable.Remove(0, searchLower.Length + 1);
  507. }
  508. // Remove from middle if surrounded by spaces
  509. sortable = sortable.Replace(" " + searchLower + " ", " ");
  510. // Remove from end if followed by a space
  511. if (sortable.EndsWith(" " + searchLower))
  512. {
  513. sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
  514. }
  515. }
  516. return ModifySortChunks(sortable);
  517. }
  518. private string ModifySortChunks(string name)
  519. {
  520. var chunks = GetSortChunks(name);
  521. var builder = new StringBuilder();
  522. foreach (var chunk in chunks)
  523. {
  524. var chunkBuilder = chunk.Item1;
  525. // This chunk is numeric
  526. if (chunk.Item2)
  527. {
  528. while (chunkBuilder.Length < 10)
  529. {
  530. chunkBuilder.Insert(0, '0');
  531. }
  532. }
  533. builder.Append(chunkBuilder);
  534. }
  535. //Logger.Debug("ModifySortChunks Start: {0} End: {1}", name, builder.ToString());
  536. return builder.ToString().RemoveDiacritics();
  537. }
  538. [IgnoreDataMember]
  539. public Guid ParentId { get; set; }
  540. /// <summary>
  541. /// Gets or sets the parent.
  542. /// </summary>
  543. /// <value>The parent.</value>
  544. [IgnoreDataMember]
  545. public Folder Parent
  546. {
  547. get { return GetParent() as Folder; }
  548. set
  549. {
  550. }
  551. }
  552. public void SetParent(Folder parent)
  553. {
  554. ParentId = parent == null ? Guid.Empty : parent.Id;
  555. }
  556. [IgnoreDataMember]
  557. public IEnumerable<Folder> Parents
  558. {
  559. get { return GetParents().OfType<Folder>(); }
  560. }
  561. public BaseItem GetParent()
  562. {
  563. if (ParentId != Guid.Empty)
  564. {
  565. return LibraryManager.GetItemById(ParentId);
  566. }
  567. return null;
  568. }
  569. public IEnumerable<BaseItem> GetParents()
  570. {
  571. var parent = GetParent();
  572. while (parent != null)
  573. {
  574. yield return parent;
  575. parent = parent.GetParent();
  576. }
  577. }
  578. /// <summary>
  579. /// Finds a parent of a given type
  580. /// </summary>
  581. /// <typeparam name="T"></typeparam>
  582. /// <returns>``0.</returns>
  583. public T FindParent<T>()
  584. where T : Folder
  585. {
  586. return GetParents().OfType<T>().FirstOrDefault();
  587. }
  588. [IgnoreDataMember]
  589. public virtual Guid? DisplayParentId
  590. {
  591. get
  592. {
  593. if (ParentId == Guid.Empty)
  594. {
  595. return null;
  596. }
  597. return ParentId;
  598. }
  599. }
  600. [IgnoreDataMember]
  601. public BaseItem DisplayParent
  602. {
  603. get
  604. {
  605. var id = DisplayParentId;
  606. if (!id.HasValue || id.Value == Guid.Empty)
  607. {
  608. return null;
  609. }
  610. return LibraryManager.GetItemById(id.Value);
  611. }
  612. }
  613. /// <summary>
  614. /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
  615. /// </summary>
  616. /// <value>The premiere date.</value>
  617. [IgnoreDataMember]
  618. public DateTime? PremiereDate { get; set; }
  619. /// <summary>
  620. /// Gets or sets the end date.
  621. /// </summary>
  622. /// <value>The end date.</value>
  623. [IgnoreDataMember]
  624. public DateTime? EndDate { get; set; }
  625. /// <summary>
  626. /// Gets or sets the display type of the media.
  627. /// </summary>
  628. /// <value>The display type of the media.</value>
  629. [IgnoreDataMember]
  630. public string DisplayMediaType { get; set; }
  631. /// <summary>
  632. /// Gets or sets the official rating.
  633. /// </summary>
  634. /// <value>The official rating.</value>
  635. [IgnoreDataMember]
  636. public string OfficialRating { get; set; }
  637. /// <summary>
  638. /// Gets or sets the critic rating.
  639. /// </summary>
  640. /// <value>The critic rating.</value>
  641. [IgnoreDataMember]
  642. public float? CriticRating { get; set; }
  643. /// <summary>
  644. /// Gets or sets the critic rating summary.
  645. /// </summary>
  646. /// <value>The critic rating summary.</value>
  647. [IgnoreDataMember]
  648. public string CriticRatingSummary { get; set; }
  649. /// <summary>
  650. /// Gets or sets the official rating description.
  651. /// </summary>
  652. /// <value>The official rating description.</value>
  653. [IgnoreDataMember]
  654. public string OfficialRatingDescription { get; set; }
  655. /// <summary>
  656. /// Gets or sets the custom rating.
  657. /// </summary>
  658. /// <value>The custom rating.</value>
  659. [IgnoreDataMember]
  660. public string CustomRating { get; set; }
  661. /// <summary>
  662. /// Gets or sets the overview.
  663. /// </summary>
  664. /// <value>The overview.</value>
  665. [IgnoreDataMember]
  666. public string Overview { get; set; }
  667. /// <summary>
  668. /// Gets or sets the studios.
  669. /// </summary>
  670. /// <value>The studios.</value>
  671. [IgnoreDataMember]
  672. public List<string> Studios { get; set; }
  673. /// <summary>
  674. /// Gets or sets the genres.
  675. /// </summary>
  676. /// <value>The genres.</value>
  677. [IgnoreDataMember]
  678. public List<string> Genres { get; set; }
  679. /// <summary>
  680. /// Gets or sets the tags.
  681. /// </summary>
  682. /// <value>The tags.</value>
  683. [IgnoreDataMember]
  684. public List<string> Tags { get; set; }
  685. /// <summary>
  686. /// Gets or sets the home page URL.
  687. /// </summary>
  688. /// <value>The home page URL.</value>
  689. [IgnoreDataMember]
  690. public string HomePageUrl { get; set; }
  691. /// <summary>
  692. /// Gets or sets the community rating.
  693. /// </summary>
  694. /// <value>The community rating.</value>
  695. [IgnoreDataMember]
  696. public float? CommunityRating { get; set; }
  697. /// <summary>
  698. /// Gets or sets the community rating vote count.
  699. /// </summary>
  700. /// <value>The community rating vote count.</value>
  701. [IgnoreDataMember]
  702. public int? VoteCount { get; set; }
  703. /// <summary>
  704. /// Gets or sets the run time ticks.
  705. /// </summary>
  706. /// <value>The run time ticks.</value>
  707. [IgnoreDataMember]
  708. public long? RunTimeTicks { get; set; }
  709. /// <summary>
  710. /// Gets or sets the production year.
  711. /// </summary>
  712. /// <value>The production year.</value>
  713. [IgnoreDataMember]
  714. public int? ProductionYear { get; set; }
  715. /// <summary>
  716. /// If the item is part of a series, this is it's number in the series.
  717. /// This could be episode number, album track number, etc.
  718. /// </summary>
  719. /// <value>The index number.</value>
  720. [IgnoreDataMember]
  721. public int? IndexNumber { get; set; }
  722. /// <summary>
  723. /// For an episode this could be the season number, or for a song this could be the disc number.
  724. /// </summary>
  725. /// <value>The parent index number.</value>
  726. [IgnoreDataMember]
  727. public int? ParentIndexNumber { get; set; }
  728. [IgnoreDataMember]
  729. public string OfficialRatingForComparison
  730. {
  731. get
  732. {
  733. if (!string.IsNullOrWhiteSpace(OfficialRating))
  734. {
  735. return OfficialRating;
  736. }
  737. var parent = DisplayParent;
  738. if (parent != null)
  739. {
  740. return parent.OfficialRatingForComparison;
  741. }
  742. return null;
  743. }
  744. }
  745. [IgnoreDataMember]
  746. public string CustomRatingForComparison
  747. {
  748. get
  749. {
  750. if (!string.IsNullOrWhiteSpace(CustomRating))
  751. {
  752. return CustomRating;
  753. }
  754. var parent = DisplayParent;
  755. if (parent != null)
  756. {
  757. return parent.CustomRatingForComparison;
  758. }
  759. return null;
  760. }
  761. }
  762. /// <summary>
  763. /// Gets the play access.
  764. /// </summary>
  765. /// <param name="user">The user.</param>
  766. /// <returns>PlayAccess.</returns>
  767. public PlayAccess GetPlayAccess(User user)
  768. {
  769. if (!user.Policy.EnableMediaPlayback)
  770. {
  771. return PlayAccess.None;
  772. }
  773. //if (!user.IsParentalScheduleAllowed())
  774. //{
  775. // return PlayAccess.None;
  776. //}
  777. return PlayAccess.Full;
  778. }
  779. /// <summary>
  780. /// Loads the theme songs.
  781. /// </summary>
  782. /// <returns>List{Audio.Audio}.</returns>
  783. private IEnumerable<Audio.Audio> LoadThemeSongs(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
  784. {
  785. var files = fileSystemChildren.Where(i => i.IsDirectory)
  786. .Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  787. .SelectMany(i => directoryService.GetFiles(i.FullName))
  788. .ToList();
  789. // Support plex/xbmc convention
  790. files.AddRange(fileSystemChildren
  791. .Where(i => !i.IsDirectory && string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase))
  792. );
  793. return LibraryManager.ResolvePaths(files, directoryService, null)
  794. .OfType<Audio.Audio>()
  795. .Select(audio =>
  796. {
  797. // Try to retrieve it from the db. If we don't find it, use the resolved version
  798. var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio;
  799. if (dbItem != null)
  800. {
  801. audio = dbItem;
  802. }
  803. audio.ExtraType = ExtraType.ThemeSong;
  804. return audio;
  805. // Sort them so that the list can be easily compared for changes
  806. }).OrderBy(i => i.Path).ToList();
  807. }
  808. /// <summary>
  809. /// Loads the video backdrops.
  810. /// </summary>
  811. /// <returns>List{Video}.</returns>
  812. private IEnumerable<Video> LoadThemeVideos(IEnumerable<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
  813. {
  814. var files = fileSystemChildren.Where(i => i.IsDirectory)
  815. .Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  816. .SelectMany(i => directoryService.GetFiles(i.FullName));
  817. return LibraryManager.ResolvePaths(files, directoryService, null)
  818. .OfType<Video>()
  819. .Select(item =>
  820. {
  821. // Try to retrieve it from the db. If we don't find it, use the resolved version
  822. var dbItem = LibraryManager.GetItemById(item.Id) as Video;
  823. if (dbItem != null)
  824. {
  825. item = dbItem;
  826. }
  827. item.ExtraType = ExtraType.ThemeVideo;
  828. return item;
  829. // Sort them so that the list can be easily compared for changes
  830. }).OrderBy(i => i.Path).ToList();
  831. }
  832. public Task RefreshMetadata(CancellationToken cancellationToken)
  833. {
  834. return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken);
  835. }
  836. /// <summary>
  837. /// Overrides the base implementation to refresh metadata for local trailers
  838. /// </summary>
  839. /// <param name="options">The options.</param>
  840. /// <param name="cancellationToken">The cancellation token.</param>
  841. /// <returns>true if a provider reports we changed</returns>
  842. public async Task<ItemUpdateType> RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken)
  843. {
  844. var locationType = LocationType;
  845. var requiresSave = false;
  846. if (SupportsOwnedItems)
  847. {
  848. try
  849. {
  850. var files = locationType != LocationType.Remote && locationType != LocationType.Virtual ?
  851. GetFileSystemChildren(options.DirectoryService).ToList() :
  852. new List<FileSystemMetadata>();
  853. var ownedItemsChanged = await RefreshedOwnedItems(options, files, cancellationToken).ConfigureAwait(false);
  854. if (ownedItemsChanged)
  855. {
  856. requiresSave = true;
  857. }
  858. }
  859. catch (Exception ex)
  860. {
  861. Logger.ErrorException("Error refreshing owned items for {0}", ex, Path ?? Name);
  862. }
  863. }
  864. var refreshOptions = requiresSave
  865. ? new MetadataRefreshOptions(options)
  866. {
  867. ForceSave = true
  868. }
  869. : options;
  870. var result = await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false);
  871. return result;
  872. }
  873. [IgnoreDataMember]
  874. protected virtual bool SupportsOwnedItems
  875. {
  876. get { return IsFolder || GetParent() != null; }
  877. }
  878. [IgnoreDataMember]
  879. public virtual bool SupportsPeople
  880. {
  881. get { return true; }
  882. }
  883. /// <summary>
  884. /// Refreshes owned items such as trailers, theme videos, special features, etc.
  885. /// Returns true or false indicating if changes were found.
  886. /// </summary>
  887. /// <param name="options"></param>
  888. /// <param name="fileSystemChildren"></param>
  889. /// <param name="cancellationToken"></param>
  890. /// <returns></returns>
  891. protected virtual async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  892. {
  893. var themeSongsChanged = false;
  894. var themeVideosChanged = false;
  895. var localTrailersChanged = false;
  896. if (LocationType == LocationType.FileSystem && GetParent() != null)
  897. {
  898. var hasThemeMedia = this as IHasThemeMedia;
  899. if (hasThemeMedia != null)
  900. {
  901. if (!IsInMixedFolder)
  902. {
  903. themeSongsChanged = await RefreshThemeSongs(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  904. themeVideosChanged = await RefreshThemeVideos(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  905. }
  906. }
  907. var hasTrailers = this as IHasTrailers;
  908. if (hasTrailers != null)
  909. {
  910. localTrailersChanged = await RefreshLocalTrailers(hasTrailers, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  911. }
  912. }
  913. return themeSongsChanged || themeVideosChanged || localTrailersChanged;
  914. }
  915. protected virtual IEnumerable<FileSystemMetadata> GetFileSystemChildren(IDirectoryService directoryService)
  916. {
  917. var path = ContainingFolderPath;
  918. return directoryService.GetFileSystemEntries(path);
  919. }
  920. private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  921. {
  922. var newItems = LibraryManager.FindTrailers(this, fileSystemChildren, options.DirectoryService).ToList();
  923. var newItemIds = newItems.Select(i => i.Id).ToList();
  924. var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
  925. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  926. await Task.WhenAll(tasks).ConfigureAwait(false);
  927. item.LocalTrailerIds = newItemIds;
  928. return itemsChanged;
  929. }
  930. private async Task<bool> RefreshThemeVideos(IHasThemeMedia item, MetadataRefreshOptions options, IEnumerable<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  931. {
  932. var newThemeVideos = LoadThemeVideos(fileSystemChildren, options.DirectoryService).ToList();
  933. var newThemeVideoIds = newThemeVideos.Select(i => i.Id).ToList();
  934. var themeVideosChanged = !item.ThemeVideoIds.SequenceEqual(newThemeVideoIds);
  935. var tasks = newThemeVideos.Select(i =>
  936. {
  937. var subOptions = new MetadataRefreshOptions(options);
  938. if (!i.IsThemeMedia)
  939. {
  940. i.ExtraType = ExtraType.ThemeVideo;
  941. subOptions.ForceSave = true;
  942. }
  943. return i.RefreshMetadata(subOptions, cancellationToken);
  944. });
  945. await Task.WhenAll(tasks).ConfigureAwait(false);
  946. item.ThemeVideoIds = newThemeVideoIds;
  947. return themeVideosChanged;
  948. }
  949. /// <summary>
  950. /// Refreshes the theme songs.
  951. /// </summary>
  952. private async Task<bool> RefreshThemeSongs(IHasThemeMedia item, MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  953. {
  954. var newThemeSongs = LoadThemeSongs(fileSystemChildren, options.DirectoryService).ToList();
  955. var newThemeSongIds = newThemeSongs.Select(i => i.Id).ToList();
  956. var themeSongsChanged = !item.ThemeSongIds.SequenceEqual(newThemeSongIds);
  957. var tasks = newThemeSongs.Select(i =>
  958. {
  959. var subOptions = new MetadataRefreshOptions(options);
  960. if (!i.IsThemeMedia)
  961. {
  962. i.ExtraType = ExtraType.ThemeSong;
  963. subOptions.ForceSave = true;
  964. }
  965. return i.RefreshMetadata(subOptions, cancellationToken);
  966. });
  967. await Task.WhenAll(tasks).ConfigureAwait(false);
  968. item.ThemeSongIds = newThemeSongIds;
  969. return themeSongsChanged;
  970. }
  971. /// <summary>
  972. /// Gets or sets the provider ids.
  973. /// </summary>
  974. /// <value>The provider ids.</value>
  975. public Dictionary<string, string> ProviderIds { get; set; }
  976. [IgnoreDataMember]
  977. public virtual Folder LatestItemsIndexContainer
  978. {
  979. get { return null; }
  980. }
  981. [IgnoreDataMember]
  982. public virtual string PresentationUniqueKey
  983. {
  984. get { return Id.ToString("N"); }
  985. }
  986. private string _userDataKey;
  987. /// <summary>
  988. /// Gets the user data key.
  989. /// </summary>
  990. /// <returns>System.String.</returns>
  991. public string GetUserDataKey()
  992. {
  993. if (string.IsNullOrWhiteSpace(_userDataKey))
  994. {
  995. var key = GetUserDataKeys().First();
  996. _userDataKey = key;
  997. return key;
  998. }
  999. return _userDataKey;
  1000. }
  1001. public virtual List<string> GetUserDataKeys()
  1002. {
  1003. var list = new List<string>();
  1004. if (SourceType == SourceType.Channel)
  1005. {
  1006. if (!string.IsNullOrWhiteSpace(ExternalId))
  1007. {
  1008. list.Add(ExternalId);
  1009. }
  1010. }
  1011. list.Add(Id.ToString());
  1012. return list;
  1013. }
  1014. internal virtual bool IsValidFromResolver(BaseItem newItem)
  1015. {
  1016. var current = this;
  1017. return current.IsInMixedFolder == newItem.IsInMixedFolder;
  1018. }
  1019. public void AfterMetadataRefresh()
  1020. {
  1021. _sortName = null;
  1022. _userDataKey = null;
  1023. }
  1024. /// <summary>
  1025. /// Gets the preferred metadata language.
  1026. /// </summary>
  1027. /// <returns>System.String.</returns>
  1028. public string GetPreferredMetadataLanguage()
  1029. {
  1030. string lang = PreferredMetadataLanguage;
  1031. if (string.IsNullOrWhiteSpace(lang))
  1032. {
  1033. lang = GetParents()
  1034. .Select(i => i.PreferredMetadataLanguage)
  1035. .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
  1036. }
  1037. if (string.IsNullOrWhiteSpace(lang))
  1038. {
  1039. lang = LibraryManager.GetCollectionFolders(this)
  1040. .Select(i => i.PreferredMetadataLanguage)
  1041. .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
  1042. }
  1043. if (string.IsNullOrWhiteSpace(lang))
  1044. {
  1045. lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
  1046. }
  1047. return lang;
  1048. }
  1049. /// <summary>
  1050. /// Gets the preferred metadata language.
  1051. /// </summary>
  1052. /// <returns>System.String.</returns>
  1053. public string GetPreferredMetadataCountryCode()
  1054. {
  1055. string lang = PreferredMetadataCountryCode;
  1056. if (string.IsNullOrWhiteSpace(lang))
  1057. {
  1058. lang = GetParents()
  1059. .Select(i => i.PreferredMetadataCountryCode)
  1060. .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
  1061. }
  1062. if (string.IsNullOrWhiteSpace(lang))
  1063. {
  1064. lang = LibraryManager.GetCollectionFolders(this)
  1065. .Select(i => i.PreferredMetadataCountryCode)
  1066. .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
  1067. }
  1068. if (string.IsNullOrWhiteSpace(lang))
  1069. {
  1070. lang = ConfigurationManager.Configuration.MetadataCountryCode;
  1071. }
  1072. return lang;
  1073. }
  1074. public virtual bool IsSaveLocalMetadataEnabled()
  1075. {
  1076. if (SourceType == SourceType.Channel)
  1077. {
  1078. return false;
  1079. }
  1080. return ConfigurationManager.Configuration.SaveLocalMeta;
  1081. }
  1082. /// <summary>
  1083. /// Determines if a given user has access to this item
  1084. /// </summary>
  1085. /// <param name="user">The user.</param>
  1086. /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
  1087. /// <exception cref="System.ArgumentNullException">user</exception>
  1088. public bool IsParentalAllowed(User user)
  1089. {
  1090. if (user == null)
  1091. {
  1092. throw new ArgumentNullException("user");
  1093. }
  1094. if (!IsVisibleViaTags(user))
  1095. {
  1096. return false;
  1097. }
  1098. var maxAllowedRating = user.Policy.MaxParentalRating;
  1099. if (maxAllowedRating == null)
  1100. {
  1101. return true;
  1102. }
  1103. var rating = CustomRatingForComparison;
  1104. if (string.IsNullOrWhiteSpace(rating))
  1105. {
  1106. rating = OfficialRatingForComparison;
  1107. }
  1108. if (string.IsNullOrWhiteSpace(rating))
  1109. {
  1110. return !GetBlockUnratedValue(user.Policy);
  1111. }
  1112. var value = LocalizationManager.GetRatingLevel(rating);
  1113. // Could not determine the integer value
  1114. if (!value.HasValue)
  1115. {
  1116. var isAllowed = !GetBlockUnratedValue(user.Policy);
  1117. if (!isAllowed)
  1118. {
  1119. Logger.Debug("{0} has an unrecognized parental rating of {1}.", Name, rating);
  1120. }
  1121. return isAllowed;
  1122. }
  1123. return value.Value <= maxAllowedRating.Value;
  1124. }
  1125. public int? GetParentalRatingValue()
  1126. {
  1127. var rating = CustomRating;
  1128. if (string.IsNullOrWhiteSpace(rating))
  1129. {
  1130. rating = OfficialRating;
  1131. }
  1132. if (string.IsNullOrWhiteSpace(rating))
  1133. {
  1134. return null;
  1135. }
  1136. return LocalizationManager.GetRatingLevel(rating);
  1137. }
  1138. public int? GetInheritedParentalRatingValue()
  1139. {
  1140. var rating = CustomRatingForComparison;
  1141. if (string.IsNullOrWhiteSpace(rating))
  1142. {
  1143. rating = OfficialRatingForComparison;
  1144. }
  1145. if (string.IsNullOrWhiteSpace(rating))
  1146. {
  1147. return null;
  1148. }
  1149. return LocalizationManager.GetRatingLevel(rating);
  1150. }
  1151. public List<string> GetInheritedTags()
  1152. {
  1153. var list = new List<string>();
  1154. list.AddRange(Tags);
  1155. foreach (var parent in GetParents())
  1156. {
  1157. list.AddRange(parent.Tags);
  1158. }
  1159. return list.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
  1160. }
  1161. private bool IsVisibleViaTags(User user)
  1162. {
  1163. var hasTags = this as IHasTags;
  1164. if (hasTags != null)
  1165. {
  1166. var policy = user.Policy;
  1167. if (policy.BlockedTags.Any(i => hasTags.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)))
  1168. {
  1169. return false;
  1170. }
  1171. }
  1172. return true;
  1173. }
  1174. protected virtual bool IsAllowTagFilterEnforced()
  1175. {
  1176. return true;
  1177. }
  1178. public virtual UnratedItem GetBlockUnratedType()
  1179. {
  1180. if (SourceType == SourceType.Channel)
  1181. {
  1182. return UnratedItem.ChannelContent;
  1183. }
  1184. return UnratedItem.Other;
  1185. }
  1186. /// <summary>
  1187. /// Gets the block unrated value.
  1188. /// </summary>
  1189. /// <param name="config">The configuration.</param>
  1190. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  1191. protected virtual bool GetBlockUnratedValue(UserPolicy config)
  1192. {
  1193. // Don't block plain folders that are unrated. Let the media underneath get blocked
  1194. // Special folders like series and albums will override this method.
  1195. if (IsFolder)
  1196. {
  1197. return false;
  1198. }
  1199. if (this is IItemByName)
  1200. {
  1201. return false;
  1202. }
  1203. return config.BlockUnratedItems.Contains(GetBlockUnratedType());
  1204. }
  1205. /// <summary>
  1206. /// Determines if this folder should be visible to a given user.
  1207. /// Default is just parental allowed. Can be overridden for more functionality.
  1208. /// </summary>
  1209. /// <param name="user">The user.</param>
  1210. /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
  1211. /// <exception cref="System.ArgumentNullException">user</exception>
  1212. public virtual bool IsVisible(User user)
  1213. {
  1214. if (user == null)
  1215. {
  1216. throw new ArgumentNullException("user");
  1217. }
  1218. return IsParentalAllowed(user);
  1219. }
  1220. public virtual bool IsVisibleStandalone(User user)
  1221. {
  1222. if (SourceType == SourceType.Channel)
  1223. {
  1224. return IsVisibleStandaloneInternal(user, false) && Channel.IsChannelVisible(this, user);
  1225. }
  1226. return IsVisibleStandaloneInternal(user, true);
  1227. }
  1228. protected bool IsVisibleStandaloneInternal(User user, bool checkFolders)
  1229. {
  1230. if (!IsVisible(user))
  1231. {
  1232. return false;
  1233. }
  1234. if (GetParents().Any(i => !i.IsVisible(user)))
  1235. {
  1236. return false;
  1237. }
  1238. if (checkFolders)
  1239. {
  1240. var topParent = GetParents().LastOrDefault() ?? this;
  1241. if (string.IsNullOrWhiteSpace(topParent.Path))
  1242. {
  1243. return true;
  1244. }
  1245. var userCollectionFolders = user.RootFolder.GetChildren(user, true).Select(i => i.Id).ToList();
  1246. var itemCollectionFolders = LibraryManager.GetCollectionFolders(this).Select(i => i.Id);
  1247. if (!itemCollectionFolders.Any(userCollectionFolders.Contains))
  1248. {
  1249. return false;
  1250. }
  1251. }
  1252. return true;
  1253. }
  1254. /// <summary>
  1255. /// Gets a value indicating whether this instance is folder.
  1256. /// </summary>
  1257. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  1258. [IgnoreDataMember]
  1259. public virtual bool IsFolder
  1260. {
  1261. get
  1262. {
  1263. return false;
  1264. }
  1265. }
  1266. public virtual string GetClientTypeName()
  1267. {
  1268. if (IsFolder && SourceType == SourceType.Channel && !(this is Channel))
  1269. {
  1270. return "ChannelFolderItem";
  1271. }
  1272. return GetType().Name;
  1273. }
  1274. /// <summary>
  1275. /// Gets the linked child.
  1276. /// </summary>
  1277. /// <param name="info">The info.</param>
  1278. /// <returns>BaseItem.</returns>
  1279. protected BaseItem GetLinkedChild(LinkedChild info)
  1280. {
  1281. // First get using the cached Id
  1282. if (info.ItemId.HasValue)
  1283. {
  1284. if (info.ItemId.Value == Guid.Empty)
  1285. {
  1286. return null;
  1287. }
  1288. var itemById = LibraryManager.GetItemById(info.ItemId.Value);
  1289. if (itemById != null)
  1290. {
  1291. return itemById;
  1292. }
  1293. }
  1294. var item = FindLinkedChild(info);
  1295. // If still null, log
  1296. if (item == null)
  1297. {
  1298. // Don't keep searching over and over
  1299. info.ItemId = Guid.Empty;
  1300. }
  1301. else
  1302. {
  1303. // Cache the id for next time
  1304. info.ItemId = item.Id;
  1305. }
  1306. return item;
  1307. }
  1308. private BaseItem FindLinkedChild(LinkedChild info)
  1309. {
  1310. if (!string.IsNullOrEmpty(info.Path))
  1311. {
  1312. var itemByPath = LibraryManager.FindByPath(info.Path, null);
  1313. if (itemByPath == null)
  1314. {
  1315. //Logger.Warn("Unable to find linked item at path {0}", info.Path);
  1316. }
  1317. return itemByPath;
  1318. }
  1319. return null;
  1320. }
  1321. [IgnoreDataMember]
  1322. public virtual bool EnableRememberingTrackSelections
  1323. {
  1324. get
  1325. {
  1326. return true;
  1327. }
  1328. }
  1329. /// <summary>
  1330. /// Adds a studio to the item
  1331. /// </summary>
  1332. /// <param name="name">The name.</param>
  1333. /// <exception cref="System.ArgumentNullException"></exception>
  1334. public void AddStudio(string name)
  1335. {
  1336. if (string.IsNullOrWhiteSpace(name))
  1337. {
  1338. throw new ArgumentNullException("name");
  1339. }
  1340. if (!Studios.Contains(name, StringComparer.OrdinalIgnoreCase))
  1341. {
  1342. Studios.Add(name);
  1343. }
  1344. }
  1345. /// <summary>
  1346. /// Adds a genre to the item
  1347. /// </summary>
  1348. /// <param name="name">The name.</param>
  1349. /// <exception cref="System.ArgumentNullException"></exception>
  1350. public void AddGenre(string name)
  1351. {
  1352. if (string.IsNullOrWhiteSpace(name))
  1353. {
  1354. throw new ArgumentNullException("name");
  1355. }
  1356. if (!Genres.Contains(name, StringComparer.OrdinalIgnoreCase))
  1357. {
  1358. Genres.Add(name);
  1359. }
  1360. }
  1361. /// <summary>
  1362. /// Marks the played.
  1363. /// </summary>
  1364. /// <param name="user">The user.</param>
  1365. /// <param name="datePlayed">The date played.</param>
  1366. /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
  1367. /// <returns>Task.</returns>
  1368. /// <exception cref="System.ArgumentNullException"></exception>
  1369. public virtual async Task MarkPlayed(User user,
  1370. DateTime? datePlayed,
  1371. bool resetPosition)
  1372. {
  1373. if (user == null)
  1374. {
  1375. throw new ArgumentNullException();
  1376. }
  1377. var data = UserDataManager.GetUserData(user, this);
  1378. if (datePlayed.HasValue)
  1379. {
  1380. // Incremenet
  1381. data.PlayCount++;
  1382. }
  1383. // Ensure it's at least one
  1384. data.PlayCount = Math.Max(data.PlayCount, 1);
  1385. if (resetPosition)
  1386. {
  1387. data.PlaybackPositionTicks = 0;
  1388. }
  1389. data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
  1390. data.Played = true;
  1391. await UserDataManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  1392. }
  1393. /// <summary>
  1394. /// Marks the unplayed.
  1395. /// </summary>
  1396. /// <param name="user">The user.</param>
  1397. /// <returns>Task.</returns>
  1398. /// <exception cref="System.ArgumentNullException"></exception>
  1399. public virtual async Task MarkUnplayed(User user)
  1400. {
  1401. if (user == null)
  1402. {
  1403. throw new ArgumentNullException();
  1404. }
  1405. var data = UserDataManager.GetUserData(user, this);
  1406. //I think it is okay to do this here.
  1407. // if this is only called when a user is manually forcing something to un-played
  1408. // then it probably is what we want to do...
  1409. data.PlayCount = 0;
  1410. data.PlaybackPositionTicks = 0;
  1411. data.LastPlayedDate = null;
  1412. data.Played = false;
  1413. await UserDataManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  1414. }
  1415. /// <summary>
  1416. /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
  1417. /// </summary>
  1418. /// <returns>Task.</returns>
  1419. public virtual Task ChangedExternally()
  1420. {
  1421. ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(FileSystem));
  1422. return Task.FromResult(true);
  1423. }
  1424. /// <summary>
  1425. /// Gets an image
  1426. /// </summary>
  1427. /// <param name="type">The type.</param>
  1428. /// <param name="imageIndex">Index of the image.</param>
  1429. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  1430. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  1431. public bool HasImage(ImageType type, int imageIndex)
  1432. {
  1433. return GetImageInfo(type, imageIndex) != null;
  1434. }
  1435. public void SetImage(ItemImageInfo image, int index)
  1436. {
  1437. if (image.Type == ImageType.Chapter)
  1438. {
  1439. throw new ArgumentException("Cannot set chapter images using SetImagePath");
  1440. }
  1441. var existingImage = GetImageInfo(image.Type, index);
  1442. if (existingImage != null)
  1443. {
  1444. ImageInfos.Remove(existingImage);
  1445. }
  1446. ImageInfos.Add(image);
  1447. }
  1448. public void SetImagePath(ImageType type, int index, FileSystemMetadata file)
  1449. {
  1450. if (type == ImageType.Chapter)
  1451. {
  1452. throw new ArgumentException("Cannot set chapter images using SetImagePath");
  1453. }
  1454. var image = GetImageInfo(type, index);
  1455. if (image == null)
  1456. {
  1457. ImageInfos.Add(GetImageInfo(file, type));
  1458. }
  1459. else
  1460. {
  1461. var imageInfo = GetImageInfo(file, type);
  1462. image.Path = file.FullName;
  1463. image.DateModified = imageInfo.DateModified;
  1464. image.IsPlaceholder = false;
  1465. }
  1466. }
  1467. /// <summary>
  1468. /// Deletes the image.
  1469. /// </summary>
  1470. /// <param name="type">The type.</param>
  1471. /// <param name="index">The index.</param>
  1472. /// <returns>Task.</returns>
  1473. public Task DeleteImage(ImageType type, int index)
  1474. {
  1475. var info = GetImageInfo(type, index);
  1476. if (info == null)
  1477. {
  1478. // Nothing to do
  1479. return Task.FromResult(true);
  1480. }
  1481. // Remove it from the item
  1482. RemoveImage(info);
  1483. if (info.IsLocalFile)
  1484. {
  1485. // Delete the source file
  1486. var currentFile = new FileInfo(info.Path);
  1487. // Deletion will fail if the file is hidden so remove the attribute first
  1488. if (currentFile.Exists)
  1489. {
  1490. if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  1491. {
  1492. currentFile.Attributes &= ~FileAttributes.Hidden;
  1493. }
  1494. FileSystem.DeleteFile(currentFile.FullName);
  1495. }
  1496. }
  1497. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1498. }
  1499. public void RemoveImage(ItemImageInfo image)
  1500. {
  1501. ImageInfos.Remove(image);
  1502. }
  1503. public virtual Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  1504. {
  1505. return LibraryManager.UpdateItem(this, updateReason, cancellationToken);
  1506. }
  1507. /// <summary>
  1508. /// Validates that images within the item are still on the file system
  1509. /// </summary>
  1510. public bool ValidateImages(IDirectoryService directoryService)
  1511. {
  1512. var allFiles = ImageInfos
  1513. .Where(i => i.IsLocalFile)
  1514. .Select(i => System.IO.Path.GetDirectoryName(i.Path))
  1515. .Distinct(StringComparer.OrdinalIgnoreCase)
  1516. .SelectMany(directoryService.GetFiles)
  1517. .Select(i => i.FullName)
  1518. .ToList();
  1519. var deletedImages = ImageInfos
  1520. .Where(image => image.IsLocalFile && !allFiles.Contains(image.Path, StringComparer.OrdinalIgnoreCase))
  1521. .ToList();
  1522. if (deletedImages.Count > 0)
  1523. {
  1524. ImageInfos = ImageInfos.Except(deletedImages).ToList();
  1525. }
  1526. return deletedImages.Count > 0;
  1527. }
  1528. /// <summary>
  1529. /// Gets the image path.
  1530. /// </summary>
  1531. /// <param name="imageType">Type of the image.</param>
  1532. /// <param name="imageIndex">Index of the image.</param>
  1533. /// <returns>System.String.</returns>
  1534. /// <exception cref="System.InvalidOperationException">
  1535. /// </exception>
  1536. /// <exception cref="System.ArgumentNullException">item</exception>
  1537. public string GetImagePath(ImageType imageType, int imageIndex)
  1538. {
  1539. var info = GetImageInfo(imageType, imageIndex);
  1540. return info == null ? null : info.Path;
  1541. }
  1542. /// <summary>
  1543. /// Gets the image information.
  1544. /// </summary>
  1545. /// <param name="imageType">Type of the image.</param>
  1546. /// <param name="imageIndex">Index of the image.</param>
  1547. /// <returns>ItemImageInfo.</returns>
  1548. public ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex)
  1549. {
  1550. if (imageType == ImageType.Chapter)
  1551. {
  1552. var chapter = ItemRepository.GetChapter(Id, imageIndex);
  1553. if (chapter == null)
  1554. {
  1555. return null;
  1556. }
  1557. var path = chapter.ImagePath;
  1558. if (string.IsNullOrWhiteSpace(path))
  1559. {
  1560. return null;
  1561. }
  1562. return new ItemImageInfo
  1563. {
  1564. Path = path,
  1565. DateModified = FileSystem.GetLastWriteTimeUtc(path),
  1566. Type = imageType
  1567. };
  1568. }
  1569. return GetImages(imageType)
  1570. .ElementAtOrDefault(imageIndex);
  1571. }
  1572. public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
  1573. {
  1574. if (imageType == ImageType.Chapter)
  1575. {
  1576. throw new ArgumentException("No image info for chapter images");
  1577. }
  1578. return ImageInfos.Where(i => i.Type == imageType);
  1579. }
  1580. /// <summary>
  1581. /// Adds the images.
  1582. /// </summary>
  1583. /// <param name="imageType">Type of the image.</param>
  1584. /// <param name="images">The images.</param>
  1585. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  1586. /// <exception cref="System.ArgumentException">Cannot call AddImages with chapter images</exception>
  1587. public bool AddImages(ImageType imageType, List<FileSystemMetadata> images)
  1588. {
  1589. if (imageType == ImageType.Chapter)
  1590. {
  1591. throw new ArgumentException("Cannot call AddImages with chapter images");
  1592. }
  1593. var existingImages = GetImages(imageType)
  1594. .ToList();
  1595. var newImageList = new List<FileSystemMetadata>();
  1596. var imageAdded = false;
  1597. foreach (var newImage in images)
  1598. {
  1599. if (newImage == null)
  1600. {
  1601. throw new ArgumentException("null image found in list");
  1602. }
  1603. var existing = existingImages
  1604. .FirstOrDefault(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase));
  1605. if (existing == null)
  1606. {
  1607. newImageList.Add(newImage);
  1608. imageAdded = true;
  1609. }
  1610. else
  1611. {
  1612. if (existing.IsLocalFile)
  1613. {
  1614. existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage);
  1615. }
  1616. }
  1617. }
  1618. if (imageAdded || images.Count != existingImages.Count)
  1619. {
  1620. var newImagePaths = images.Select(i => i.FullName).ToList();
  1621. var deleted = existingImages
  1622. .Where(i => i.IsLocalFile && !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !FileSystem.FileExists(i.Path))
  1623. .ToList();
  1624. ImageInfos = ImageInfos.Except(deleted).ToList();
  1625. }
  1626. ImageInfos.AddRange(newImageList.Select(i => GetImageInfo(i, imageType)));
  1627. return newImageList.Count > 0;
  1628. }
  1629. private ItemImageInfo GetImageInfo(FileSystemMetadata file, ImageType type)
  1630. {
  1631. return new ItemImageInfo
  1632. {
  1633. Path = file.FullName,
  1634. Type = type,
  1635. DateModified = FileSystem.GetLastWriteTimeUtc(file)
  1636. };
  1637. }
  1638. /// <summary>
  1639. /// Gets the file system path to delete when the item is to be deleted
  1640. /// </summary>
  1641. /// <returns></returns>
  1642. public virtual IEnumerable<string> GetDeletePaths()
  1643. {
  1644. return new[] { Path };
  1645. }
  1646. public bool AllowsMultipleImages(ImageType type)
  1647. {
  1648. return type == ImageType.Backdrop || type == ImageType.Screenshot || type == ImageType.Chapter;
  1649. }
  1650. public Task SwapImages(ImageType type, int index1, int index2)
  1651. {
  1652. if (!AllowsMultipleImages(type))
  1653. {
  1654. throw new ArgumentException("The change index operation is only applicable to backdrops and screenshots");
  1655. }
  1656. var info1 = GetImageInfo(type, index1);
  1657. var info2 = GetImageInfo(type, index2);
  1658. if (info1 == null || info2 == null)
  1659. {
  1660. // Nothing to do
  1661. return Task.FromResult(true);
  1662. }
  1663. if (!info1.IsLocalFile || !info2.IsLocalFile)
  1664. {
  1665. // TODO: Not supported yet
  1666. return Task.FromResult(true);
  1667. }
  1668. var path1 = info1.Path;
  1669. var path2 = info2.Path;
  1670. FileSystem.SwapFiles(path1, path2);
  1671. // Refresh these values
  1672. info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
  1673. info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
  1674. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1675. }
  1676. public virtual bool IsPlayed(User user)
  1677. {
  1678. var userdata = UserDataManager.GetUserData(user, this);
  1679. return userdata != null && userdata.Played;
  1680. }
  1681. public bool IsFavoriteOrLiked(User user)
  1682. {
  1683. var userdata = UserDataManager.GetUserData(user, this);
  1684. return userdata != null && (userdata.IsFavorite || (userdata.Likes ?? false));
  1685. }
  1686. public virtual bool IsUnplayed(User user)
  1687. {
  1688. if (user == null)
  1689. {
  1690. throw new ArgumentNullException("user");
  1691. }
  1692. var userdata = UserDataManager.GetUserData(user, this);
  1693. return userdata == null || !userdata.Played;
  1694. }
  1695. ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
  1696. {
  1697. return GetItemLookupInfo<ItemLookupInfo>();
  1698. }
  1699. protected T GetItemLookupInfo<T>()
  1700. where T : ItemLookupInfo, new()
  1701. {
  1702. return new T
  1703. {
  1704. MetadataCountryCode = GetPreferredMetadataCountryCode(),
  1705. MetadataLanguage = GetPreferredMetadataLanguage(),
  1706. Name = Name,
  1707. ProviderIds = ProviderIds,
  1708. IndexNumber = IndexNumber,
  1709. ParentIndexNumber = ParentIndexNumber,
  1710. Year = ProductionYear,
  1711. PremiereDate = PremiereDate
  1712. };
  1713. }
  1714. /// <summary>
  1715. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  1716. /// </summary>
  1717. public virtual bool BeforeMetadataRefresh()
  1718. {
  1719. _userDataKey = null;
  1720. _sortName = null;
  1721. var hasChanges = false;
  1722. if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Path))
  1723. {
  1724. Name = FileSystem.GetFileNameWithoutExtension(Path);
  1725. hasChanges = true;
  1726. }
  1727. return hasChanges;
  1728. }
  1729. protected static string GetMappedPath(string path, LocationType locationType)
  1730. {
  1731. if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
  1732. {
  1733. foreach (var map in ConfigurationManager.Configuration.PathSubstitutions)
  1734. {
  1735. path = LibraryManager.SubstitutePath(path, map.From, map.To);
  1736. }
  1737. }
  1738. return path;
  1739. }
  1740. public virtual void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
  1741. {
  1742. if (RunTimeTicks.HasValue)
  1743. {
  1744. double pct = RunTimeTicks.Value;
  1745. if (pct > 0)
  1746. {
  1747. pct = userData.PlaybackPositionTicks / pct;
  1748. if (pct > 0)
  1749. {
  1750. dto.PlayedPercentage = 100 * pct;
  1751. }
  1752. }
  1753. }
  1754. }
  1755. protected Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, string path, CancellationToken cancellationToken)
  1756. {
  1757. var newOptions = new MetadataRefreshOptions(options.DirectoryService)
  1758. {
  1759. ImageRefreshMode = options.ImageRefreshMode,
  1760. MetadataRefreshMode = options.MetadataRefreshMode,
  1761. ReplaceAllMetadata = options.ReplaceAllMetadata
  1762. };
  1763. var id = LibraryManager.GetNewItemId(path, typeof(Video));
  1764. // Try to retrieve it from the db. If we don't find it, use the resolved version
  1765. var video = LibraryManager.GetItemById(id) as Video;
  1766. if (video == null)
  1767. {
  1768. video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video;
  1769. newOptions.ForceSave = true;
  1770. }
  1771. if (video == null)
  1772. {
  1773. return Task.FromResult(true);
  1774. }
  1775. return video.RefreshMetadata(newOptions, cancellationToken);
  1776. }
  1777. public string GetEtag(User user)
  1778. {
  1779. return string.Join("|", GetEtagValues(user).ToArray()).GetMD5().ToString("N");
  1780. }
  1781. protected virtual List<string> GetEtagValues(User user)
  1782. {
  1783. return new List<string>
  1784. {
  1785. DateLastSaved.Ticks.ToString(CultureInfo.InvariantCulture)
  1786. };
  1787. }
  1788. public virtual IEnumerable<Guid> GetAncestorIds()
  1789. {
  1790. return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
  1791. }
  1792. public BaseItem GetTopParent()
  1793. {
  1794. if (IsTopParent)
  1795. {
  1796. return this;
  1797. }
  1798. return GetParents().FirstOrDefault(i => i.IsTopParent);
  1799. }
  1800. [IgnoreDataMember]
  1801. public virtual bool IsTopParent
  1802. {
  1803. get
  1804. {
  1805. if (GetParent() is AggregateFolder || this is BasePluginFolder)
  1806. {
  1807. return true;
  1808. }
  1809. var view = this as UserView;
  1810. if (view != null && string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
  1811. {
  1812. return true;
  1813. }
  1814. if (view != null && string.Equals(view.ViewType, CollectionType.Channels, StringComparison.OrdinalIgnoreCase))
  1815. {
  1816. return true;
  1817. }
  1818. return false;
  1819. }
  1820. }
  1821. [IgnoreDataMember]
  1822. public virtual bool SupportsAncestors
  1823. {
  1824. get
  1825. {
  1826. return true;
  1827. }
  1828. }
  1829. public virtual IEnumerable<Guid> GetIdsForAncestorQuery()
  1830. {
  1831. return new[] { Id };
  1832. }
  1833. public virtual Task Delete(DeleteOptions options)
  1834. {
  1835. return LibraryManager.DeleteItem(this, options);
  1836. }
  1837. public virtual Task OnFileDeleted()
  1838. {
  1839. // Remove from database
  1840. return Delete(new DeleteOptions
  1841. {
  1842. DeleteFileLocation = false
  1843. });
  1844. }
  1845. }
  1846. }