BaseItem.cs 68 KB

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