BaseItem.cs 69 KB

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