BaseItem.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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 or sets 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. var files = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
  487. GetFileSystemChildren().ToList() :
  488. new List<FileSystemInfo>();
  489. await BeforeRefreshMetadata(options, files, cancellationToken).ConfigureAwait(false);
  490. }
  491. await ProviderManager.RefreshMetadata(this, options, cancellationToken).ConfigureAwait(false);
  492. }
  493. protected virtual async Task BeforeRefreshMetadata(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  494. {
  495. var themeSongsChanged = false;
  496. var themeVideosChanged = false;
  497. var localTrailersChanged = false;
  498. if (LocationType == LocationType.FileSystem && Parent != null)
  499. {
  500. var hasThemeMedia = this as IHasThemeMedia;
  501. if (hasThemeMedia != null)
  502. {
  503. if (!IsInMixedFolder)
  504. {
  505. themeSongsChanged = await RefreshThemeSongs(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  506. themeVideosChanged = await RefreshThemeVideos(hasThemeMedia, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  507. }
  508. }
  509. var hasTrailers = this as IHasTrailers;
  510. if (hasTrailers != null)
  511. {
  512. localTrailersChanged = await RefreshLocalTrailers(hasTrailers, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  513. }
  514. }
  515. if (themeSongsChanged || themeVideosChanged || localTrailersChanged)
  516. {
  517. options.ForceSave = true;
  518. }
  519. }
  520. protected virtual IEnumerable<FileSystemInfo> GetFileSystemChildren()
  521. {
  522. var path = ContainingFolderPath;
  523. return new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly);
  524. }
  525. private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  526. {
  527. var newItems = LoadLocalTrailers(fileSystemChildren).ToList();
  528. var newItemIds = newItems.Select(i => i.Id).ToList();
  529. var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
  530. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  531. await Task.WhenAll(tasks).ConfigureAwait(false);
  532. item.LocalTrailerIds = newItemIds;
  533. return itemsChanged;
  534. }
  535. private async Task<bool> RefreshThemeVideos(IHasThemeMedia item, MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  536. {
  537. var newThemeVideos = LoadThemeVideos(fileSystemChildren).ToList();
  538. var newThemeVideoIds = newThemeVideos.Select(i => i.Id).ToList();
  539. var themeVideosChanged = !item.ThemeVideoIds.SequenceEqual(newThemeVideoIds);
  540. var tasks = newThemeVideos.Select(i => i.RefreshMetadata(options, cancellationToken));
  541. await Task.WhenAll(tasks).ConfigureAwait(false);
  542. item.ThemeVideoIds = newThemeVideoIds;
  543. return themeVideosChanged;
  544. }
  545. /// <summary>
  546. /// Refreshes the theme songs.
  547. /// </summary>
  548. private async Task<bool> RefreshThemeSongs(IHasThemeMedia item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  549. {
  550. var newThemeSongs = LoadThemeSongs(fileSystemChildren).ToList();
  551. var newThemeSongIds = newThemeSongs.Select(i => i.Id).ToList();
  552. var themeSongsChanged = !item.ThemeSongIds.SequenceEqual(newThemeSongIds);
  553. var tasks = newThemeSongs.Select(i => i.RefreshMetadata(options, cancellationToken));
  554. await Task.WhenAll(tasks).ConfigureAwait(false);
  555. item.ThemeSongIds = newThemeSongIds;
  556. return themeSongsChanged;
  557. }
  558. /// <summary>
  559. /// Gets or sets the provider ids.
  560. /// </summary>
  561. /// <value>The provider ids.</value>
  562. public Dictionary<string, string> ProviderIds { get; set; }
  563. /// <summary>
  564. /// Override this to false if class should be ignored for indexing purposes
  565. /// </summary>
  566. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  567. [IgnoreDataMember]
  568. public virtual bool IncludeInIndex
  569. {
  570. get { return true; }
  571. }
  572. /// <summary>
  573. /// Override this to true if class should be grouped under a container in indicies
  574. /// The container class should be defined via IndexContainer
  575. /// </summary>
  576. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  577. [IgnoreDataMember]
  578. public virtual bool GroupInIndex
  579. {
  580. get { return false; }
  581. }
  582. /// <summary>
  583. /// Override this to return the folder that should be used to construct a container
  584. /// for this item in an index. GroupInIndex should be true as well.
  585. /// </summary>
  586. /// <value>The index container.</value>
  587. [IgnoreDataMember]
  588. public virtual Folder IndexContainer
  589. {
  590. get { return null; }
  591. }
  592. /// <summary>
  593. /// Gets the user data key.
  594. /// </summary>
  595. /// <returns>System.String.</returns>
  596. public virtual string GetUserDataKey()
  597. {
  598. return Id.ToString();
  599. }
  600. /// <summary>
  601. /// Gets the preferred metadata language.
  602. /// </summary>
  603. /// <returns>System.String.</returns>
  604. public string GetPreferredMetadataLanguage()
  605. {
  606. string lang = null;
  607. var hasLang = this as IHasPreferredMetadataLanguage;
  608. if (hasLang != null)
  609. {
  610. lang = hasLang.PreferredMetadataLanguage;
  611. }
  612. if (string.IsNullOrEmpty(lang))
  613. {
  614. lang = Parents.OfType<IHasPreferredMetadataLanguage>()
  615. .Select(i => i.PreferredMetadataLanguage)
  616. .FirstOrDefault(i => !string.IsNullOrEmpty(i));
  617. }
  618. if (string.IsNullOrEmpty(lang))
  619. {
  620. lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
  621. }
  622. return lang;
  623. }
  624. /// <summary>
  625. /// Gets the preferred metadata language.
  626. /// </summary>
  627. /// <returns>System.String.</returns>
  628. public string GetPreferredMetadataCountryCode()
  629. {
  630. string lang = null;
  631. var hasLang = this as IHasPreferredMetadataLanguage;
  632. if (hasLang != null)
  633. {
  634. lang = hasLang.PreferredMetadataCountryCode;
  635. }
  636. if (string.IsNullOrEmpty(lang))
  637. {
  638. lang = Parents.OfType<IHasPreferredMetadataLanguage>()
  639. .Select(i => i.PreferredMetadataCountryCode)
  640. .FirstOrDefault(i => !string.IsNullOrEmpty(i));
  641. }
  642. if (string.IsNullOrEmpty(lang))
  643. {
  644. lang = ConfigurationManager.Configuration.MetadataCountryCode;
  645. }
  646. return lang;
  647. }
  648. public virtual bool IsSaveLocalMetadataEnabled()
  649. {
  650. return ConfigurationManager.Configuration.SaveLocalMeta;
  651. }
  652. /// <summary>
  653. /// Determines if a given user has access to this item
  654. /// </summary>
  655. /// <param name="user">The user.</param>
  656. /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
  657. /// <exception cref="System.ArgumentNullException">user</exception>
  658. public bool IsParentalAllowed(User user)
  659. {
  660. if (user == null)
  661. {
  662. throw new ArgumentNullException("user");
  663. }
  664. var maxAllowedRating = user.Configuration.MaxParentalRating;
  665. if (maxAllowedRating == null)
  666. {
  667. return true;
  668. }
  669. var rating = CustomRatingForComparison;
  670. if (string.IsNullOrEmpty(rating))
  671. {
  672. rating = OfficialRatingForComparison;
  673. }
  674. if (string.IsNullOrEmpty(rating))
  675. {
  676. return !GetBlockUnratedValue(user.Configuration);
  677. }
  678. var value = LocalizationManager.GetRatingLevel(rating);
  679. // Could not determine the integer value
  680. if (!value.HasValue)
  681. {
  682. return true;
  683. }
  684. return value.Value <= maxAllowedRating.Value;
  685. }
  686. /// <summary>
  687. /// Gets the block unrated value.
  688. /// </summary>
  689. /// <param name="config">The configuration.</param>
  690. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  691. protected virtual bool GetBlockUnratedValue(UserConfiguration config)
  692. {
  693. return config.BlockNotRated;
  694. }
  695. /// <summary>
  696. /// Determines if this folder should be visible to a given user.
  697. /// Default is just parental allowed. Can be overridden for more functionality.
  698. /// </summary>
  699. /// <param name="user">The user.</param>
  700. /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
  701. /// <exception cref="System.ArgumentNullException">user</exception>
  702. public virtual bool IsVisible(User user)
  703. {
  704. if (user == null)
  705. {
  706. throw new ArgumentNullException("user");
  707. }
  708. return IsParentalAllowed(user);
  709. }
  710. /// <summary>
  711. /// Finds the particular item by searching through our parents and, if not found there, loading from repo
  712. /// </summary>
  713. /// <param name="id">The id.</param>
  714. /// <returns>BaseItem.</returns>
  715. /// <exception cref="System.ArgumentException"></exception>
  716. protected BaseItem FindParentItem(Guid id)
  717. {
  718. if (id == Guid.Empty)
  719. {
  720. throw new ArgumentException();
  721. }
  722. var parent = Parent;
  723. while (parent != null && !parent.IsRoot)
  724. {
  725. if (parent.Id == id) return parent;
  726. parent = parent.Parent;
  727. }
  728. return null;
  729. }
  730. /// <summary>
  731. /// Gets a value indicating whether this instance is folder.
  732. /// </summary>
  733. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  734. [IgnoreDataMember]
  735. public virtual bool IsFolder
  736. {
  737. get
  738. {
  739. return false;
  740. }
  741. }
  742. /// <summary>
  743. /// Determine if we have changed vs the passed in copy
  744. /// </summary>
  745. /// <param name="copy">The copy.</param>
  746. /// <returns><c>true</c> if the specified copy has changed; otherwise, <c>false</c>.</returns>
  747. /// <exception cref="System.ArgumentNullException"></exception>
  748. public virtual bool HasChanged(BaseItem copy)
  749. {
  750. if (copy == null)
  751. {
  752. throw new ArgumentNullException();
  753. }
  754. if (IsInMixedFolder != copy.IsInMixedFolder)
  755. {
  756. Logger.Debug(Name + " changed due to different value for IsInMixedFolder.");
  757. return true;
  758. }
  759. var changed = copy.DateModified != DateModified;
  760. if (changed)
  761. {
  762. Logger.Debug(Name + " changed - original creation: " + DateCreated + " new creation: " + copy.DateCreated + " original modified: " + DateModified + " new modified: " + copy.DateModified);
  763. }
  764. return changed;
  765. }
  766. public virtual string GetClientTypeName()
  767. {
  768. return GetType().Name;
  769. }
  770. /// <summary>
  771. /// Determines if the item is considered new based on user settings
  772. /// </summary>
  773. /// <returns><c>true</c> if [is recently added] [the specified user]; otherwise, <c>false</c>.</returns>
  774. /// <exception cref="System.ArgumentNullException"></exception>
  775. public bool IsRecentlyAdded()
  776. {
  777. return (DateTime.UtcNow - DateCreated).TotalDays < ConfigurationManager.Configuration.RecentItemDays;
  778. }
  779. /// <summary>
  780. /// Adds a person to the item
  781. /// </summary>
  782. /// <param name="person">The person.</param>
  783. /// <exception cref="System.ArgumentNullException"></exception>
  784. public void AddPerson(PersonInfo person)
  785. {
  786. if (person == null)
  787. {
  788. throw new ArgumentNullException("person");
  789. }
  790. if (string.IsNullOrWhiteSpace(person.Name))
  791. {
  792. throw new ArgumentNullException();
  793. }
  794. // Normalize
  795. if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  796. {
  797. person.Type = PersonType.GuestStar;
  798. }
  799. else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
  800. {
  801. person.Type = PersonType.Director;
  802. }
  803. else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase))
  804. {
  805. person.Type = PersonType.Producer;
  806. }
  807. else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
  808. {
  809. person.Type = PersonType.Writer;
  810. }
  811. // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
  812. if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
  813. {
  814. var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase));
  815. if (existing != null)
  816. {
  817. existing.Type = PersonType.GuestStar;
  818. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  819. return;
  820. }
  821. }
  822. if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
  823. {
  824. // If the actor already exists without a role and we have one, fill it in
  825. 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)));
  826. if (existing == null)
  827. {
  828. // Wasn't there - add it
  829. People.Add(person);
  830. }
  831. else
  832. {
  833. // Was there, if no role and we have one - fill it in
  834. if (string.IsNullOrWhiteSpace(existing.Role) && !string.IsNullOrWhiteSpace(person.Role))
  835. {
  836. existing.Role = person.Role;
  837. }
  838. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  839. }
  840. }
  841. else
  842. {
  843. var existing = People.FirstOrDefault(p =>
  844. string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) &&
  845. string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase));
  846. // Check for dupes based on the combination of Name and Type
  847. if (existing == null)
  848. {
  849. People.Add(person);
  850. }
  851. else
  852. {
  853. existing.SortOrder = person.SortOrder ?? existing.SortOrder;
  854. }
  855. }
  856. }
  857. /// <summary>
  858. /// Adds a studio to the item
  859. /// </summary>
  860. /// <param name="name">The name.</param>
  861. /// <exception cref="System.ArgumentNullException"></exception>
  862. public void AddStudio(string name)
  863. {
  864. if (string.IsNullOrWhiteSpace(name))
  865. {
  866. throw new ArgumentNullException("name");
  867. }
  868. if (!Studios.Contains(name, StringComparer.OrdinalIgnoreCase))
  869. {
  870. Studios.Add(name);
  871. }
  872. }
  873. /// <summary>
  874. /// Adds a genre to the item
  875. /// </summary>
  876. /// <param name="name">The name.</param>
  877. /// <exception cref="System.ArgumentNullException"></exception>
  878. public void AddGenre(string name)
  879. {
  880. if (string.IsNullOrWhiteSpace(name))
  881. {
  882. throw new ArgumentNullException("name");
  883. }
  884. if (!Genres.Contains(name, StringComparer.OrdinalIgnoreCase))
  885. {
  886. Genres.Add(name);
  887. }
  888. }
  889. /// <summary>
  890. /// Marks the played.
  891. /// </summary>
  892. /// <param name="user">The user.</param>
  893. /// <param name="datePlayed">The date played.</param>
  894. /// <param name="userManager">The user manager.</param>
  895. /// <returns>Task.</returns>
  896. /// <exception cref="System.ArgumentNullException"></exception>
  897. public virtual async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataManager userManager)
  898. {
  899. if (user == null)
  900. {
  901. throw new ArgumentNullException();
  902. }
  903. var key = GetUserDataKey();
  904. var data = userManager.GetUserData(user.Id, key);
  905. if (datePlayed.HasValue)
  906. {
  907. // Incremenet
  908. data.PlayCount++;
  909. }
  910. // Ensure it's at least one
  911. data.PlayCount = Math.Max(data.PlayCount, 1);
  912. data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
  913. data.Played = true;
  914. await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  915. }
  916. /// <summary>
  917. /// Marks the unplayed.
  918. /// </summary>
  919. /// <param name="user">The user.</param>
  920. /// <param name="userManager">The user manager.</param>
  921. /// <returns>Task.</returns>
  922. /// <exception cref="System.ArgumentNullException"></exception>
  923. public virtual async Task MarkUnplayed(User user, IUserDataManager userManager)
  924. {
  925. if (user == null)
  926. {
  927. throw new ArgumentNullException();
  928. }
  929. var key = GetUserDataKey();
  930. var data = userManager.GetUserData(user.Id, key);
  931. //I think it is okay to do this here.
  932. // if this is only called when a user is manually forcing something to un-played
  933. // then it probably is what we want to do...
  934. data.PlayCount = 0;
  935. data.PlaybackPositionTicks = 0;
  936. data.LastPlayedDate = null;
  937. data.Played = false;
  938. await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
  939. }
  940. /// <summary>
  941. /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
  942. /// </summary>
  943. /// <returns>Task.</returns>
  944. public virtual Task ChangedExternally()
  945. {
  946. return RefreshMetadata(CancellationToken.None);
  947. }
  948. /// <summary>
  949. /// Finds a parent of a given type
  950. /// </summary>
  951. /// <typeparam name="T"></typeparam>
  952. /// <returns>``0.</returns>
  953. public T FindParent<T>()
  954. where T : Folder
  955. {
  956. var parent = Parent;
  957. while (parent != null)
  958. {
  959. var result = parent as T;
  960. if (result != null)
  961. {
  962. return result;
  963. }
  964. parent = parent.Parent;
  965. }
  966. return null;
  967. }
  968. /// <summary>
  969. /// Gets an image
  970. /// </summary>
  971. /// <param name="type">The type.</param>
  972. /// <param name="imageIndex">Index of the image.</param>
  973. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  974. /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception>
  975. public bool HasImage(ImageType type, int imageIndex)
  976. {
  977. return GetImageInfo(type, imageIndex) != null;
  978. }
  979. public void SetImagePath(ImageType type, int index, FileInfo file)
  980. {
  981. if (type == ImageType.Chapter)
  982. {
  983. throw new ArgumentException("Cannot set chapter images using SetImagePath");
  984. }
  985. var image = GetImageInfo(type, index);
  986. if (image == null)
  987. {
  988. ImageInfos.Add(new ItemImageInfo
  989. {
  990. Path = file.FullName,
  991. Type = type,
  992. DateModified = FileSystem.GetLastWriteTimeUtc(file)
  993. });
  994. }
  995. else
  996. {
  997. image.Path = file.FullName;
  998. image.DateModified = FileSystem.GetLastWriteTimeUtc(file);
  999. }
  1000. }
  1001. /// <summary>
  1002. /// Deletes the image.
  1003. /// </summary>
  1004. /// <param name="type">The type.</param>
  1005. /// <param name="index">The index.</param>
  1006. /// <returns>Task.</returns>
  1007. public Task DeleteImage(ImageType type, int index)
  1008. {
  1009. var info = GetImageInfo(type, index);
  1010. if (info == null)
  1011. {
  1012. // Nothing to do
  1013. return Task.FromResult(true);
  1014. }
  1015. // Remove it from the item
  1016. ImageInfos.Remove(info);
  1017. // Delete the source file
  1018. var currentFile = new FileInfo(info.Path);
  1019. // Deletion will fail if the file is hidden so remove the attribute first
  1020. if (currentFile.Exists)
  1021. {
  1022. if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  1023. {
  1024. currentFile.Attributes &= ~FileAttributes.Hidden;
  1025. }
  1026. currentFile.Delete();
  1027. }
  1028. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1029. }
  1030. public virtual Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  1031. {
  1032. return LibraryManager.UpdateItem(this, ItemUpdateType.ImageUpdate, cancellationToken);
  1033. }
  1034. /// <summary>
  1035. /// Validates that images within the item are still on the file system
  1036. /// </summary>
  1037. public bool ValidateImages()
  1038. {
  1039. var deletedImages = ImageInfos
  1040. .Where(image => !File.Exists(image.Path))
  1041. .ToList();
  1042. if (deletedImages.Count > 0)
  1043. {
  1044. ImageInfos = ImageInfos.Except(deletedImages).ToList();
  1045. }
  1046. return deletedImages.Count > 0;
  1047. }
  1048. /// <summary>
  1049. /// Gets the image path.
  1050. /// </summary>
  1051. /// <param name="imageType">Type of the image.</param>
  1052. /// <param name="imageIndex">Index of the image.</param>
  1053. /// <returns>System.String.</returns>
  1054. /// <exception cref="System.InvalidOperationException">
  1055. /// </exception>
  1056. /// <exception cref="System.ArgumentNullException">item</exception>
  1057. public string GetImagePath(ImageType imageType, int imageIndex)
  1058. {
  1059. var info = GetImageInfo(imageType, imageIndex);
  1060. return info == null ? null : info.Path;
  1061. }
  1062. /// <summary>
  1063. /// Gets the image information.
  1064. /// </summary>
  1065. /// <param name="imageType">Type of the image.</param>
  1066. /// <param name="imageIndex">Index of the image.</param>
  1067. /// <returns>ItemImageInfo.</returns>
  1068. public ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex)
  1069. {
  1070. if (imageType == ImageType.Chapter)
  1071. {
  1072. var chapter = ItemRepository.GetChapter(Id, imageIndex);
  1073. if (chapter == null)
  1074. {
  1075. return null;
  1076. }
  1077. var path = chapter.ImagePath;
  1078. if (string.IsNullOrWhiteSpace(path))
  1079. {
  1080. return null;
  1081. }
  1082. return new ItemImageInfo
  1083. {
  1084. Path = path,
  1085. DateModified = FileSystem.GetLastWriteTimeUtc(path),
  1086. Type = imageType
  1087. };
  1088. }
  1089. return GetImages(imageType)
  1090. .ElementAtOrDefault(imageIndex);
  1091. }
  1092. public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
  1093. {
  1094. if (imageType == ImageType.Chapter)
  1095. {
  1096. throw new ArgumentException("No image info for chapter images");
  1097. }
  1098. return ImageInfos.Where(i => i.Type == imageType);
  1099. }
  1100. /// <summary>
  1101. /// Adds the images.
  1102. /// </summary>
  1103. /// <param name="imageType">Type of the image.</param>
  1104. /// <param name="images">The images.</param>
  1105. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  1106. /// <exception cref="System.ArgumentException">Cannot call AddImages with chapter images</exception>
  1107. public bool AddImages(ImageType imageType, IEnumerable<FileInfo> images)
  1108. {
  1109. if (imageType == ImageType.Chapter)
  1110. {
  1111. throw new ArgumentException("Cannot call AddImages with chapter images");
  1112. }
  1113. var existingImagePaths = GetImages(imageType)
  1114. .Select(i => i.Path)
  1115. .ToList();
  1116. var newImages = images
  1117. .Where(i => !existingImagePaths.Contains(i.FullName, StringComparer.OrdinalIgnoreCase))
  1118. .ToList();
  1119. ImageInfos.AddRange(newImages.Select(i => new ItemImageInfo
  1120. {
  1121. Path = i.FullName,
  1122. Type = imageType,
  1123. DateModified = FileSystem.GetLastWriteTimeUtc(i)
  1124. }));
  1125. return newImages.Count > 0;
  1126. }
  1127. /// <summary>
  1128. /// Gets the file system path to delete when the item is to be deleted
  1129. /// </summary>
  1130. /// <returns></returns>
  1131. public virtual IEnumerable<string> GetDeletePaths()
  1132. {
  1133. return new[] { Path };
  1134. }
  1135. public bool AllowsMultipleImages(ImageType type)
  1136. {
  1137. return type == ImageType.Backdrop || type == ImageType.Screenshot || type == ImageType.Chapter;
  1138. }
  1139. public Task SwapImages(ImageType type, int index1, int index2)
  1140. {
  1141. if (!AllowsMultipleImages(type))
  1142. {
  1143. throw new ArgumentException("The change index operation is only applicable to backdrops and screenshots");
  1144. }
  1145. var info1 = GetImageInfo(type, index1);
  1146. var info2 = GetImageInfo(type, index2);
  1147. if (info1 == null || info2 == null)
  1148. {
  1149. // Nothing to do
  1150. return Task.FromResult(true);
  1151. }
  1152. var path1 = info1.Path;
  1153. var path2 = info2.Path;
  1154. FileSystem.SwapFiles(path1, path2);
  1155. info1.Path = path2;
  1156. info2.Path = path1;
  1157. info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
  1158. info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
  1159. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1160. }
  1161. public virtual bool IsPlayed(User user)
  1162. {
  1163. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1164. return userdata != null && userdata.Played;
  1165. }
  1166. public virtual bool IsUnplayed(User user)
  1167. {
  1168. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1169. return userdata == null || !userdata.Played;
  1170. }
  1171. ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
  1172. {
  1173. return GetItemLookupInfo<ItemLookupInfo>();
  1174. }
  1175. protected T GetItemLookupInfo<T>()
  1176. where T : ItemLookupInfo, new()
  1177. {
  1178. return new T
  1179. {
  1180. MetadataCountryCode = GetPreferredMetadataCountryCode(),
  1181. MetadataLanguage = GetPreferredMetadataLanguage(),
  1182. Name = Name,
  1183. ProviderIds = ProviderIds,
  1184. IndexNumber = IndexNumber,
  1185. ParentIndexNumber = ParentIndexNumber
  1186. };
  1187. }
  1188. }
  1189. }