BaseItem.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.Localization;
  6. using MediaBrowser.Controller.Persistence;
  7. using MediaBrowser.Controller.Providers;
  8. using MediaBrowser.Model.Configuration;
  9. using MediaBrowser.Model.Entities;
  10. using MediaBrowser.Model.Logging;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.Serialization;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. namespace MediaBrowser.Controller.Entities
  19. {
  20. /// <summary>
  21. /// Class BaseItem
  22. /// </summary>
  23. public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData, IHasMetadata, IHasLookupInfo<ItemLookupInfo>
  24. {
  25. protected BaseItem()
  26. {
  27. Genres = new List<string>();
  28. Studios = new List<string>();
  29. People = new List<PersonInfo>();
  30. ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  31. LockedFields = new List<MetadataFields>();
  32. ImageInfos = new List<ItemImageInfo>();
  33. }
  34. /// <summary>
  35. /// The supported image extensions
  36. /// </summary>
  37. public static readonly string[] SupportedImageExtensions = new[] { ".png", ".jpg", ".jpeg", ".tbn" };
  38. /// <summary>
  39. /// The trailer folder name
  40. /// </summary>
  41. public const string TrailerFolderName = "trailers";
  42. public const string ThemeSongsFolderName = "theme-music";
  43. public const string ThemeSongFilename = "theme";
  44. public const string ThemeVideosFolderName = "backdrops";
  45. public const string XbmcTrailerFileSuffix = "-trailer";
  46. public List<ItemImageInfo> ImageInfos { get; set; }
  47. /// <summary>
  48. /// Gets a value indicating whether this instance is in mixed folder.
  49. /// </summary>
  50. /// <value><c>true</c> if this instance is in mixed folder; otherwise, <c>false</c>.</value>
  51. public bool IsInMixedFolder { get; set; }
  52. private string _name;
  53. /// <summary>
  54. /// Gets or sets the name.
  55. /// </summary>
  56. /// <value>The name.</value>
  57. public string Name
  58. {
  59. get
  60. {
  61. return _name;
  62. }
  63. set
  64. {
  65. _name = value;
  66. // lazy load this again
  67. _sortName = null;
  68. }
  69. }
  70. /// <summary>
  71. /// Gets or sets the id.
  72. /// </summary>
  73. /// <value>The id.</value>
  74. public Guid Id { get; set; }
  75. /// <summary>
  76. /// Return the id that should be used to key display prefs for this item.
  77. /// Default is based on the type for everything except actual generic folders.
  78. /// </summary>
  79. /// <value>The display prefs id.</value>
  80. [IgnoreDataMember]
  81. public virtual Guid DisplayPreferencesId
  82. {
  83. get
  84. {
  85. var thisType = GetType();
  86. return thisType == typeof(Folder) ? Id : thisType.FullName.GetMD5();
  87. }
  88. }
  89. /// <summary>
  90. /// Gets or sets the path.
  91. /// </summary>
  92. /// <value>The path.</value>
  93. public virtual string Path { get; set; }
  94. [IgnoreDataMember]
  95. protected internal bool IsOffline { get; set; }
  96. /// <summary>
  97. /// Returns the folder containing the item.
  98. /// If the item is a folder, it returns the folder itself
  99. /// </summary>
  100. [IgnoreDataMember]
  101. public virtual string ContainingFolderPath
  102. {
  103. get
  104. {
  105. if (IsFolder)
  106. {
  107. return Path;
  108. }
  109. return System.IO.Path.GetDirectoryName(Path);
  110. }
  111. }
  112. [IgnoreDataMember]
  113. public virtual bool IsOwnedItem
  114. {
  115. get
  116. {
  117. // Local trailer, special feature, theme video, etc.
  118. // An item that belongs to another item but is not part of the Parent-Child tree
  119. return !IsFolder && Parent == null;
  120. }
  121. }
  122. /// <summary>
  123. /// Gets or sets the type of the location.
  124. /// </summary>
  125. /// <value>The type of the location.</value>
  126. [IgnoreDataMember]
  127. public virtual LocationType LocationType
  128. {
  129. get
  130. {
  131. if (IsOffline)
  132. {
  133. return LocationType.Offline;
  134. }
  135. if (string.IsNullOrEmpty(Path))
  136. {
  137. return LocationType.Virtual;
  138. }
  139. return System.IO.Path.IsPathRooted(Path) ? LocationType.FileSystem : LocationType.Remote;
  140. }
  141. }
  142. /// <summary>
  143. /// This is just a helper for convenience
  144. /// </summary>
  145. /// <value>The primary image path.</value>
  146. [IgnoreDataMember]
  147. public string PrimaryImagePath
  148. {
  149. get { return this.GetImagePath(ImageType.Primary); }
  150. }
  151. /// <summary>
  152. /// Gets or sets the date created.
  153. /// </summary>
  154. /// <value>The date created.</value>
  155. public DateTime DateCreated { get; set; }
  156. /// <summary>
  157. /// Gets or sets the date modified.
  158. /// </summary>
  159. /// <value>The date modified.</value>
  160. public DateTime DateModified { get; set; }
  161. public DateTime DateLastSaved { get; set; }
  162. /// <summary>
  163. /// The logger
  164. /// </summary>
  165. public static ILogger Logger { get; set; }
  166. public static ILibraryManager LibraryManager { get; set; }
  167. public static IServerConfigurationManager ConfigurationManager { get; set; }
  168. public static IProviderManager ProviderManager { get; set; }
  169. public static ILocalizationManager LocalizationManager { get; set; }
  170. public static IItemRepository ItemRepository { get; set; }
  171. public static IFileSystem FileSystem { get; set; }
  172. public static IUserDataManager UserDataManager { get; set; }
  173. /// <summary>
  174. /// Returns a <see cref="System.String" /> that represents this instance.
  175. /// </summary>
  176. /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
  177. public override string ToString()
  178. {
  179. return Name;
  180. }
  181. /// <summary>
  182. /// Returns true if this item should not attempt to fetch metadata
  183. /// </summary>
  184. /// <value><c>true</c> if [dont fetch meta]; otherwise, <c>false</c>.</value>
  185. public bool DontFetchMeta { get; set; }
  186. /// <summary>
  187. /// Gets or sets the locked fields.
  188. /// </summary>
  189. /// <value>The locked fields.</value>
  190. public List<MetadataFields> LockedFields { get; set; }
  191. /// <summary>
  192. /// Gets the type of the media.
  193. /// </summary>
  194. /// <value>The type of the media.</value>
  195. [IgnoreDataMember]
  196. public virtual string MediaType
  197. {
  198. get
  199. {
  200. return null;
  201. }
  202. }
  203. [IgnoreDataMember]
  204. public virtual IEnumerable<string> PhysicalLocations
  205. {
  206. get
  207. {
  208. var locationType = LocationType;
  209. if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
  210. {
  211. return new string[] { };
  212. }
  213. return new[] { Path };
  214. }
  215. }
  216. private string _forcedSortName;
  217. /// <summary>
  218. /// Gets or sets the name of the forced sort.
  219. /// </summary>
  220. /// <value>The name of the forced sort.</value>
  221. public string ForcedSortName
  222. {
  223. get { return _forcedSortName; }
  224. set { _forcedSortName = value; _sortName = null; }
  225. }
  226. private string _sortName;
  227. /// <summary>
  228. /// Gets the name of the sort.
  229. /// </summary>
  230. /// <value>The name of the sort.</value>
  231. [IgnoreDataMember]
  232. public string SortName
  233. {
  234. get
  235. {
  236. if (!string.IsNullOrEmpty(ForcedSortName))
  237. {
  238. return ForcedSortName;
  239. }
  240. return _sortName ?? (_sortName = CreateSortName());
  241. }
  242. }
  243. /// <summary>
  244. /// Creates the name of the sort.
  245. /// </summary>
  246. /// <returns>System.String.</returns>
  247. protected virtual string CreateSortName()
  248. {
  249. if (Name == null) return null; //some items may not have name filled in properly
  250. var sortable = Name.Trim().ToLower();
  251. sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
  252. sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " "));
  253. foreach (var search in ConfigurationManager.Configuration.SortRemoveWords)
  254. {
  255. var searchLower = search.ToLower();
  256. // Remove from beginning if a space follows
  257. if (sortable.StartsWith(searchLower + " "))
  258. {
  259. sortable = sortable.Remove(0, searchLower.Length + 1);
  260. }
  261. // Remove from middle if surrounded by spaces
  262. sortable = sortable.Replace(" " + searchLower + " ", " ");
  263. // Remove from end if followed by a space
  264. if (sortable.EndsWith(" " + searchLower))
  265. {
  266. sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
  267. }
  268. }
  269. return sortable;
  270. }
  271. /// <summary>
  272. /// Gets or sets the parent.
  273. /// </summary>
  274. /// <value>The parent.</value>
  275. [IgnoreDataMember]
  276. public Folder Parent { get; set; }
  277. [IgnoreDataMember]
  278. public IEnumerable<Folder> Parents
  279. {
  280. get
  281. {
  282. var parent = Parent;
  283. while (parent != null)
  284. {
  285. yield return parent;
  286. parent = parent.Parent;
  287. }
  288. }
  289. }
  290. /// <summary>
  291. /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
  292. /// </summary>
  293. /// <value>The premiere date.</value>
  294. public DateTime? PremiereDate { get; set; }
  295. /// <summary>
  296. /// Gets or sets the end date.
  297. /// </summary>
  298. /// <value>The end date.</value>
  299. public DateTime? EndDate { get; set; }
  300. /// <summary>
  301. /// Gets or sets the display type of the media.
  302. /// </summary>
  303. /// <value>The display type of the media.</value>
  304. public string DisplayMediaType { get; set; }
  305. /// <summary>
  306. /// Gets or sets the official rating.
  307. /// </summary>
  308. /// <value>The official rating.</value>
  309. public string OfficialRating { get; set; }
  310. /// <summary>
  311. /// Gets or sets the official rating description.
  312. /// </summary>
  313. /// <value>The official rating description.</value>
  314. public string OfficialRatingDescription { get; set; }
  315. /// <summary>
  316. /// Gets or sets the custom rating.
  317. /// </summary>
  318. /// <value>The custom rating.</value>
  319. public string CustomRating { get; set; }
  320. /// <summary>
  321. /// Gets or sets the overview.
  322. /// </summary>
  323. /// <value>The overview.</value>
  324. public string Overview { get; set; }
  325. /// <summary>
  326. /// Gets or sets the people.
  327. /// </summary>
  328. /// <value>The people.</value>
  329. public List<PersonInfo> People { get; set; }
  330. /// <summary>
  331. /// Gets or sets the studios.
  332. /// </summary>
  333. /// <value>The studios.</value>
  334. public List<string> Studios { get; set; }
  335. /// <summary>
  336. /// Gets or sets the genres.
  337. /// </summary>
  338. /// <value>The genres.</value>
  339. public List<string> Genres { get; set; }
  340. /// <summary>
  341. /// Gets or sets the home page URL.
  342. /// </summary>
  343. /// <value>The home page URL.</value>
  344. public string HomePageUrl { get; set; }
  345. /// <summary>
  346. /// Gets or sets the community rating.
  347. /// </summary>
  348. /// <value>The community rating.</value>
  349. public float? CommunityRating { get; set; }
  350. /// <summary>
  351. /// Gets or sets the community rating vote count.
  352. /// </summary>
  353. /// <value>The community rating vote count.</value>
  354. public int? VoteCount { get; set; }
  355. /// <summary>
  356. /// Gets or sets the run time ticks.
  357. /// </summary>
  358. /// <value>The run time ticks.</value>
  359. public long? RunTimeTicks { get; set; }
  360. /// <summary>
  361. /// Gets or sets the production year.
  362. /// </summary>
  363. /// <value>The production year.</value>
  364. public int? ProductionYear { get; set; }
  365. /// <summary>
  366. /// If the item is part of a series, this is it's number in the series.
  367. /// This could be episode number, album track number, etc.
  368. /// </summary>
  369. /// <value>The index number.</value>
  370. public int? IndexNumber { get; set; }
  371. /// <summary>
  372. /// For an episode this could be the season number, or for a song this could be the disc number.
  373. /// </summary>
  374. /// <value>The parent index number.</value>
  375. public int? ParentIndexNumber { get; set; }
  376. [IgnoreDataMember]
  377. public virtual string OfficialRatingForComparison
  378. {
  379. get { return OfficialRating; }
  380. }
  381. [IgnoreDataMember]
  382. public string CustomRatingForComparison
  383. {
  384. get
  385. {
  386. if (!string.IsNullOrEmpty(CustomRating))
  387. {
  388. return CustomRating;
  389. }
  390. var parent = Parent;
  391. if (parent != null)
  392. {
  393. return parent.CustomRatingForComparison;
  394. }
  395. return null;
  396. }
  397. }
  398. /// <summary>
  399. /// Loads local trailers from the file system
  400. /// </summary>
  401. /// <returns>List{Video}.</returns>
  402. private IEnumerable<Trailer> LoadLocalTrailers(List<FileSystemInfo> fileSystemChildren)
  403. {
  404. var files = fileSystemChildren.OfType<DirectoryInfo>()
  405. .Where(i => string.Equals(i.Name, TrailerFolderName, StringComparison.OrdinalIgnoreCase))
  406. .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
  407. .ToList();
  408. // Support plex/xbmc convention
  409. files.AddRange(fileSystemChildren.OfType<FileInfo>()
  410. .Where(i => System.IO.Path.GetFileNameWithoutExtension(i.Name).EndsWith(XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) && !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase))
  411. );
  412. return LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
  413. {
  414. // Try to retrieve it from the db. If we don't find it, use the resolved version
  415. var dbItem = LibraryManager.GetItemById(video.Id) as Trailer;
  416. if (dbItem != null)
  417. {
  418. video = dbItem;
  419. }
  420. return video;
  421. // Sort them so that the list can be easily compared for changes
  422. }).OrderBy(i => i.Path).ToList();
  423. }
  424. /// <summary>
  425. /// Loads the theme songs.
  426. /// </summary>
  427. /// <returns>List{Audio.Audio}.</returns>
  428. private IEnumerable<Audio.Audio> LoadThemeSongs(List<FileSystemInfo> fileSystemChildren)
  429. {
  430. var files = fileSystemChildren.OfType<DirectoryInfo>()
  431. .Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  432. .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
  433. .ToList();
  434. // Support plex/xbmc convention
  435. files.AddRange(fileSystemChildren.OfType<FileInfo>()
  436. .Where(i => string.Equals(System.IO.Path.GetFileNameWithoutExtension(i.Name), ThemeSongFilename, StringComparison.OrdinalIgnoreCase))
  437. );
  438. return LibraryManager.ResolvePaths<Audio.Audio>(files, null).Select(audio =>
  439. {
  440. // Try to retrieve it from the db. If we don't find it, use the resolved version
  441. var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio;
  442. if (dbItem != null)
  443. {
  444. audio = dbItem;
  445. }
  446. return audio;
  447. // Sort them so that the list can be easily compared for changes
  448. }).OrderBy(i => i.Path).ToList();
  449. }
  450. /// <summary>
  451. /// Loads the video backdrops.
  452. /// </summary>
  453. /// <returns>List{Video}.</returns>
  454. private IEnumerable<Video> LoadThemeVideos(IEnumerable<FileSystemInfo> fileSystemChildren)
  455. {
  456. var files = fileSystemChildren.OfType<DirectoryInfo>()
  457. .Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  458. .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly));
  459. return LibraryManager.ResolvePaths<Video>(files, null).Select(item =>
  460. {
  461. // Try to retrieve it from the db. If we don't find it, use the resolved version
  462. var dbItem = LibraryManager.GetItemById(item.Id) as Video;
  463. if (dbItem != null)
  464. {
  465. item = dbItem;
  466. }
  467. return item;
  468. // Sort them so that the list can be easily compared for changes
  469. }).OrderBy(i => i.Path).ToList();
  470. }
  471. public Task RefreshMetadata(CancellationToken cancellationToken)
  472. {
  473. return RefreshMetadata(new MetadataRefreshOptions(), cancellationToken);
  474. }
  475. /// <summary>
  476. /// Overrides the base implementation to refresh metadata for local trailers
  477. /// </summary>
  478. /// <param name="options">The options.</param>
  479. /// <param name="cancellationToken">The cancellation token.</param>
  480. /// <returns>true if a provider reports we changed</returns>
  481. public async Task RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken)
  482. {
  483. var locationType = LocationType;
  484. if (IsFolder || Parent != null)
  485. {
  486. options.DirectoryService = options.DirectoryService ?? new DirectoryService(Logger);
  487. var files = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
  488. GetFileSystemChildren(options.DirectoryService).ToList() :
  489. new List<FileSystemInfo>();
  490. await BeforeRefreshMetadata(options, files, cancellationToken).ConfigureAwait(false);
  491. }
  492. await ProviderManager.RefreshMetadata(this, options, cancellationToken).ConfigureAwait(false);
  493. }
  494. protected virtual async Task BeforeRefreshMetadata(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  495. {
  496. var themeSongsChanged = false;
  497. var themeVideosChanged = false;
  498. var localTrailersChanged = false;
  499. if (LocationType == LocationType.FileSystem && Parent != null)
  500. {
  501. var hasThemeMedia = this as IHasThemeMedia;
  502. if (hasThemeMedia != null)
  503. {
  504. if (!IsInMixedFolder)
  505. {
  506. themeSongsChanged = await RefreshThemeSongs(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  507. themeVideosChanged = await RefreshThemeVideos(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  508. }
  509. }
  510. var hasTrailers = this as IHasTrailers;
  511. if (hasTrailers != null)
  512. {
  513. localTrailersChanged = await RefreshLocalTrailers(hasTrailers, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  514. }
  515. }
  516. if (themeSongsChanged || themeVideosChanged || localTrailersChanged)
  517. {
  518. options.ForceSave = true;
  519. }
  520. }
  521. protected virtual IEnumerable<FileSystemInfo> GetFileSystemChildren(DirectoryService directoryService)
  522. {
  523. var path = ContainingFolderPath;
  524. return directoryService.GetFileSystemEntries(path);
  525. }
  526. private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  527. {
  528. var newItems = LoadLocalTrailers(fileSystemChildren).ToList();
  529. var newItemIds = newItems.Select(i => i.Id).ToList();
  530. var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
  531. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  532. await Task.WhenAll(tasks).ConfigureAwait(false);
  533. item.LocalTrailerIds = newItemIds;
  534. return itemsChanged;
  535. }
  536. private async Task<bool> RefreshThemeVideos(IHasThemeMedia item, MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  537. {
  538. var newThemeVideos = LoadThemeVideos(fileSystemChildren).ToList();
  539. var newThemeVideoIds = newThemeVideos.Select(i => i.Id).ToList();
  540. var themeVideosChanged = !item.ThemeVideoIds.SequenceEqual(newThemeVideoIds);
  541. var tasks = newThemeVideos.Select(i => i.RefreshMetadata(options, cancellationToken));
  542. await Task.WhenAll(tasks).ConfigureAwait(false);
  543. item.ThemeVideoIds = newThemeVideoIds;
  544. return themeVideosChanged;
  545. }
  546. /// <summary>
  547. /// Refreshes the theme songs.
  548. /// </summary>
  549. private async Task<bool> RefreshThemeSongs(IHasThemeMedia item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  550. {
  551. var newThemeSongs = LoadThemeSongs(fileSystemChildren).ToList();
  552. var newThemeSongIds = newThemeSongs.Select(i => i.Id).ToList();
  553. var themeSongsChanged = !item.ThemeSongIds.SequenceEqual(newThemeSongIds);
  554. var tasks = newThemeSongs.Select(i => i.RefreshMetadata(options, cancellationToken));
  555. await Task.WhenAll(tasks).ConfigureAwait(false);
  556. item.ThemeSongIds = newThemeSongIds;
  557. return themeSongsChanged;
  558. }
  559. /// <summary>
  560. /// Gets or sets the provider ids.
  561. /// </summary>
  562. /// <value>The provider ids.</value>
  563. public Dictionary<string, string> ProviderIds { get; set; }
  564. /// <summary>
  565. /// Override this to false if class should be ignored for indexing purposes
  566. /// </summary>
  567. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  568. [IgnoreDataMember]
  569. public virtual bool IncludeInIndex
  570. {
  571. get { return true; }
  572. }
  573. /// <summary>
  574. /// Override this to true if class should be grouped under a container in indicies
  575. /// The container class should be defined via IndexContainer
  576. /// </summary>
  577. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  578. [IgnoreDataMember]
  579. public virtual bool GroupInIndex
  580. {
  581. get { return false; }
  582. }
  583. /// <summary>
  584. /// Override this to return the folder that should be used to construct a container
  585. /// for this item in an index. GroupInIndex should be true as well.
  586. /// </summary>
  587. /// <value>The index container.</value>
  588. [IgnoreDataMember]
  589. public virtual Folder IndexContainer
  590. {
  591. get { return null; }
  592. }
  593. /// <summary>
  594. /// Gets the user data key.
  595. /// </summary>
  596. /// <returns>System.String.</returns>
  597. public virtual string GetUserDataKey()
  598. {
  599. return Id.ToString();
  600. }
  601. /// <summary>
  602. /// Gets the preferred metadata language.
  603. /// </summary>
  604. /// <returns>System.String.</returns>
  605. public string GetPreferredMetadataLanguage()
  606. {
  607. string lang = null;
  608. var hasLang = this as IHasPreferredMetadataLanguage;
  609. if (hasLang != null)
  610. {
  611. lang = hasLang.PreferredMetadataLanguage;
  612. }
  613. if (string.IsNullOrEmpty(lang))
  614. {
  615. lang = Parents.OfType<IHasPreferredMetadataLanguage>()
  616. .Select(i => i.PreferredMetadataLanguage)
  617. .FirstOrDefault(i => !string.IsNullOrEmpty(i));
  618. }
  619. if (string.IsNullOrEmpty(lang))
  620. {
  621. lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
  622. }
  623. return lang;
  624. }
  625. /// <summary>
  626. /// Gets the preferred metadata language.
  627. /// </summary>
  628. /// <returns>System.String.</returns>
  629. public string GetPreferredMetadataCountryCode()
  630. {
  631. string lang = null;
  632. var hasLang = this as IHasPreferredMetadataLanguage;
  633. if (hasLang != null)
  634. {
  635. lang = hasLang.PreferredMetadataCountryCode;
  636. }
  637. if (string.IsNullOrEmpty(lang))
  638. {
  639. lang = Parents.OfType<IHasPreferredMetadataLanguage>()
  640. .Select(i => i.PreferredMetadataCountryCode)
  641. .FirstOrDefault(i => !string.IsNullOrEmpty(i));
  642. }
  643. if (string.IsNullOrEmpty(lang))
  644. {
  645. lang = ConfigurationManager.Configuration.MetadataCountryCode;
  646. }
  647. return lang;
  648. }
  649. public virtual bool IsSaveLocalMetadataEnabled()
  650. {
  651. return ConfigurationManager.Configuration.SaveLocalMeta;
  652. }
  653. /// <summary>
  654. /// Determines if a given user has access to this item
  655. /// </summary>
  656. /// <param name="user">The user.</param>
  657. /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
  658. /// <exception cref="System.ArgumentNullException">user</exception>
  659. public bool IsParentalAllowed(User user)
  660. {
  661. if (user == null)
  662. {
  663. throw new ArgumentNullException("user");
  664. }
  665. var maxAllowedRating = user.Configuration.MaxParentalRating;
  666. if (maxAllowedRating == null)
  667. {
  668. return true;
  669. }
  670. var rating = CustomRatingForComparison;
  671. if (string.IsNullOrEmpty(rating))
  672. {
  673. rating = OfficialRatingForComparison;
  674. }
  675. if (string.IsNullOrEmpty(rating))
  676. {
  677. return !GetBlockUnratedValue(user.Configuration);
  678. }
  679. var value = LocalizationManager.GetRatingLevel(rating);
  680. // Could not determine the integer value
  681. if (!value.HasValue)
  682. {
  683. return true;
  684. }
  685. return value.Value <= maxAllowedRating.Value;
  686. }
  687. /// <summary>
  688. /// Gets the block unrated value.
  689. /// </summary>
  690. /// <param name="config">The configuration.</param>
  691. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  692. protected virtual bool GetBlockUnratedValue(UserConfiguration config)
  693. {
  694. return config.BlockNotRated;
  695. }
  696. /// <summary>
  697. /// Determines if this folder should be visible to a given user.
  698. /// Default is just parental allowed. Can be overridden for more functionality.
  699. /// </summary>
  700. /// <param name="user">The user.</param>
  701. /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
  702. /// <exception cref="System.ArgumentNullException">user</exception>
  703. public virtual bool IsVisible(User user)
  704. {
  705. if (user == null)
  706. {
  707. throw new ArgumentNullException("user");
  708. }
  709. return IsParentalAllowed(user);
  710. }
  711. /// <summary>
  712. /// Gets a value indicating whether this instance is folder.
  713. /// </summary>
  714. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  715. [IgnoreDataMember]
  716. public virtual bool IsFolder
  717. {
  718. get
  719. {
  720. return false;
  721. }
  722. }
  723. /// <summary>
  724. /// Determine if we have changed vs the passed in copy
  725. /// </summary>
  726. /// <param name="copy">The copy.</param>
  727. /// <returns><c>true</c> if the specified copy has changed; otherwise, <c>false</c>.</returns>
  728. /// <exception cref="System.ArgumentNullException"></exception>
  729. public virtual bool HasChanged(BaseItem copy)
  730. {
  731. if (copy == null)
  732. {
  733. throw new ArgumentNullException();
  734. }
  735. if (IsInMixedFolder != copy.IsInMixedFolder)
  736. {
  737. Logger.Debug(Name + " changed due to different value for IsInMixedFolder.");
  738. return true;
  739. }
  740. var changed = copy.DateModified != DateModified;
  741. if (changed)
  742. {
  743. Logger.Debug(Name + " changed - original creation: " + DateCreated + " new creation: " + copy.DateCreated + " original modified: " + DateModified + " new modified: " + copy.DateModified);
  744. }
  745. return changed;
  746. }
  747. public virtual string GetClientTypeName()
  748. {
  749. return GetType().Name;
  750. }
  751. /// <summary>
  752. /// Determines if the item is considered new based on user settings
  753. /// </summary>
  754. /// <returns><c>true</c> if [is recently added] [the specified user]; otherwise, <c>false</c>.</returns>
  755. /// <exception cref="System.ArgumentNullException"></exception>
  756. public bool IsRecentlyAdded()
  757. {
  758. return (DateTime.UtcNow - DateCreated).TotalDays < ConfigurationManager.Configuration.RecentItemDays;
  759. }
  760. /// <summary>
  761. /// Adds a person to the item
  762. /// </summary>
  763. /// <param name="person">The person.</param>
  764. /// <exception cref="System.ArgumentNullException"></exception>
  765. public void AddPerson(PersonInfo person)
  766. {
  767. if (person == null)
  768. {
  769. throw new ArgumentNullException("person");
  770. }
  771. if (string.IsNullOrWhiteSpace(person.Name))
  772. {
  773. throw new ArgumentNullException();
  774. }
  775. // Normalize
  776. if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  777. {
  778. person.Type = PersonType.GuestStar;
  779. }
  780. else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
  781. {
  782. person.Type = PersonType.Director;
  783. }
  784. else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase))
  785. {
  786. person.Type = PersonType.Producer;
  787. }
  788. else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
  789. {
  790. person.Type = PersonType.Writer;
  791. }
  792. // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
  793. if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  794. {
  795. var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase));
  796. if (existing != null)
  797. {
  798. existing.Type = PersonType.GuestStar;
  799. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  800. return;
  801. }
  802. }
  803. if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
  804. {
  805. // If the actor already exists without a role and we have one, fill it in
  806. var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase) || p.Type.Equals(PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)));
  807. if (existing == null)
  808. {
  809. // Wasn't there - add it
  810. People.Add(person);
  811. }
  812. else
  813. {
  814. // Was there, if no role and we have one - fill it in
  815. if (string.IsNullOrWhiteSpace(existing.Role) && !string.IsNullOrWhiteSpace(person.Role))
  816. {
  817. existing.Role = person.Role;
  818. }
  819. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  820. }
  821. }
  822. else
  823. {
  824. var existing = People.FirstOrDefault(p =>
  825. string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) &&
  826. string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase));
  827. // Check for dupes based on the combination of Name and Type
  828. if (existing == null)
  829. {
  830. People.Add(person);
  831. }
  832. else
  833. {
  834. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  835. }
  836. }
  837. }
  838. /// <summary>
  839. /// Adds a studio to the item
  840. /// </summary>
  841. /// <param name="name">The name.</param>
  842. /// <exception cref="System.ArgumentNullException"></exception>
  843. public void AddStudio(string name)
  844. {
  845. if (string.IsNullOrWhiteSpace(name))
  846. {
  847. throw new ArgumentNullException("name");
  848. }
  849. if (!Studios.Contains(name, StringComparer.OrdinalIgnoreCase))
  850. {
  851. Studios.Add(name);
  852. }
  853. }
  854. /// <summary>
  855. /// Adds a genre to the item
  856. /// </summary>
  857. /// <param name="name">The name.</param>
  858. /// <exception cref="System.ArgumentNullException"></exception>
  859. public void AddGenre(string name)
  860. {
  861. if (string.IsNullOrWhiteSpace(name))
  862. {
  863. throw new ArgumentNullException("name");
  864. }
  865. if (!Genres.Contains(name, StringComparer.OrdinalIgnoreCase))
  866. {
  867. Genres.Add(name);
  868. }
  869. }
  870. /// <summary>
  871. /// Marks the played.
  872. /// </summary>
  873. /// <param name="user">The user.</param>
  874. /// <param name="datePlayed">The date played.</param>
  875. /// <param name="userManager">The user manager.</param>
  876. /// <returns>Task.</returns>
  877. /// <exception cref="System.ArgumentNullException"></exception>
  878. public virtual async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataManager userManager)
  879. {
  880. if (user == null)
  881. {
  882. throw new ArgumentNullException();
  883. }
  884. var key = GetUserDataKey();
  885. var data = userManager.GetUserData(user.Id, key);
  886. if (datePlayed.HasValue)
  887. {
  888. // Incremenet
  889. data.PlayCount++;
  890. }
  891. // Ensure it's at least one
  892. data.PlayCount = Math.Max(data.PlayCount, 1);
  893. data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
  894. data.Played = true;
  895. await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  896. }
  897. /// <summary>
  898. /// Marks the unplayed.
  899. /// </summary>
  900. /// <param name="user">The user.</param>
  901. /// <param name="userManager">The user manager.</param>
  902. /// <returns>Task.</returns>
  903. /// <exception cref="System.ArgumentNullException"></exception>
  904. public virtual async Task MarkUnplayed(User user, IUserDataManager userManager)
  905. {
  906. if (user == null)
  907. {
  908. throw new ArgumentNullException();
  909. }
  910. var key = GetUserDataKey();
  911. var data = userManager.GetUserData(user.Id, key);
  912. //I think it is okay to do this here.
  913. // if this is only called when a user is manually forcing something to un-played
  914. // then it probably is what we want to do...
  915. data.PlayCount = 0;
  916. data.PlaybackPositionTicks = 0;
  917. data.LastPlayedDate = null;
  918. data.Played = false;
  919. await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  920. }
  921. /// <summary>
  922. /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
  923. /// </summary>
  924. /// <returns>Task.</returns>
  925. public virtual Task ChangedExternally()
  926. {
  927. return RefreshMetadata(CancellationToken.None);
  928. }
  929. /// <summary>
  930. /// Finds a parent of a given type
  931. /// </summary>
  932. /// <typeparam name="T"></typeparam>
  933. /// <returns>``0.</returns>
  934. public T FindParent<T>()
  935. where T : Folder
  936. {
  937. var parent = Parent;
  938. while (parent != null)
  939. {
  940. var result = parent as T;
  941. if (result != null)
  942. {
  943. return result;
  944. }
  945. parent = parent.Parent;
  946. }
  947. return null;
  948. }
  949. /// <summary>
  950. /// Gets an image
  951. /// </summary>
  952. /// <param name="type">The type.</param>
  953. /// <param name="imageIndex">Index of the image.</param>
  954. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  955. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  956. public bool HasImage(ImageType type, int imageIndex)
  957. {
  958. return GetImageInfo(type, imageIndex) != null;
  959. }
  960. public void SetImagePath(ImageType type, int index, FileInfo file)
  961. {
  962. if (type == ImageType.Chapter)
  963. {
  964. throw new ArgumentException("Cannot set chapter images using SetImagePath");
  965. }
  966. var image = GetImageInfo(type, index);
  967. if (image == null)
  968. {
  969. ImageInfos.Add(new ItemImageInfo
  970. {
  971. Path = file.FullName,
  972. Type = type,
  973. DateModified = FileSystem.GetLastWriteTimeUtc(file)
  974. });
  975. }
  976. else
  977. {
  978. image.Path = file.FullName;
  979. image.DateModified = FileSystem.GetLastWriteTimeUtc(file);
  980. }
  981. }
  982. /// <summary>
  983. /// Deletes the image.
  984. /// </summary>
  985. /// <param name="type">The type.</param>
  986. /// <param name="index">The index.</param>
  987. /// <returns>Task.</returns>
  988. public Task DeleteImage(ImageType type, int index)
  989. {
  990. var info = GetImageInfo(type, index);
  991. if (info == null)
  992. {
  993. // Nothing to do
  994. return Task.FromResult(true);
  995. }
  996. // Remove it from the item
  997. ImageInfos.Remove(info);
  998. // Delete the source file
  999. var currentFile = new FileInfo(info.Path);
  1000. // Deletion will fail if the file is hidden so remove the attribute first
  1001. if (currentFile.Exists)
  1002. {
  1003. if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  1004. {
  1005. currentFile.Attributes &= ~FileAttributes.Hidden;
  1006. }
  1007. currentFile.Delete();
  1008. }
  1009. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1010. }
  1011. public virtual Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  1012. {
  1013. return LibraryManager.UpdateItem(this, ItemUpdateType.ImageUpdate, cancellationToken);
  1014. }
  1015. /// <summary>
  1016. /// Validates that images within the item are still on the file system
  1017. /// </summary>
  1018. public bool ValidateImages(DirectoryService directoryService)
  1019. {
  1020. var allDirectories = ImageInfos.Select(i => System.IO.Path.GetDirectoryName(i.Path)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
  1021. var allFiles = allDirectories.SelectMany(directoryService.GetFiles).Select(i => i.FullName).ToList();
  1022. var deletedImages = ImageInfos
  1023. .Where(image => !allFiles.Contains(image.Path, StringComparer.OrdinalIgnoreCase))
  1024. .ToList();
  1025. if (deletedImages.Count > 0)
  1026. {
  1027. ImageInfos = ImageInfos.Except(deletedImages).ToList();
  1028. }
  1029. return deletedImages.Count > 0;
  1030. }
  1031. /// <summary>
  1032. /// Gets the image path.
  1033. /// </summary>
  1034. /// <param name="imageType">Type of the image.</param>
  1035. /// <param name="imageIndex">Index of the image.</param>
  1036. /// <returns>System.String.</returns>
  1037. /// <exception cref="System.InvalidOperationException">
  1038. /// </exception>
  1039. /// <exception cref="System.ArgumentNullException">item</exception>
  1040. public string GetImagePath(ImageType imageType, int imageIndex)
  1041. {
  1042. var info = GetImageInfo(imageType, imageIndex);
  1043. return info == null ? null : info.Path;
  1044. }
  1045. /// <summary>
  1046. /// Gets the image information.
  1047. /// </summary>
  1048. /// <param name="imageType">Type of the image.</param>
  1049. /// <param name="imageIndex">Index of the image.</param>
  1050. /// <returns>ItemImageInfo.</returns>
  1051. public ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex)
  1052. {
  1053. if (imageType == ImageType.Chapter)
  1054. {
  1055. var chapter = ItemRepository.GetChapter(Id, imageIndex);
  1056. if (chapter == null)
  1057. {
  1058. return null;
  1059. }
  1060. var path = chapter.ImagePath;
  1061. if (string.IsNullOrWhiteSpace(path))
  1062. {
  1063. return null;
  1064. }
  1065. return new ItemImageInfo
  1066. {
  1067. Path = path,
  1068. DateModified = FileSystem.GetLastWriteTimeUtc(path),
  1069. Type = imageType
  1070. };
  1071. }
  1072. return GetImages(imageType)
  1073. .ElementAtOrDefault(imageIndex);
  1074. }
  1075. public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
  1076. {
  1077. if (imageType == ImageType.Chapter)
  1078. {
  1079. throw new ArgumentException("No image info for chapter images");
  1080. }
  1081. return ImageInfos.Where(i => i.Type == imageType);
  1082. }
  1083. /// <summary>
  1084. /// Adds the images.
  1085. /// </summary>
  1086. /// <param name="imageType">Type of the image.</param>
  1087. /// <param name="images">The images.</param>
  1088. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  1089. /// <exception cref="System.ArgumentException">Cannot call AddImages with chapter images</exception>
  1090. public bool AddImages(ImageType imageType, IEnumerable<FileInfo> images)
  1091. {
  1092. if (imageType == ImageType.Chapter)
  1093. {
  1094. throw new ArgumentException("Cannot call AddImages with chapter images");
  1095. }
  1096. var existingImagePaths = GetImages(imageType)
  1097. .Select(i => i.Path)
  1098. .ToList();
  1099. var newImages = images
  1100. .Where(i => !existingImagePaths.Contains(i.FullName, StringComparer.OrdinalIgnoreCase))
  1101. .ToList();
  1102. ImageInfos.AddRange(newImages.Select(i => new ItemImageInfo
  1103. {
  1104. Path = i.FullName,
  1105. Type = imageType,
  1106. DateModified = FileSystem.GetLastWriteTimeUtc(i)
  1107. }));
  1108. return newImages.Count > 0;
  1109. }
  1110. /// <summary>
  1111. /// Gets the file system path to delete when the item is to be deleted
  1112. /// </summary>
  1113. /// <returns></returns>
  1114. public virtual IEnumerable<string> GetDeletePaths()
  1115. {
  1116. return new[] { Path };
  1117. }
  1118. public bool AllowsMultipleImages(ImageType type)
  1119. {
  1120. return type == ImageType.Backdrop || type == ImageType.Screenshot || type == ImageType.Chapter;
  1121. }
  1122. public Task SwapImages(ImageType type, int index1, int index2)
  1123. {
  1124. if (!AllowsMultipleImages(type))
  1125. {
  1126. throw new ArgumentException("The change index operation is only applicable to backdrops and screenshots");
  1127. }
  1128. var info1 = GetImageInfo(type, index1);
  1129. var info2 = GetImageInfo(type, index2);
  1130. if (info1 == null || info2 == null)
  1131. {
  1132. // Nothing to do
  1133. return Task.FromResult(true);
  1134. }
  1135. var path1 = info1.Path;
  1136. var path2 = info2.Path;
  1137. FileSystem.SwapFiles(path1, path2);
  1138. info1.Path = path2;
  1139. info2.Path = path1;
  1140. info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
  1141. info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
  1142. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1143. }
  1144. public virtual bool IsPlayed(User user)
  1145. {
  1146. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1147. return userdata != null && userdata.Played;
  1148. }
  1149. public virtual bool IsUnplayed(User user)
  1150. {
  1151. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1152. return userdata == null || !userdata.Played;
  1153. }
  1154. ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
  1155. {
  1156. return GetItemLookupInfo<ItemLookupInfo>();
  1157. }
  1158. protected T GetItemLookupInfo<T>()
  1159. where T : ItemLookupInfo, new()
  1160. {
  1161. return new T
  1162. {
  1163. MetadataCountryCode = GetPreferredMetadataCountryCode(),
  1164. MetadataLanguage = GetPreferredMetadataLanguage(),
  1165. Name = Name,
  1166. ProviderIds = ProviderIds,
  1167. IndexNumber = IndexNumber,
  1168. ParentIndexNumber = ParentIndexNumber
  1169. };
  1170. }
  1171. }
  1172. }