BaseItem.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  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. // Refresh these values
  1139. info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
  1140. info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
  1141. return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
  1142. }
  1143. public virtual bool IsPlayed(User user)
  1144. {
  1145. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1146. return userdata != null && userdata.Played;
  1147. }
  1148. public virtual bool IsUnplayed(User user)
  1149. {
  1150. var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
  1151. return userdata == null || !userdata.Played;
  1152. }
  1153. ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
  1154. {
  1155. return GetItemLookupInfo<ItemLookupInfo>();
  1156. }
  1157. protected T GetItemLookupInfo<T>()
  1158. where T : ItemLookupInfo, new()
  1159. {
  1160. return new T
  1161. {
  1162. MetadataCountryCode = GetPreferredMetadataCountryCode(),
  1163. MetadataLanguage = GetPreferredMetadataLanguage(),
  1164. Name = Name,
  1165. ProviderIds = ProviderIds,
  1166. IndexNumber = IndexNumber,
  1167. ParentIndexNumber = ParentIndexNumber
  1168. };
  1169. }
  1170. }
  1171. }