Folder.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. using MediaBrowser.Common.Progress;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.Querying;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Runtime.Serialization;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using CommonIO;
  15. using MediaBrowser.Controller.Channels;
  16. using MediaBrowser.Controller.Entities.Audio;
  17. using MediaBrowser.Controller.Entities.TV;
  18. using MediaBrowser.Model.Channels;
  19. namespace MediaBrowser.Controller.Entities
  20. {
  21. /// <summary>
  22. /// Class Folder
  23. /// </summary>
  24. public class Folder : BaseItem, IHasThemeMedia
  25. {
  26. public static IUserManager UserManager { get; set; }
  27. public static IUserViewManager UserViewManager { get; set; }
  28. public List<Guid> ThemeSongIds { get; set; }
  29. public List<Guid> ThemeVideoIds { get; set; }
  30. [IgnoreDataMember]
  31. public DateTime? DateLastMediaAdded { get; set; }
  32. public Folder()
  33. {
  34. LinkedChildren = new List<LinkedChild>();
  35. ThemeSongIds = new List<Guid>();
  36. ThemeVideoIds = new List<Guid>();
  37. }
  38. [IgnoreDataMember]
  39. public virtual bool IsPreSorted
  40. {
  41. get { return false; }
  42. }
  43. /// <summary>
  44. /// Gets a value indicating whether this instance is folder.
  45. /// </summary>
  46. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  47. [IgnoreDataMember]
  48. public override bool IsFolder
  49. {
  50. get
  51. {
  52. return true;
  53. }
  54. }
  55. [IgnoreDataMember]
  56. public virtual bool SupportsCumulativeRunTimeTicks
  57. {
  58. get
  59. {
  60. return false;
  61. }
  62. }
  63. [IgnoreDataMember]
  64. public virtual bool SupportsDateLastMediaAdded
  65. {
  66. get
  67. {
  68. return false;
  69. }
  70. }
  71. public override bool RequiresRefresh()
  72. {
  73. var baseResult = base.RequiresRefresh();
  74. if (SupportsCumulativeRunTimeTicks && !RunTimeTicks.HasValue)
  75. {
  76. baseResult = true;
  77. }
  78. return baseResult;
  79. }
  80. [IgnoreDataMember]
  81. public override string FileNameWithoutExtension
  82. {
  83. get
  84. {
  85. if (LocationType == LocationType.FileSystem)
  86. {
  87. return System.IO.Path.GetFileName(Path);
  88. }
  89. return null;
  90. }
  91. }
  92. protected override bool IsAllowTagFilterEnforced()
  93. {
  94. if (this is ICollectionFolder)
  95. {
  96. return false;
  97. }
  98. if (this is UserView)
  99. {
  100. return false;
  101. }
  102. return true;
  103. }
  104. /// <summary>
  105. /// Gets or sets a value indicating whether this instance is physical root.
  106. /// </summary>
  107. /// <value><c>true</c> if this instance is physical root; otherwise, <c>false</c>.</value>
  108. public bool IsPhysicalRoot { get; set; }
  109. /// <summary>
  110. /// Gets or sets a value indicating whether this instance is root.
  111. /// </summary>
  112. /// <value><c>true</c> if this instance is root; otherwise, <c>false</c>.</value>
  113. public bool IsRoot { get; set; }
  114. public virtual List<LinkedChild> LinkedChildren { get; set; }
  115. [IgnoreDataMember]
  116. protected virtual bool SupportsShortcutChildren
  117. {
  118. get { return false; }
  119. }
  120. /// <summary>
  121. /// Adds the child.
  122. /// </summary>
  123. /// <param name="item">The item.</param>
  124. /// <param name="cancellationToken">The cancellation token.</param>
  125. /// <returns>Task.</returns>
  126. /// <exception cref="System.InvalidOperationException">Unable to add + item.Name</exception>
  127. public async Task AddChild(BaseItem item, CancellationToken cancellationToken)
  128. {
  129. item.SetParent(this);
  130. if (item.Id == Guid.Empty)
  131. {
  132. item.Id = LibraryManager.GetNewItemId(item.Path, item.GetType());
  133. }
  134. if (ActualChildren.Any(i => i.Id == item.Id))
  135. {
  136. throw new ArgumentException(string.Format("A child with the Id {0} already exists.", item.Id));
  137. }
  138. if (item.DateCreated == DateTime.MinValue)
  139. {
  140. item.DateCreated = DateTime.UtcNow;
  141. }
  142. if (item.DateModified == DateTime.MinValue)
  143. {
  144. item.DateModified = DateTime.UtcNow;
  145. }
  146. await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
  147. }
  148. /// <summary>
  149. /// Removes the child.
  150. /// </summary>
  151. /// <param name="item">The item.</param>
  152. public void RemoveChild(BaseItem item)
  153. {
  154. item.SetParent(null);
  155. }
  156. #region Indexing
  157. /// <summary>
  158. /// Returns the valid set of index by options for this folder type.
  159. /// Override or extend to modify.
  160. /// </summary>
  161. /// <returns>Dictionary{System.StringFunc{UserIEnumerable{BaseItem}}}.</returns>
  162. protected virtual IEnumerable<string> GetIndexByOptions()
  163. {
  164. return new List<string> {
  165. {"None"},
  166. {"Performer"},
  167. {"Genre"},
  168. {"Director"},
  169. {"Year"},
  170. {"Studio"}
  171. };
  172. }
  173. /// <summary>
  174. /// Get the list of indexy by choices for this folder (localized).
  175. /// </summary>
  176. /// <value>The index by option strings.</value>
  177. [IgnoreDataMember]
  178. public IEnumerable<string> IndexByOptionStrings
  179. {
  180. get { return GetIndexByOptions(); }
  181. }
  182. #endregion
  183. /// <summary>
  184. /// Gets the actual children.
  185. /// </summary>
  186. /// <value>The actual children.</value>
  187. [IgnoreDataMember]
  188. protected virtual IEnumerable<BaseItem> ActualChildren
  189. {
  190. get
  191. {
  192. return LoadChildren();
  193. }
  194. }
  195. /// <summary>
  196. /// thread-safe access to the actual children of this folder - without regard to user
  197. /// </summary>
  198. /// <value>The children.</value>
  199. [IgnoreDataMember]
  200. public IEnumerable<BaseItem> Children
  201. {
  202. get { return ActualChildren.ToList(); }
  203. }
  204. /// <summary>
  205. /// thread-safe access to all recursive children of this folder - without regard to user
  206. /// </summary>
  207. /// <value>The recursive children.</value>
  208. [IgnoreDataMember]
  209. public IEnumerable<BaseItem> RecursiveChildren
  210. {
  211. get { return GetRecursiveChildren(); }
  212. }
  213. public override bool IsVisible(User user)
  214. {
  215. if (this is ICollectionFolder && !(this is BasePluginFolder))
  216. {
  217. if (user.Policy.BlockedMediaFolders != null)
  218. {
  219. if (user.Policy.BlockedMediaFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase) ||
  220. // Backwards compatibility
  221. user.Policy.BlockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
  222. {
  223. return false;
  224. }
  225. }
  226. else
  227. {
  228. if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
  229. {
  230. return false;
  231. }
  232. }
  233. }
  234. return base.IsVisible(user);
  235. }
  236. /// <summary>
  237. /// Loads our children. Validation will occur externally.
  238. /// We want this sychronous.
  239. /// </summary>
  240. protected virtual IEnumerable<BaseItem> LoadChildren()
  241. {
  242. //Logger.Debug("Loading children from {0} {1} {2}", GetType().Name, Id, Path);
  243. //just load our children from the repo - the library will be validated and maintained in other processes
  244. return GetCachedChildren();
  245. }
  246. public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
  247. {
  248. return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)));
  249. }
  250. /// <summary>
  251. /// Validates that the children of the folder still exist
  252. /// </summary>
  253. /// <param name="progress">The progress.</param>
  254. /// <param name="cancellationToken">The cancellation token.</param>
  255. /// <param name="metadataRefreshOptions">The metadata refresh options.</param>
  256. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  257. /// <returns>Task.</returns>
  258. public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true)
  259. {
  260. return ValidateChildrenInternal(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService);
  261. }
  262. private Dictionary<Guid, BaseItem> GetActualChildrenDictionary()
  263. {
  264. var dictionary = new Dictionary<Guid, BaseItem>();
  265. foreach (var child in ActualChildren)
  266. {
  267. var id = child.Id;
  268. if (dictionary.ContainsKey(id))
  269. {
  270. Logger.Error("Found folder containing items with duplicate id. Path: {0}, Child Name: {1}",
  271. Path ?? Name,
  272. child.Path ?? child.Name);
  273. }
  274. else
  275. {
  276. dictionary[id] = child;
  277. }
  278. }
  279. return dictionary;
  280. }
  281. private bool IsValidFromResolver(BaseItem current, BaseItem newItem)
  282. {
  283. return current.IsValidFromResolver(newItem);
  284. }
  285. /// <summary>
  286. /// Validates the children internal.
  287. /// </summary>
  288. /// <param name="progress">The progress.</param>
  289. /// <param name="cancellationToken">The cancellation token.</param>
  290. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  291. /// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
  292. /// <param name="refreshOptions">The refresh options.</param>
  293. /// <param name="directoryService">The directory service.</param>
  294. /// <returns>Task.</returns>
  295. protected async virtual Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  296. {
  297. var locationType = LocationType;
  298. cancellationToken.ThrowIfCancellationRequested();
  299. var validChildren = new List<BaseItem>();
  300. if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
  301. {
  302. IEnumerable<BaseItem> nonCachedChildren;
  303. try
  304. {
  305. nonCachedChildren = GetNonCachedChildren(directoryService);
  306. }
  307. catch (IOException ex)
  308. {
  309. nonCachedChildren = new BaseItem[] { };
  310. Logger.ErrorException("Error getting file system entries for {0}", ex, Path);
  311. }
  312. if (nonCachedChildren == null) return; //nothing to validate
  313. progress.Report(5);
  314. //build a dictionary of the current children we have now by Id so we can compare quickly and easily
  315. var currentChildren = GetActualChildrenDictionary();
  316. //create a list for our validated children
  317. var newItems = new List<BaseItem>();
  318. cancellationToken.ThrowIfCancellationRequested();
  319. foreach (var child in nonCachedChildren)
  320. {
  321. BaseItem currentChild;
  322. if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child))
  323. {
  324. await currentChild.UpdateIsOffline(false).ConfigureAwait(false);
  325. validChildren.Add(currentChild);
  326. continue;
  327. }
  328. // Brand new item - needs to be added
  329. child.SetParent(this);
  330. newItems.Add(child);
  331. validChildren.Add(child);
  332. }
  333. // If any items were added or removed....
  334. if (newItems.Count > 0 || currentChildren.Count != validChildren.Count)
  335. {
  336. // That's all the new and changed ones - now see if there are any that are missing
  337. var itemsRemoved = currentChildren.Values.Except(validChildren).ToList();
  338. var actualRemovals = new List<BaseItem>();
  339. foreach (var item in itemsRemoved)
  340. {
  341. var itemLocationType = item.LocationType;
  342. if (itemLocationType == LocationType.Virtual ||
  343. itemLocationType == LocationType.Remote)
  344. {
  345. }
  346. else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path))
  347. {
  348. await item.UpdateIsOffline(true).ConfigureAwait(false);
  349. }
  350. else
  351. {
  352. actualRemovals.Add(item);
  353. }
  354. }
  355. if (actualRemovals.Count > 0)
  356. {
  357. foreach (var item in actualRemovals)
  358. {
  359. Logger.Debug("Removed item: " + item.Path);
  360. item.SetParent(null);
  361. item.IsOffline = false;
  362. await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
  363. LibraryManager.ReportItemRemoved(item);
  364. }
  365. }
  366. await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false);
  367. }
  368. }
  369. progress.Report(10);
  370. cancellationToken.ThrowIfCancellationRequested();
  371. if (recursive)
  372. {
  373. await ValidateSubFolders(ActualChildren.OfType<Folder>().ToList(), directoryService, progress, cancellationToken).ConfigureAwait(false);
  374. }
  375. progress.Report(20);
  376. if (refreshChildMetadata)
  377. {
  378. var container = this as IMetadataContainer;
  379. var innerProgress = new ActionableProgress<double>();
  380. innerProgress.RegisterAction(p => progress.Report(.80 * p + 20));
  381. if (container != null)
  382. {
  383. await container.RefreshAllMetadata(refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false);
  384. }
  385. else
  386. {
  387. await RefreshMetadataRecursive(refreshOptions, recursive, innerProgress, cancellationToken);
  388. }
  389. }
  390. progress.Report(100);
  391. }
  392. private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
  393. {
  394. var children = ActualChildren.ToList();
  395. var percentages = new Dictionary<Guid, double>(children.Count);
  396. var numComplete = 0;
  397. var count = children.Count;
  398. foreach (var child in children)
  399. {
  400. cancellationToken.ThrowIfCancellationRequested();
  401. if (child.IsFolder)
  402. {
  403. var innerProgress = new ActionableProgress<double>();
  404. // Avoid implicitly captured closure
  405. var currentChild = child;
  406. innerProgress.RegisterAction(p =>
  407. {
  408. lock (percentages)
  409. {
  410. percentages[currentChild.Id] = p / 100;
  411. var innerPercent = percentages.Values.Sum();
  412. innerPercent /= count;
  413. innerPercent *= 100;
  414. progress.Report(innerPercent);
  415. }
  416. });
  417. await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
  418. .ConfigureAwait(false);
  419. }
  420. else
  421. {
  422. await RefreshChildMetadata(child, refreshOptions, false, new Progress<double>(), cancellationToken)
  423. .ConfigureAwait(false);
  424. }
  425. numComplete++;
  426. double percent = numComplete;
  427. percent /= count;
  428. percent *= 100;
  429. progress.Report(percent);
  430. }
  431. progress.Report(100);
  432. }
  433. private async Task RefreshChildMetadata(BaseItem child, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
  434. {
  435. var container = child as IMetadataContainer;
  436. if (container != null)
  437. {
  438. await container.RefreshAllMetadata(refreshOptions, progress, cancellationToken).ConfigureAwait(false);
  439. }
  440. else
  441. {
  442. await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
  443. if (recursive)
  444. {
  445. var folder = child as Folder;
  446. if (folder != null)
  447. {
  448. await folder.RefreshMetadataRecursive(refreshOptions, true, progress, cancellationToken);
  449. }
  450. }
  451. }
  452. progress.Report(100);
  453. }
  454. /// <summary>
  455. /// Refreshes the children.
  456. /// </summary>
  457. /// <param name="children">The children.</param>
  458. /// <param name="directoryService">The directory service.</param>
  459. /// <param name="progress">The progress.</param>
  460. /// <param name="cancellationToken">The cancellation token.</param>
  461. /// <returns>Task.</returns>
  462. private async Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
  463. {
  464. var list = children;
  465. var childCount = list.Count;
  466. var percentages = new Dictionary<Guid, double>(list.Count);
  467. foreach (var item in list)
  468. {
  469. cancellationToken.ThrowIfCancellationRequested();
  470. var child = item;
  471. var innerProgress = new ActionableProgress<double>();
  472. innerProgress.RegisterAction(p =>
  473. {
  474. lock (percentages)
  475. {
  476. percentages[child.Id] = p / 100;
  477. var percent = percentages.Values.Sum();
  478. percent /= childCount;
  479. progress.Report(10 * percent + 10);
  480. }
  481. });
  482. await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService)
  483. .ConfigureAwait(false);
  484. }
  485. }
  486. /// <summary>
  487. /// Determines whether the specified path is offline.
  488. /// </summary>
  489. /// <param name="path">The path.</param>
  490. /// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
  491. public static bool IsPathOffline(string path)
  492. {
  493. if (FileSystem.FileExists(path))
  494. {
  495. return false;
  496. }
  497. var originalPath = path;
  498. // Depending on whether the path is local or unc, it may return either null or '\' at the top
  499. while (!string.IsNullOrEmpty(path) && path.Length > 1)
  500. {
  501. if (FileSystem.DirectoryExists(path))
  502. {
  503. return false;
  504. }
  505. path = System.IO.Path.GetDirectoryName(path);
  506. }
  507. if (ContainsPath(LibraryManager.GetVirtualFolders(), originalPath))
  508. {
  509. return true;
  510. }
  511. return false;
  512. }
  513. /// <summary>
  514. /// Determines whether the specified folders contains path.
  515. /// </summary>
  516. /// <param name="folders">The folders.</param>
  517. /// <param name="path">The path.</param>
  518. /// <returns><c>true</c> if the specified folders contains path; otherwise, <c>false</c>.</returns>
  519. private static bool ContainsPath(IEnumerable<VirtualFolderInfo> folders, string path)
  520. {
  521. return folders.SelectMany(i => i.Locations).Any(i => ContainsPath(i, path));
  522. }
  523. private static bool ContainsPath(string parent, string path)
  524. {
  525. return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || FileSystem.ContainsSubPath(parent, path);
  526. }
  527. /// <summary>
  528. /// Get the children of this folder from the actual file system
  529. /// </summary>
  530. /// <returns>IEnumerable{BaseItem}.</returns>
  531. protected virtual IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
  532. {
  533. var collectionType = LibraryManager.GetContentType(this);
  534. var libraryOptions = LibraryManager.GetLibraryOptions(this);
  535. return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, libraryOptions, collectionType);
  536. }
  537. /// <summary>
  538. /// Get our children from the repo - stubbed for now
  539. /// </summary>
  540. /// <returns>IEnumerable{BaseItem}.</returns>
  541. protected IEnumerable<BaseItem> GetCachedChildren()
  542. {
  543. return ItemRepository.GetItemList(new InternalItemsQuery
  544. {
  545. ParentId = Id,
  546. GroupByPresentationUniqueKey = false
  547. });
  548. }
  549. public virtual int GetChildCount(User user)
  550. {
  551. if (LinkedChildren.Count > 0)
  552. {
  553. if (!(this is ICollectionFolder))
  554. {
  555. return GetChildren(user, true).Count();
  556. }
  557. }
  558. var result = GetItems(new InternalItemsQuery(user)
  559. {
  560. Recursive = false,
  561. Limit = 0,
  562. ParentId = Id
  563. }).Result;
  564. return result.TotalRecordCount;
  565. }
  566. public QueryResult<BaseItem> QueryRecursive(InternalItemsQuery query)
  567. {
  568. var user = query.User;
  569. if (!query.ForceDirect && RequiresPostFiltering(query))
  570. {
  571. IEnumerable<BaseItem> items;
  572. Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
  573. if (query.User == null)
  574. {
  575. items = GetRecursiveChildren(filter);
  576. }
  577. else
  578. {
  579. items = GetRecursiveChildren(user, query);
  580. }
  581. return PostFilterAndSort(items, query, true, true);
  582. }
  583. if (!(this is UserRootFolder) && !(this is AggregateFolder))
  584. {
  585. query.ParentId = query.ParentId ?? Id;
  586. }
  587. return LibraryManager.GetItemsResult(query);
  588. }
  589. private bool RequiresPostFiltering(InternalItemsQuery query)
  590. {
  591. if (LinkedChildren.Count > 0)
  592. {
  593. if (!(this is ICollectionFolder))
  594. {
  595. Logger.Debug("Query requires post-filtering due to LinkedChildren. Type: " + GetType().Name);
  596. return true;
  597. }
  598. }
  599. if (query.SortBy != null && query.SortBy.Length > 0)
  600. {
  601. if (query.SortBy.Contains(ItemSortBy.AiredEpisodeOrder, StringComparer.OrdinalIgnoreCase))
  602. {
  603. Logger.Debug("Query requires post-filtering due to ItemSortBy.AiredEpisodeOrder");
  604. return true;
  605. }
  606. if (query.SortBy.Contains(ItemSortBy.Budget, StringComparer.OrdinalIgnoreCase))
  607. {
  608. Logger.Debug("Query requires post-filtering due to ItemSortBy.Budget");
  609. return true;
  610. }
  611. if (query.SortBy.Contains(ItemSortBy.GameSystem, StringComparer.OrdinalIgnoreCase))
  612. {
  613. Logger.Debug("Query requires post-filtering due to ItemSortBy.GameSystem");
  614. return true;
  615. }
  616. if (query.SortBy.Contains(ItemSortBy.Metascore, StringComparer.OrdinalIgnoreCase))
  617. {
  618. Logger.Debug("Query requires post-filtering due to ItemSortBy.Metascore");
  619. return true;
  620. }
  621. if (query.SortBy.Contains(ItemSortBy.Players, StringComparer.OrdinalIgnoreCase))
  622. {
  623. Logger.Debug("Query requires post-filtering due to ItemSortBy.Players");
  624. return true;
  625. }
  626. if (query.SortBy.Contains(ItemSortBy.Revenue, StringComparer.OrdinalIgnoreCase))
  627. {
  628. Logger.Debug("Query requires post-filtering due to ItemSortBy.Revenue");
  629. return true;
  630. }
  631. if (query.SortBy.Contains(ItemSortBy.VideoBitRate, StringComparer.OrdinalIgnoreCase))
  632. {
  633. Logger.Debug("Query requires post-filtering due to ItemSortBy.VideoBitRate");
  634. return true;
  635. }
  636. }
  637. if (query.ItemIds.Length > 0)
  638. {
  639. Logger.Debug("Query requires post-filtering due to ItemIds");
  640. return true;
  641. }
  642. if (query.IsInBoxSet.HasValue)
  643. {
  644. Logger.Debug("Query requires post-filtering due to IsInBoxSet");
  645. return true;
  646. }
  647. // Filter by Video3DFormat
  648. if (query.Is3D.HasValue)
  649. {
  650. Logger.Debug("Query requires post-filtering due to Is3D");
  651. return true;
  652. }
  653. if (query.HasOfficialRating.HasValue)
  654. {
  655. Logger.Debug("Query requires post-filtering due to HasOfficialRating");
  656. return true;
  657. }
  658. if (query.IsPlaceHolder.HasValue)
  659. {
  660. Logger.Debug("Query requires post-filtering due to IsPlaceHolder");
  661. return true;
  662. }
  663. if (query.HasSpecialFeature.HasValue)
  664. {
  665. Logger.Debug("Query requires post-filtering due to HasSpecialFeature");
  666. return true;
  667. }
  668. if (query.HasSubtitles.HasValue)
  669. {
  670. Logger.Debug("Query requires post-filtering due to HasSubtitles");
  671. return true;
  672. }
  673. if (query.HasTrailer.HasValue)
  674. {
  675. Logger.Debug("Query requires post-filtering due to HasTrailer");
  676. return true;
  677. }
  678. if (query.HasThemeSong.HasValue)
  679. {
  680. Logger.Debug("Query requires post-filtering due to HasThemeSong");
  681. return true;
  682. }
  683. if (query.HasThemeVideo.HasValue)
  684. {
  685. Logger.Debug("Query requires post-filtering due to HasThemeVideo");
  686. return true;
  687. }
  688. // Filter by VideoType
  689. if (query.VideoTypes.Length > 0)
  690. {
  691. Logger.Debug("Query requires post-filtering due to VideoTypes");
  692. return true;
  693. }
  694. // Apply person filter
  695. if (query.ItemIdsFromPersonFilters != null)
  696. {
  697. Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters");
  698. return true;
  699. }
  700. if (query.MinPlayers.HasValue)
  701. {
  702. Logger.Debug("Query requires post-filtering due to MinPlayers");
  703. return true;
  704. }
  705. if (query.MaxPlayers.HasValue)
  706. {
  707. Logger.Debug("Query requires post-filtering due to MaxPlayers");
  708. return true;
  709. }
  710. if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager))
  711. {
  712. Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems");
  713. return true;
  714. }
  715. if (!string.IsNullOrWhiteSpace(query.AdjacentTo))
  716. {
  717. Logger.Debug("Query requires post-filtering due to AdjacentTo");
  718. return true;
  719. }
  720. if (query.AirDays.Length > 0)
  721. {
  722. Logger.Debug("Query requires post-filtering due to AirDays");
  723. return true;
  724. }
  725. if (query.SeriesStatuses.Length > 0)
  726. {
  727. Logger.Debug("Query requires post-filtering due to SeriesStatuses");
  728. return true;
  729. }
  730. if (query.AiredDuringSeason.HasValue)
  731. {
  732. Logger.Debug("Query requires post-filtering due to AiredDuringSeason");
  733. return true;
  734. }
  735. if (!string.IsNullOrWhiteSpace(query.AlbumArtistStartsWithOrGreater))
  736. {
  737. Logger.Debug("Query requires post-filtering due to AlbumArtistStartsWithOrGreater");
  738. return true;
  739. }
  740. if (query.IsPlayed.HasValue)
  741. {
  742. if (query.IncludeItemTypes.Length == 1 && query.IncludeItemTypes.Contains(typeof(Series).Name))
  743. {
  744. Logger.Debug("Query requires post-filtering due to IsPlayed");
  745. return true;
  746. }
  747. }
  748. return false;
  749. }
  750. public Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
  751. {
  752. if (query.ItemIds.Length > 0)
  753. {
  754. var result = LibraryManager.GetItemsResult(query);
  755. if (query.SortBy.Length == 0)
  756. {
  757. var ids = query.ItemIds.ToList();
  758. // Try to preserve order
  759. result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray();
  760. }
  761. return Task.FromResult(result);
  762. }
  763. return GetItemsInternal(query);
  764. }
  765. protected virtual async Task<QueryResult<BaseItem>> GetItemsInternal(InternalItemsQuery query)
  766. {
  767. if (SourceType == SourceType.Channel)
  768. {
  769. try
  770. {
  771. // Don't blow up here because it could cause parent screens with other content to fail
  772. return await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
  773. {
  774. ChannelId = ChannelId,
  775. FolderId = Id.ToString("N"),
  776. Limit = query.Limit,
  777. StartIndex = query.StartIndex,
  778. UserId = query.User.Id.ToString("N"),
  779. SortBy = query.SortBy,
  780. SortOrder = query.SortOrder
  781. }, new Progress<double>(), CancellationToken.None);
  782. }
  783. catch
  784. {
  785. // Already logged at lower levels
  786. return new QueryResult<BaseItem>();
  787. }
  788. }
  789. if (query.Recursive)
  790. {
  791. return QueryRecursive(query);
  792. }
  793. var user = query.User;
  794. Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
  795. IEnumerable<BaseItem> items;
  796. if (query.User == null)
  797. {
  798. items = query.Recursive
  799. ? GetRecursiveChildren(filter)
  800. : Children.Where(filter);
  801. }
  802. else
  803. {
  804. items = query.Recursive
  805. ? GetRecursiveChildren(user, query)
  806. : GetChildren(user, true).Where(filter);
  807. }
  808. return PostFilterAndSort(items, query, true, true);
  809. }
  810. protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query, bool collapseBoxSetItems, bool enableSorting)
  811. {
  812. return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager, ConfigurationManager, collapseBoxSetItems, enableSorting);
  813. }
  814. public virtual IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
  815. {
  816. if (user == null)
  817. {
  818. throw new ArgumentNullException();
  819. }
  820. //the true root should return our users root folder children
  821. if (IsPhysicalRoot) return user.RootFolder.GetChildren(user, includeLinkedChildren);
  822. var result = new Dictionary<Guid, BaseItem>();
  823. AddChildren(user, includeLinkedChildren, result, false, null);
  824. return result.Values;
  825. }
  826. protected virtual IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  827. {
  828. return Children;
  829. }
  830. /// <summary>
  831. /// Adds the children to list.
  832. /// </summary>
  833. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  834. private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query)
  835. {
  836. foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
  837. {
  838. if (child.IsVisible(user))
  839. {
  840. if (query == null || UserViewBuilder.FilterItem(child, query))
  841. {
  842. result[child.Id] = child;
  843. }
  844. if (recursive && child.IsFolder)
  845. {
  846. var folder = (Folder)child;
  847. folder.AddChildren(user, includeLinkedChildren, result, true, query);
  848. }
  849. }
  850. }
  851. if (includeLinkedChildren)
  852. {
  853. foreach (var child in GetLinkedChildren(user))
  854. {
  855. if (child.IsVisible(user))
  856. {
  857. if (query == null || UserViewBuilder.FilterItem(child, query))
  858. {
  859. result[child.Id] = child;
  860. }
  861. }
  862. }
  863. }
  864. }
  865. /// <summary>
  866. /// Gets allowed recursive children of an item
  867. /// </summary>
  868. /// <param name="user">The user.</param>
  869. /// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
  870. /// <returns>IEnumerable{BaseItem}.</returns>
  871. /// <exception cref="System.ArgumentNullException"></exception>
  872. public IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true)
  873. {
  874. return GetRecursiveChildren(user, null);
  875. }
  876. public virtual IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
  877. {
  878. if (user == null)
  879. {
  880. throw new ArgumentNullException("user");
  881. }
  882. var result = new Dictionary<Guid, BaseItem>();
  883. AddChildren(user, true, result, true, query);
  884. return result.Values;
  885. }
  886. /// <summary>
  887. /// Gets the recursive children.
  888. /// </summary>
  889. /// <returns>IList{BaseItem}.</returns>
  890. public IList<BaseItem> GetRecursiveChildren()
  891. {
  892. return GetRecursiveChildren(i => true);
  893. }
  894. public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter)
  895. {
  896. var result = new Dictionary<Guid, BaseItem>();
  897. AddChildrenToList(result, true, true, filter);
  898. return result.Values.ToList();
  899. }
  900. /// <summary>
  901. /// Adds the children to list.
  902. /// </summary>
  903. private void AddChildrenToList(Dictionary<Guid, BaseItem> result, bool includeLinkedChildren, bool recursive, Func<BaseItem, bool> filter)
  904. {
  905. foreach (var child in Children)
  906. {
  907. if (filter == null || filter(child))
  908. {
  909. result[child.Id] = child;
  910. }
  911. if (recursive && child.IsFolder)
  912. {
  913. var folder = (Folder)child;
  914. // We can only support includeLinkedChildren for the first folder, or we might end up stuck in a loop of linked items
  915. folder.AddChildrenToList(result, false, true, filter);
  916. }
  917. }
  918. if (includeLinkedChildren)
  919. {
  920. foreach (var child in GetLinkedChildren())
  921. {
  922. if (filter == null || filter(child))
  923. {
  924. result[child.Id] = child;
  925. }
  926. }
  927. }
  928. }
  929. /// <summary>
  930. /// Gets the linked children.
  931. /// </summary>
  932. /// <returns>IEnumerable{BaseItem}.</returns>
  933. public IEnumerable<BaseItem> GetLinkedChildren()
  934. {
  935. return LinkedChildren
  936. .Select(GetLinkedChild)
  937. .Where(i => i != null);
  938. }
  939. protected virtual bool FilterLinkedChildrenPerUser
  940. {
  941. get
  942. {
  943. return false;
  944. }
  945. }
  946. public IEnumerable<BaseItem> GetLinkedChildren(User user)
  947. {
  948. if (!FilterLinkedChildrenPerUser || user == null)
  949. {
  950. return GetLinkedChildren();
  951. }
  952. var locations = user.RootFolder
  953. .Children
  954. .OfType<CollectionFolder>()
  955. .Where(i => i.IsVisible(user))
  956. .SelectMany(i => i.PhysicalLocations)
  957. .ToList();
  958. return LinkedChildren
  959. .Select(i =>
  960. {
  961. var requiresPostFilter = true;
  962. if (!string.IsNullOrWhiteSpace(i.Path))
  963. {
  964. requiresPostFilter = false;
  965. if (!locations.Any(l => FileSystem.ContainsSubPath(l, i.Path)))
  966. {
  967. return null;
  968. }
  969. }
  970. var child = GetLinkedChild(i);
  971. if (requiresPostFilter && child != null)
  972. {
  973. if (string.IsNullOrWhiteSpace(child.Path))
  974. {
  975. Logger.Debug("Found LinkedChild with null path: {0}", child.Name);
  976. return child;
  977. }
  978. if (!locations.Any(l => FileSystem.ContainsSubPath(l, child.Path)))
  979. {
  980. return null;
  981. }
  982. }
  983. return child;
  984. })
  985. .Where(i => i != null);
  986. }
  987. /// <summary>
  988. /// Gets the linked children.
  989. /// </summary>
  990. /// <returns>IEnumerable{BaseItem}.</returns>
  991. public IEnumerable<Tuple<LinkedChild, BaseItem>> GetLinkedChildrenInfos()
  992. {
  993. return LinkedChildren
  994. .Select(i => new Tuple<LinkedChild, BaseItem>(i, GetLinkedChild(i)))
  995. .Where(i => i.Item2 != null);
  996. }
  997. [IgnoreDataMember]
  998. protected override bool SupportsOwnedItems
  999. {
  1000. get
  1001. {
  1002. return base.SupportsOwnedItems || SupportsShortcutChildren;
  1003. }
  1004. }
  1005. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  1006. {
  1007. var changesFound = false;
  1008. if (LocationType == LocationType.FileSystem)
  1009. {
  1010. if (RefreshLinkedChildren(fileSystemChildren))
  1011. {
  1012. changesFound = true;
  1013. }
  1014. }
  1015. var baseHasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  1016. return baseHasChanges || changesFound;
  1017. }
  1018. /// <summary>
  1019. /// Refreshes the linked children.
  1020. /// </summary>
  1021. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  1022. private bool RefreshLinkedChildren(IEnumerable<FileSystemMetadata> fileSystemChildren)
  1023. {
  1024. var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList();
  1025. var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList();
  1026. List<LinkedChild> newShortcutLinks;
  1027. if (SupportsShortcutChildren)
  1028. {
  1029. newShortcutLinks = fileSystemChildren
  1030. .Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory && FileSystem.IsShortcut(i.FullName))
  1031. .Select(i =>
  1032. {
  1033. try
  1034. {
  1035. Logger.Debug("Found shortcut at {0}", i.FullName);
  1036. var resolvedPath = FileSystem.ResolveShortcut(i.FullName);
  1037. if (!string.IsNullOrEmpty(resolvedPath))
  1038. {
  1039. return new LinkedChild
  1040. {
  1041. Path = resolvedPath,
  1042. Type = LinkedChildType.Shortcut
  1043. };
  1044. }
  1045. Logger.Error("Error resolving shortcut {0}", i.FullName);
  1046. return null;
  1047. }
  1048. catch (IOException ex)
  1049. {
  1050. Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName);
  1051. return null;
  1052. }
  1053. })
  1054. .Where(i => i != null)
  1055. .ToList();
  1056. }
  1057. else { newShortcutLinks = new List<LinkedChild>(); }
  1058. if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer()))
  1059. {
  1060. Logger.Info("Shortcut links have changed for {0}", Path);
  1061. newShortcutLinks.AddRange(currentManualLinks);
  1062. LinkedChildren = newShortcutLinks;
  1063. return true;
  1064. }
  1065. foreach (var child in LinkedChildren)
  1066. {
  1067. // Reset the cached value
  1068. child.ItemId = null;
  1069. }
  1070. return false;
  1071. }
  1072. /// <summary>
  1073. /// Folders need to validate and refresh
  1074. /// </summary>
  1075. /// <returns>Task.</returns>
  1076. public override async Task ChangedExternally()
  1077. {
  1078. var progress = new Progress<double>();
  1079. await ValidateChildren(progress, CancellationToken.None).ConfigureAwait(false);
  1080. await base.ChangedExternally().ConfigureAwait(false);
  1081. }
  1082. /// <summary>
  1083. /// Marks the played.
  1084. /// </summary>
  1085. /// <param name="user">The user.</param>
  1086. /// <param name="datePlayed">The date played.</param>
  1087. /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
  1088. /// <returns>Task.</returns>
  1089. public override async Task MarkPlayed(User user,
  1090. DateTime? datePlayed,
  1091. bool resetPosition)
  1092. {
  1093. var query = new InternalItemsQuery
  1094. {
  1095. User = user,
  1096. Recursive = true,
  1097. IsFolder = false,
  1098. EnableTotalRecordCount = false
  1099. };
  1100. if (!user.Configuration.DisplayMissingEpisodes || !user.Configuration.DisplayUnairedEpisodes)
  1101. {
  1102. query.ExcludeLocationTypes = new[] { LocationType.Virtual };
  1103. }
  1104. var itemsResult = await GetItems(query).ConfigureAwait(false);
  1105. // Sweep through recursively and update status
  1106. var tasks = itemsResult.Items.Select(c => c.MarkPlayed(user, datePlayed, resetPosition));
  1107. await Task.WhenAll(tasks).ConfigureAwait(false);
  1108. }
  1109. /// <summary>
  1110. /// Marks the unplayed.
  1111. /// </summary>
  1112. /// <param name="user">The user.</param>
  1113. /// <returns>Task.</returns>
  1114. public override async Task MarkUnplayed(User user)
  1115. {
  1116. var itemsResult = await GetItems(new InternalItemsQuery
  1117. {
  1118. User = user,
  1119. Recursive = true,
  1120. IsFolder = false,
  1121. EnableTotalRecordCount = false
  1122. }).ConfigureAwait(false);
  1123. // Sweep through recursively and update status
  1124. var tasks = itemsResult.Items.Select(c => c.MarkUnplayed(user));
  1125. await Task.WhenAll(tasks).ConfigureAwait(false);
  1126. }
  1127. public override bool IsPlayed(User user)
  1128. {
  1129. var itemsResult = GetItems(new InternalItemsQuery(user)
  1130. {
  1131. Recursive = true,
  1132. IsFolder = false,
  1133. ExcludeLocationTypes = new[] { LocationType.Virtual },
  1134. EnableTotalRecordCount = false
  1135. }).Result;
  1136. return itemsResult.Items
  1137. .All(i => i.IsPlayed(user));
  1138. }
  1139. public override bool IsUnplayed(User user)
  1140. {
  1141. return !IsPlayed(user);
  1142. }
  1143. [IgnoreDataMember]
  1144. public virtual bool SupportsUserDataFromChildren
  1145. {
  1146. get
  1147. {
  1148. // These are just far too slow.
  1149. if (this is ICollectionFolder)
  1150. {
  1151. return false;
  1152. }
  1153. if (this is UserView)
  1154. {
  1155. return false;
  1156. }
  1157. if (this is UserRootFolder)
  1158. {
  1159. return false;
  1160. }
  1161. if (this is Channel)
  1162. {
  1163. return false;
  1164. }
  1165. if (SourceType != SourceType.Library)
  1166. {
  1167. return false;
  1168. }
  1169. return true;
  1170. }
  1171. }
  1172. public override async Task FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user)
  1173. {
  1174. if (!SupportsUserDataFromChildren)
  1175. {
  1176. return;
  1177. }
  1178. var unplayedQueryResult = await GetItems(new InternalItemsQuery(user)
  1179. {
  1180. Recursive = true,
  1181. IsFolder = false,
  1182. IsVirtualItem = false,
  1183. EnableTotalRecordCount = true,
  1184. Limit = 0,
  1185. IsPlayed = false
  1186. }).ConfigureAwait(false);
  1187. var allItemsQueryResult = await GetItems(new InternalItemsQuery(user)
  1188. {
  1189. Recursive = true,
  1190. IsFolder = false,
  1191. IsVirtualItem = false,
  1192. EnableTotalRecordCount = true,
  1193. Limit = 0
  1194. }).ConfigureAwait(false);
  1195. if (itemDto != null)
  1196. {
  1197. itemDto.RecursiveItemCount = allItemsQueryResult.TotalRecordCount;
  1198. }
  1199. var recursiveItemCount = allItemsQueryResult.TotalRecordCount;
  1200. double unplayedCount = unplayedQueryResult.TotalRecordCount;
  1201. if (recursiveItemCount > 0)
  1202. {
  1203. var unplayedPercentage = (unplayedCount / recursiveItemCount) * 100;
  1204. dto.PlayedPercentage = 100 - unplayedPercentage;
  1205. dto.Played = dto.PlayedPercentage.Value >= 100;
  1206. dto.UnplayedItemCount = unplayedQueryResult.TotalRecordCount;
  1207. }
  1208. if (itemDto != null)
  1209. {
  1210. if (this is Season || this is MusicAlbum)
  1211. {
  1212. itemDto.ChildCount = recursiveItemCount;
  1213. }
  1214. }
  1215. }
  1216. }
  1217. }