ItemMetadata.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if (string.IsNullOrEmpty(title))
  21. {
  22. throw new ArgumentNullException(nameof(title));
  23. }
  24. if (string.IsNullOrEmpty(language))
  25. {
  26. throw new ArgumentNullException(nameof(language));
  27. }
  28. Title = title;
  29. Language = language;
  30. DateAdded = DateTime.UtcNow;
  31. DateModified = DateAdded;
  32. PersonRoles = new HashSet<PersonRole>();
  33. Genres = new HashSet<Genre>();
  34. Artwork = new HashSet<Artwork>();
  35. Ratings = new HashSet<Rating>();
  36. Sources = new HashSet<MetadataProviderId>();
  37. }
  38. /// <summary>
  39. /// Gets the id.
  40. /// </summary>
  41. /// <remarks>
  42. /// Identity, Indexed, Required.
  43. /// </remarks>
  44. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  45. public int Id { get; private set; }
  46. /// <summary>
  47. /// Gets or sets the title.
  48. /// </summary>
  49. /// <remarks>
  50. /// Required, Max length = 1024.
  51. /// </remarks>
  52. [MaxLength(1024)]
  53. [StringLength(1024)]
  54. public string Title { get; set; }
  55. /// <summary>
  56. /// Gets or sets the original title.
  57. /// </summary>
  58. /// <remarks>
  59. /// Max length = 1024.
  60. /// </remarks>
  61. [MaxLength(1024)]
  62. [StringLength(1024)]
  63. public string? OriginalTitle { get; set; }
  64. /// <summary>
  65. /// Gets or sets the sort title.
  66. /// </summary>
  67. /// <remarks>
  68. /// Max length = 1024.
  69. /// </remarks>
  70. [MaxLength(1024)]
  71. [StringLength(1024)]
  72. public string? SortTitle { get; set; }
  73. /// <summary>
  74. /// Gets or sets the language.
  75. /// </summary>
  76. /// <remarks>
  77. /// Required, Min length = 3, Max length = 3.
  78. /// ISO-639-3 3-character language codes.
  79. /// </remarks>
  80. [MinLength(3)]
  81. [MaxLength(3)]
  82. [StringLength(3)]
  83. public string Language { get; set; }
  84. /// <summary>
  85. /// Gets or sets the release date.
  86. /// </summary>
  87. public DateTimeOffset? ReleaseDate { get; set; }
  88. /// <summary>
  89. /// Gets the date added.
  90. /// </summary>
  91. /// <remarks>
  92. /// Required.
  93. /// </remarks>
  94. public DateTime DateAdded { get; private set; }
  95. /// <summary>
  96. /// Gets or sets the date modified.
  97. /// </summary>
  98. /// <remarks>
  99. /// Required.
  100. /// </remarks>
  101. public DateTime DateModified { get; set; }
  102. /// <inheritdoc />
  103. [ConcurrencyCheck]
  104. public uint RowVersion { get; private set; }
  105. /// <summary>
  106. /// Gets a collection containing the person roles for this item.
  107. /// </summary>
  108. public virtual ICollection<PersonRole> PersonRoles { get; private set; }
  109. /// <summary>
  110. /// Gets a collection containing the genres for this item.
  111. /// </summary>
  112. public virtual ICollection<Genre> Genres { get; private set; }
  113. /// <inheritdoc />
  114. public virtual ICollection<Artwork> Artwork { get; private set; }
  115. /// <summary>
  116. /// Gets a collection containing the ratings for this item.
  117. /// </summary>
  118. public virtual ICollection<Rating> Ratings { get; private set; }
  119. /// <summary>
  120. /// Gets a collection containing the metadata sources for this item.
  121. /// </summary>
  122. public virtual ICollection<MetadataProviderId> Sources { get; private set; }
  123. /// <inheritdoc />
  124. public void OnSavingChanges()
  125. {
  126. RowVersion++;
  127. }
  128. }
  129. }