ItemMetadata.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using Jellyfin.Data.Interfaces;
  6. namespace Jellyfin.Data.Entities.Libraries
  7. {
  8. /// <summary>
  9. /// An abstract class that holds metadata.
  10. /// </summary>
  11. public abstract class ItemMetadata : IHasArtwork, IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="ItemMetadata"/> class.
  15. /// </summary>
  16. /// <param name="title">The title or name of the object.</param>
  17. /// <param name="language">ISO-639-3 3-character language codes.</param>
  18. protected ItemMetadata(string title, string language)
  19. {
  20. ArgumentException.ThrowIfNullOrEmpty(title);
  21. ArgumentException.ThrowIfNullOrEmpty(language);
  22. Title = title;
  23. Language = language;
  24. DateAdded = DateTime.UtcNow;
  25. DateModified = DateAdded;
  26. PersonRoles = new HashSet<PersonRole>();
  27. Genres = new HashSet<Genre>();
  28. Artwork = new HashSet<Artwork>();
  29. Ratings = new HashSet<Rating>();
  30. Sources = new HashSet<MetadataProviderId>();
  31. }
  32. /// <summary>
  33. /// Gets the id.
  34. /// </summary>
  35. /// <remarks>
  36. /// Identity, Indexed, Required.
  37. /// </remarks>
  38. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  39. public int Id { get; private set; }
  40. /// <summary>
  41. /// Gets or sets the title.
  42. /// </summary>
  43. /// <remarks>
  44. /// Required, Max length = 1024.
  45. /// </remarks>
  46. [MaxLength(1024)]
  47. [StringLength(1024)]
  48. public string Title { get; set; }
  49. /// <summary>
  50. /// Gets or sets the original title.
  51. /// </summary>
  52. /// <remarks>
  53. /// Max length = 1024.
  54. /// </remarks>
  55. [MaxLength(1024)]
  56. [StringLength(1024)]
  57. public string? OriginalTitle { get; set; }
  58. /// <summary>
  59. /// Gets or sets the sort title.
  60. /// </summary>
  61. /// <remarks>
  62. /// Max length = 1024.
  63. /// </remarks>
  64. [MaxLength(1024)]
  65. [StringLength(1024)]
  66. public string? SortTitle { get; set; }
  67. /// <summary>
  68. /// Gets or sets the language.
  69. /// </summary>
  70. /// <remarks>
  71. /// Required, Min length = 3, Max length = 3.
  72. /// ISO-639-3 3-character language codes.
  73. /// </remarks>
  74. [MinLength(3)]
  75. [MaxLength(3)]
  76. [StringLength(3)]
  77. public string Language { get; set; }
  78. /// <summary>
  79. /// Gets or sets the release date.
  80. /// </summary>
  81. public DateTimeOffset? ReleaseDate { get; set; }
  82. /// <summary>
  83. /// Gets the date added.
  84. /// </summary>
  85. /// <remarks>
  86. /// Required.
  87. /// </remarks>
  88. public DateTime DateAdded { get; private set; }
  89. /// <summary>
  90. /// Gets or sets the date modified.
  91. /// </summary>
  92. /// <remarks>
  93. /// Required.
  94. /// </remarks>
  95. public DateTime DateModified { get; set; }
  96. /// <inheritdoc />
  97. [ConcurrencyCheck]
  98. public uint RowVersion { get; private set; }
  99. /// <summary>
  100. /// Gets a collection containing the person roles for this item.
  101. /// </summary>
  102. public virtual ICollection<PersonRole> PersonRoles { get; private set; }
  103. /// <summary>
  104. /// Gets a collection containing the genres for this item.
  105. /// </summary>
  106. public virtual ICollection<Genre> Genres { get; private set; }
  107. /// <inheritdoc />
  108. public virtual ICollection<Artwork> Artwork { get; private set; }
  109. /// <summary>
  110. /// Gets a collection containing the ratings for this item.
  111. /// </summary>
  112. public virtual ICollection<Rating> Ratings { get; private set; }
  113. /// <summary>
  114. /// Gets a collection containing the metadata sources for this item.
  115. /// </summary>
  116. public virtual ICollection<MetadataProviderId> Sources { get; private set; }
  117. /// <inheritdoc />
  118. public void OnSavingChanges()
  119. {
  120. RowVersion++;
  121. }
  122. }
  123. }