BaseItem.cs 68 KB

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