BaseItem.cs 69 KB

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