BaseItem.cs 68 KB

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