BaseItem.cs 69 KB

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