BaseItem.cs 69 KB

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