< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.BaseItem
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/BaseItem.cs
Line coverage
55%
Covered lines: 519
Uncovered lines: 424
Coverable lines: 943
Total lines: 2970
Line coverage: 55%
Branch coverage
42%
Covered branches: 258
Total branches: 614
Branch coverage: 42%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 4/16/2026 - 12:15:18 AM Line coverage: 51% (374/732) Branch coverage: 39.8% (185/464) Total lines: 26944/19/2026 - 12:14:27 AM Line coverage: 47.2% (404/855) Branch coverage: 38.6% (207/536) Total lines: 26945/4/2026 - 12:15:16 AM Line coverage: 45.4% (403/887) Branch coverage: 36.5% (202/552) Total lines: 27705/8/2026 - 12:15:13 AM Line coverage: 45.5% (404/887) Branch coverage: 36.5% (202/552) Total lines: 27735/20/2026 - 12:15:44 AM Line coverage: 45.5% (404/887) Branch coverage: 32.4% (179/552) Total lines: 27735/27/2026 - 12:15:38 AM Line coverage: 45.6% (406/890) Branch coverage: 32.6% (182/558) Total lines: 27886/2/2026 - 12:15:49 AM Line coverage: 45.9% (408/888) Branch coverage: 33.2% (183/550) Total lines: 27796/6/2026 - 12:15:50 AM Line coverage: 45.9% (408/888) Branch coverage: 33.2% (183/550) Total lines: 27817/6/2026 - 12:16:28 AM Line coverage: 54.4% (505/927) Branch coverage: 41% (244/594) Total lines: 29137/26/2026 - 12:17:51 AM Line coverage: 55% (519/943) Branch coverage: 42% (258/614) Total lines: 2970 4/16/2026 - 12:15:18 AM Line coverage: 51% (374/732) Branch coverage: 39.8% (185/464) Total lines: 26944/19/2026 - 12:14:27 AM Line coverage: 47.2% (404/855) Branch coverage: 38.6% (207/536) Total lines: 26945/4/2026 - 12:15:16 AM Line coverage: 45.4% (403/887) Branch coverage: 36.5% (202/552) Total lines: 27705/8/2026 - 12:15:13 AM Line coverage: 45.5% (404/887) Branch coverage: 36.5% (202/552) Total lines: 27735/20/2026 - 12:15:44 AM Line coverage: 45.5% (404/887) Branch coverage: 32.4% (179/552) Total lines: 27735/27/2026 - 12:15:38 AM Line coverage: 45.6% (406/890) Branch coverage: 32.6% (182/558) Total lines: 27886/2/2026 - 12:15:49 AM Line coverage: 45.9% (408/888) Branch coverage: 33.2% (183/550) Total lines: 27796/6/2026 - 12:15:50 AM Line coverage: 45.9% (408/888) Branch coverage: 33.2% (183/550) Total lines: 27817/6/2026 - 12:16:28 AM Line coverage: 54.4% (505/927) Branch coverage: 41% (244/594) Total lines: 29137/26/2026 - 12:17:51 AM Line coverage: 55% (519/943) Branch coverage: 42% (258/614) Total lines: 2970

Coverage delta

Coverage delta 9 -9

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%11100%
get_SupportsAddingToPlaylist()100%210%
get_AlwaysScanInternalMetadataPath()100%11100%
get_SupportsPlayedStatus()100%210%
get_SupportsPositionTicksResume()100%210%
get_SupportsRemoteImageDownloading()100%11100%
get_Name()100%11100%
set_Name(...)100%11100%
get_IsUnaired()0%620%
get_IsThemeMedia()0%2040%
get_OriginalLanguage()100%11100%
set_OriginalLanguage(...)50%66100%
get_DisplayPreferencesId()50%22100%
get_SourceType()50%2266.66%
get_ContainingFolderPath()100%22100%
get_IsHidden()100%210%
get_LocationType()33.33%7666.66%
get_PathProtocol()100%22100%
get_IsFileProtocol()100%11100%
get_HasPathProtocol()100%210%
get_SupportsLocalMetadata()50%2266.66%
get_FileNameWithoutExtension()0%620%
get_EnableAlphaNumericSorting()100%11100%
get_IsHD()100%11100%
get_PrimaryImagePath()100%210%
get_MediaType()100%11100%
get_PhysicalLocations()0%620%
get_EnableMediaSourceDisplay()50%2266.66%
get_ForcedSortName()100%11100%
set_ForcedSortName(...)100%11100%
get_SortName()100%44100%
set_SortName(...)100%11100%
get_DisplayParentId()100%11100%
get_DisplayParent()100%22100%
get_HasLocalAlternateVersions()100%210%
get_OfficialRatingForComparison()75%4485.71%
get_CustomRatingForComparison()100%11100%
get_LatestItemsIndexContainer()100%210%
get_EnableRememberingTrackSelections()100%11100%
get_IsTopParent()80%121075%
get_SupportsAncestors()100%11100%
get_SupportsOwnedItems()100%22100%
get_SupportsPeople()100%11100%
get_SupportsThemeMedia()100%210%
get_SupportsInheritedParentImages()100%210%
get_IsFolder()100%11100%
get_IsDisplayedAsFolder()100%210%
GetCustomRatingForComparision(...)87.5%8888.88%
GetDefaultPrimaryImageAspectRatio()100%210%
CreatePresentationUniqueKey()100%11100%
CanDelete()0%620%
IsAuthorizedToDelete(...)0%7280%
GetOwner()50%22100%
CanDelete(...)50%22100%
CanDelete(...)100%11100%
CanDownload()100%11100%
IsAuthorizedToDownload(...)100%210%
CanDownload(...)50%22100%
ToString()100%11100%
GetInternalMetadataPath()100%11100%
GetInternalMetadataPath(...)50%2275%
CreateSortName()100%11100%
GetSortName(...)85.71%141487.5%
ModifySortChunks(...)87.5%8893.75%
GetParent()100%22100%
GetParents()100%22100%
FindParent()0%2040%
GetPlayAccess(...)50%2266.66%
GetMediaStreams()100%210%
IsActiveRecording()100%210%
GetMediaSources(...)37.5%10866.66%
GetAllItemsForMediaSources()100%210%
GetVersionInfo(...)36.95%594681.63%
GetMediaSourceName(...)57.14%834271.42%
GetCommonNamePrefix(...)80%101087.5%
GetCommonVersionPrefix(...)95.83%2424100%
RefreshMetadata(...)100%11100%
RefreshMetadata()62.5%8882.35%
IsVisibleStandaloneInternal(...)0%342180%
SetParent(...)50%22100%
RefreshedOwnedItems()62.5%201675%
GetFileSystemChildren(...)100%11100%
RefreshExtras()0%342180%
GetPresentationUniqueKey()0%620%
RequiresRefresh()33.33%11650%
GetUserDataKeys()25%5466.66%
UpdateFromResolvedItem(...)50%2260%
AfterMetadataRefresh()100%11100%
GetPreferredMetadataLanguage()50%88100%
GetPreferredMetadataCountryCode()50%88100%
GetInheritedOriginalLanguage()100%210%
IsSaveLocalMetadataEnabled()50%2275%
IsParentalAllowed(...)18.75%641642.85%
GetParentalRatingScore()50%4483.33%
GetInheritedTags()75%4485.71%
IsVisibleViaTags(...)9.09%3022216.66%
GetBlockUnratedType()50%2266.66%
GetBlockUnratedValue(...)50%5466.66%
IsVisible(...)100%11100%
IsVisibleStandalone(...)0%2040%
GetClientTypeName()70%141066.66%
GetBaseItemKind()100%22100%
GetLinkedChild(...)0%7280%
FindLinkedChild(...)0%210140%
AddStudio(...)50%4475%
SetStudios(...)100%11100%
AddGenre(...)50%22100%
MarkPlayed(...)0%110100%
MarkUnplayed(...)100%210%
ResetPlayedState(...)100%11100%
ChangedExternally()100%210%
HasImage(...)100%11100%
SetImage(...)75%4490.9%
SetImagePath(...)75%4490.9%
DeleteImageAsync()0%4260%
RemoveImage(...)100%210%
RemoveImages(...)100%11100%
AddImage(...)100%11100%
UpdateToRepositoryAsync()100%11100%
ReattachUserDataAsync()100%11100%
ValidateImages()91.66%1212100%
GetImagePath(...)50%22100%
GetImageInfo(...)16.66%24620%
GetImageIndex(...)0%110100%
GetImages()83.33%6685.71%
AddImages(...)85%202091.3%
GetImageInfo(...)100%11100%
GetDeletePaths()100%210%
GetLocalMetadataFilesToDelete()0%2040%
AllowsMultipleImages(...)100%22100%
SwapImagesAsync(...)0%110100%
IsPlayed(...)0%2040%
IsFavoriteOrLiked(...)0%4260%
IsUnplayed(...)0%2040%
MediaBrowser.Controller.Providers.IHasLookupInfo<MediaBrowser.Controller.Providers.ItemLookupInfo>.GetLookupInfo()100%11100%
GetItemLookupInfo()100%11100%
GetNameForMetadataLookup()100%11100%
BeforeMetadataRefresh(...)25%5466.66%
GetMappedPath(...)0%620%
FillUserDataDtoValues(...)0%4260%
InheritDatesFromOwner(...)91.66%1212100%
RefreshMetadataForOwnedItem()0%420200%
RefreshMetadataForOwnedVideo()0%4260%
GetEtag(...)100%11100%
GetEtagValues(...)100%11100%
GetAncestorIds()100%11100%
GetTopParent()100%22100%
GetIdsForAncestorQuery()100%11100%
GetRefreshProgress()100%210%
OnMetadataChanged()25%22840%
UpdateRatingToItems(...)0%4260%
GetThemeSongs(...)100%210%
GetThemeSongs(...)100%210%
GetThemeVideos(...)100%210%
GetThemeVideos(...)100%210%
GetExtraOwnerIds()100%11100%
GetExtras(...)100%11100%
GetExtras(...)100%210%
GetRunTimeTicksForPlayState()100%210%
Equals(...)50%22100%
Equals(...)50%22100%
GetHashCode()100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/BaseItem.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591, SA1401
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Collections.Immutable;
 8using System.Globalization;
 9using System.IO;
 10using System.Linq;
 11using System.Text;
 12using System.Text.Json.Serialization;
 13using System.Threading;
 14using System.Threading.Tasks;
 15using Jellyfin.Data;
 16using Jellyfin.Data.Enums;
 17using Jellyfin.Database.Implementations.Entities;
 18using Jellyfin.Database.Implementations.Enums;
 19using Jellyfin.Extensions;
 20using MediaBrowser.Common.Extensions;
 21using MediaBrowser.Controller.Channels;
 22using MediaBrowser.Controller.Chapters;
 23using MediaBrowser.Controller.Configuration;
 24using MediaBrowser.Controller.Dto;
 25using MediaBrowser.Controller.Entities.TV;
 26using MediaBrowser.Controller.Library;
 27using MediaBrowser.Controller.MediaSegments;
 28using MediaBrowser.Controller.Persistence;
 29using MediaBrowser.Controller.Providers;
 30using MediaBrowser.Model.Configuration;
 31using MediaBrowser.Model.Dto;
 32using MediaBrowser.Model.Entities;
 33using MediaBrowser.Model.Globalization;
 34using MediaBrowser.Model.IO;
 35using MediaBrowser.Model.Library;
 36using MediaBrowser.Model.LiveTv;
 37using MediaBrowser.Model.MediaInfo;
 38using Microsoft.Extensions.Logging;
 39
 40namespace MediaBrowser.Controller.Entities
 41{
 42    /// <summary>
 43    /// Class BaseItem.
 44    /// </summary>
 45    public abstract class BaseItem : IHasProviderIds, IHasLookupInfo<ItemLookupInfo>, IEquatable<BaseItem>
 46    {
 47        private BaseItemKind? _baseItemKind;
 48
 49        public const string ThemeSongFileName = "theme";
 50
 51        /// <summary>
 52        /// The supported image extensions.
 53        /// </summary>
 554        public static readonly string[] SupportedImageExtensions
 555            = [".png", ".jpg", ".jpeg", ".webp", ".tbn", ".gif", ".svg"];
 56
 557        private static readonly List<string> _supportedExtensions = new List<string>(SupportedImageExtensions)
 558        {
 559            ".nfo",
 560            ".xml",
 561            ".srt",
 562            ".vtt",
 563            ".sub",
 564            ".sup",
 565            ".idx",
 566            ".txt",
 567            ".edl",
 568            ".bif",
 569            ".smi",
 570            ".ttml",
 571            ".lrc",
 572            ".elrc"
 573        };
 74
 75        /// <summary>
 76        /// Extra types that should be counted and displayed as "Special Features" in the UI.
 77        /// </summary>
 578        public static readonly IReadOnlyCollection<ExtraType> DisplayExtraTypes = new HashSet<ExtraType>
 579        {
 580            Model.Entities.ExtraType.Unknown,
 581            Model.Entities.ExtraType.BehindTheScenes,
 582            Model.Entities.ExtraType.Clip,
 583            Model.Entities.ExtraType.DeletedScene,
 584            Model.Entities.ExtraType.Interview,
 585            Model.Entities.ExtraType.Sample,
 586            Model.Entities.ExtraType.Scene,
 587            Model.Entities.ExtraType.Featurette,
 588            Model.Entities.ExtraType.Short
 589        };
 90
 591        private static readonly char[] VersionDelimiters = ['-', '_', '.'];
 92
 93        private string _sortName;
 94
 95        private string _forcedSortName;
 96
 97        private string _name;
 98
 99        private string _originalLanguage;
 100
 101        public const char SlugChar = '-';
 102
 103        protected BaseItem()
 104        {
 1243105            Tags = Array.Empty<string>();
 1243106            Genres = Array.Empty<string>();
 1243107            Studios = Array.Empty<string>();
 1243108            ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 1243109            LockedFields = Array.Empty<MetadataField>();
 1243110            ImageInfos = Array.Empty<ItemImageInfo>();
 1243111            ProductionLocations = Array.Empty<string>();
 1243112            RemoteTrailers = Array.Empty<MediaUrl>();
 1243113            UserData = [];
 1243114        }
 115
 116        /// <summary>
 117        /// Gets or Sets the user data collection as cached from the last Db query.
 118        /// </summary>
 119        [JsonIgnore]
 120        public ICollection<UserData> UserData { get; set; }
 121
 122        [JsonIgnore]
 123        public string PreferredMetadataCountryCode { get; set; }
 124
 125        [JsonIgnore]
 126        public string PreferredMetadataLanguage { get; set; }
 127
 128        public long? Size { get; set; }
 129
 130        public string Container { get; set; }
 131
 132        [JsonIgnore]
 133        public string Tagline { get; set; }
 134
 135        [JsonIgnore]
 136        public virtual ItemImageInfo[] ImageInfos { get; set; }
 137
 138        [JsonIgnore]
 139        public bool IsVirtualItem { get; set; }
 140
 141        /// <summary>
 142        /// Gets or sets the album.
 143        /// </summary>
 144        /// <value>The album.</value>
 145        [JsonIgnore]
 146        public string Album { get; set; }
 147
 148        /// <summary>
 149        /// Gets or sets the LUFS value.
 150        /// </summary>
 151        /// <value>The LUFS Value.</value>
 152        [JsonIgnore]
 153        public float? LUFS { get; set; }
 154
 155        /// <summary>
 156        /// Gets or sets the gain required for audio normalization.
 157        /// </summary>
 158        /// <value>The gain required for audio normalization.</value>
 159        [JsonIgnore]
 160        public float? NormalizationGain { get; set; }
 161
 162        /// <summary>
 163        /// Gets or sets the channel identifier.
 164        /// </summary>
 165        /// <value>The channel identifier.</value>
 166        [JsonIgnore]
 167        public Guid ChannelId { get; set; }
 168
 169        [JsonIgnore]
 0170        public virtual bool SupportsAddingToPlaylist => false;
 171
 172        [JsonIgnore]
 17173        public virtual bool AlwaysScanInternalMetadataPath => false;
 174
 175        /// <summary>
 176        /// Gets or sets a value indicating whether this instance is in mixed folder.
 177        /// </summary>
 178        /// <value><c>true</c> if this instance is in mixed folder; otherwise, <c>false</c>.</value>
 179        [JsonIgnore]
 180        public bool IsInMixedFolder { get; set; }
 181
 182        [JsonIgnore]
 0183        public virtual bool SupportsPlayedStatus => false;
 184
 185        [JsonIgnore]
 0186        public virtual bool SupportsPositionTicksResume => false;
 187
 188        [JsonIgnore]
 17189        public virtual bool SupportsRemoteImageDownloading => true;
 190
 191        /// <summary>
 192        /// Gets or sets the name.
 193        /// </summary>
 194        /// <value>The name.</value>
 195        [JsonIgnore]
 196        public virtual string Name
 197        {
 956198            get => _name;
 199            set
 200            {
 441201                _name = value;
 202
 203                // lazy load this again
 441204                _sortName = null;
 441205            }
 206        }
 207
 208        [JsonIgnore]
 0209        public bool IsUnaired => PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date;
 210
 211        [JsonIgnore]
 212        public int? TotalBitrate { get; set; }
 213
 214        [JsonIgnore]
 215        public ExtraType? ExtraType { get; set; }
 216
 217        [JsonIgnore]
 0218        public bool IsThemeMedia => ExtraType.HasValue && (ExtraType.Value == Model.Entities.ExtraType.ThemeSong || Extr
 219
 220        [JsonIgnore]
 221        public string OriginalTitle { get; set; }
 222
 223        [JsonIgnore]
 224        public string OriginalLanguage
 225        {
 423226            get => _originalLanguage;
 234227            set => _originalLanguage = LocalizationManager?.FindLanguageInfo(value)?.TwoLetterISOLanguageName ?? value;
 228        }
 229
 230        /// <summary>
 231        /// Gets or sets the id.
 232        /// </summary>
 233        /// <value>The id.</value>
 234        [JsonIgnore]
 235        public Guid Id { get; set; }
 236
 237        [JsonIgnore]
 238        public Guid OwnerId { get; set; }
 239
 240        /// <summary>
 241        /// Gets or sets the audio.
 242        /// </summary>
 243        /// <value>The audio.</value>
 244        [JsonIgnore]
 245        public ProgramAudio? Audio { get; set; }
 246
 247        /// <summary>
 248        /// Gets the id that should be used to key display prefs for this item.
 249        /// Default is based on the type for everything except actual generic folders.
 250        /// </summary>
 251        /// <value>The display prefs id.</value>
 252        [JsonIgnore]
 253        public virtual Guid DisplayPreferencesId
 254        {
 255            get
 256            {
 6257                var thisType = GetType();
 6258                return thisType == typeof(Folder) ? Id : thisType.FullName.GetMD5();
 259            }
 260        }
 261
 262        /// <summary>
 263        /// Gets or sets the path.
 264        /// </summary>
 265        /// <value>The path.</value>
 266        [JsonIgnore]
 267        public virtual string Path { get; set; }
 268
 269        [JsonIgnore]
 270        public virtual SourceType SourceType
 271        {
 272            get
 273            {
 2394274                if (!ChannelId.IsEmpty())
 275                {
 0276                    return SourceType.Channel;
 277                }
 278
 2394279                return SourceType.Library;
 280            }
 281        }
 282
 283        /// <summary>
 284        /// Gets the folder containing the item.
 285        /// If the item is a folder, it returns the folder itself.
 286        /// </summary>
 287        [JsonIgnore]
 288        public virtual string ContainingFolderPath
 289        {
 290            get
 291            {
 482292                if (IsFolder)
 293                {
 417294                    return Path;
 295                }
 296
 65297                return System.IO.Path.GetDirectoryName(Path);
 298            }
 299        }
 300
 301        /// <summary>
 302        /// Gets or sets the name of the service.
 303        /// </summary>
 304        /// <value>The name of the service.</value>
 305        [JsonIgnore]
 306        public string ServiceName { get; set; }
 307
 308        /// <summary>
 309        /// Gets or sets the external id.
 310        /// </summary>
 311        /// <remarks>
 312        /// If this content came from an external service, the id of the content on that service.
 313        /// </remarks>
 314        [JsonIgnore]
 315        public string ExternalId { get; set; }
 316
 317        [JsonIgnore]
 318        public string ExternalSeriesId { get; set; }
 319
 320        [JsonIgnore]
 0321        public virtual bool IsHidden => false;
 322
 323        /// <summary>
 324        /// Gets the type of the location.
 325        /// </summary>
 326        /// <value>The type of the location.</value>
 327        [JsonIgnore]
 328        public virtual LocationType LocationType
 329        {
 330            get
 331            {
 16332                var path = Path;
 16333                if (string.IsNullOrEmpty(path))
 334                {
 7335                    if (SourceType == SourceType.Channel)
 336                    {
 0337                        return LocationType.Remote;
 338                    }
 339
 7340                    return LocationType.Virtual;
 341                }
 342
 9343                return FileSystem.IsPathFile(path) ? LocationType.FileSystem : LocationType.Remote;
 344            }
 345        }
 346
 347        [JsonIgnore]
 348        public MediaProtocol? PathProtocol
 349        {
 350            get
 351            {
 2658352                var path = Path;
 353
 2658354                if (string.IsNullOrEmpty(path))
 355                {
 116356                    return null;
 357                }
 358
 2542359                return MediaSourceManager.GetPathProtocol(path);
 360            }
 361        }
 362
 363        [JsonIgnore]
 2619364        public bool IsFileProtocol => PathProtocol == MediaProtocol.File;
 365
 366        [JsonIgnore]
 0367        public bool HasPathProtocol => PathProtocol.HasValue;
 368
 369        [JsonIgnore]
 370        public virtual bool SupportsLocalMetadata
 371        {
 372            get
 373            {
 1364374                if (SourceType == SourceType.Channel)
 375                {
 0376                    return false;
 377                }
 378
 1364379                return IsFileProtocol;
 380            }
 381        }
 382
 383        [JsonIgnore]
 384        public virtual string FileNameWithoutExtension
 385        {
 386            get
 387            {
 0388                if (IsFileProtocol)
 389                {
 0390                    return System.IO.Path.GetFileNameWithoutExtension(Path);
 391                }
 392
 0393                return null;
 394            }
 395        }
 396
 397        [JsonIgnore]
 107398        public virtual bool EnableAlphaNumericSorting => true;
 399
 146400        public virtual bool IsHD => Height >= 720;
 401
 402        public bool IsShortcut { get; set; }
 403
 404        public string ShortcutPath { get; set; }
 405
 406        public int Width { get; set; }
 407
 408        public int Height { get; set; }
 409
 410        /// <summary>
 411        /// Gets the primary image path.
 412        /// </summary>
 413        /// <remarks>
 414        /// This is just a helper for convenience.
 415        /// </remarks>
 416        /// <value>The primary image path.</value>
 417        [JsonIgnore]
 0418        public string PrimaryImagePath => this.GetImagePath(ImageType.Primary);
 419
 420        /// <summary>
 421        /// Gets or sets the date created.
 422        /// </summary>
 423        /// <value>The date created.</value>
 424        [JsonIgnore]
 425        public DateTime DateCreated { get; set; }
 426
 427        /// <summary>
 428        /// Gets or sets the date modified.
 429        /// </summary>
 430        /// <value>The date modified.</value>
 431        [JsonIgnore]
 432        public DateTime DateModified { get; set; }
 433
 434        public DateTime DateLastSaved { get; set; }
 435
 436        [JsonIgnore]
 437        public DateTime DateLastRefreshed { get; set; }
 438
 439        [JsonIgnore]
 440        public bool IsLocked { get; set; }
 441
 442        /// <summary>
 443        /// Gets or sets the locked fields.
 444        /// </summary>
 445        /// <value>The locked fields.</value>
 446        [JsonIgnore]
 447        public MetadataField[] LockedFields { get; set; }
 448
 449        /// <summary>
 450        /// Gets the type of the media.
 451        /// </summary>
 452        /// <value>The type of the media.</value>
 453        [JsonIgnore]
 140454        public virtual MediaType MediaType => MediaType.Unknown;
 455
 456        [JsonIgnore]
 457        public virtual string[] PhysicalLocations
 458        {
 459            get
 460            {
 0461                if (!IsFileProtocol)
 462                {
 0463                    return Array.Empty<string>();
 464                }
 465
 0466                return [Path];
 467            }
 468        }
 469
 470        [JsonIgnore]
 471        public bool EnableMediaSourceDisplay
 472        {
 473            get
 474            {
 6475                if (SourceType == SourceType.Channel)
 476                {
 0477                    return ChannelManager.EnableMediaSourceDisplay(this);
 478                }
 479
 6480                return true;
 481            }
 482        }
 483
 484        [JsonIgnore]
 485        public Guid ParentId { get; set; }
 486
 487        /// <summary>
 488        /// Gets or sets the logger.
 489        /// </summary>
 490        public static ILogger<BaseItem> Logger { get; set; }
 491
 492        public static ILibraryManager LibraryManager { get; set; }
 493
 494        public static IServerConfigurationManager ConfigurationManager { get; set; }
 495
 496        public static IProviderManager ProviderManager { get; set; }
 497
 498        public static ILocalizationManager LocalizationManager { get; set; }
 499
 500        public static IItemRepository ItemRepository { get; set; }
 501
 502        public static IItemCountService ItemCountService { get; set; }
 503
 504        public static IChapterManager ChapterManager { get; set; }
 505
 506        public static IFileSystem FileSystem { get; set; }
 507
 508        public static IUserDataManager UserDataManager { get; set; }
 509
 510        public static IChannelManager ChannelManager { get; set; }
 511
 512        public static IMediaSourceManager MediaSourceManager { get; set; }
 513
 514        public static IMediaSegmentManager MediaSegmentManager { get; set; }
 515
 516        /// <summary>
 517        /// Gets or sets the name of the forced sort.
 518        /// </summary>
 519        /// <value>The name of the forced sort.</value>
 520        [JsonIgnore]
 521        public string ForcedSortName
 522        {
 494523            get => _forcedSortName;
 524            set
 525            {
 95526                _forcedSortName = value;
 95527                _sortName = null;
 95528            }
 529        }
 530
 531        /// <summary>
 532        /// Gets or sets the name of the sort.
 533        /// </summary>
 534        /// <value>The name of the sort.</value>
 535        [JsonIgnore]
 536        public string SortName
 537        {
 538            get
 539            {
 181540                if (_sortName is null)
 541                {
 107542                    if (!string.IsNullOrEmpty(ForcedSortName))
 543                    {
 544                        // Run the forced sort name through the same cleaning as auto-generated sort names.
 1545                        _sortName = GetSortName(ForcedSortName, EnableAlphaNumericSorting, ConfigurationManager.Configur
 546                    }
 547                    else
 548                    {
 106549                        _sortName = CreateSortName();
 550                    }
 551                }
 552
 181553                return _sortName;
 554            }
 555
 135556            set => _sortName = value;
 557        }
 558
 559        [JsonIgnore]
 358560        public virtual Guid DisplayParentId => ParentId;
 561
 562        [JsonIgnore]
 563        public BaseItem DisplayParent
 564        {
 565            get
 566            {
 358567                var id = DisplayParentId;
 358568                if (id.IsEmpty())
 569                {
 264570                    return null;
 571                }
 572
 94573                return LibraryManager.GetItemById(id);
 574            }
 575        }
 576
 577        /// <summary>
 578        /// Gets or sets the date that the item first debuted. For movies this could be premiere date, episodes would be
 579        /// </summary>
 580        /// <value>The premiere date.</value>
 581        [JsonIgnore]
 582        public DateTime? PremiereDate { get; set; }
 583
 584        /// <summary>
 585        /// Gets or sets the end date.
 586        /// </summary>
 587        /// <value>The end date.</value>
 588        [JsonIgnore]
 589        public DateTime? EndDate { get; set; }
 590
 591        /// <summary>
 592        /// Gets or sets the official rating.
 593        /// </summary>
 594        /// <value>The official rating.</value>
 595        [JsonIgnore]
 596        public string OfficialRating { get; set; }
 597
 598        [JsonIgnore]
 599        public int? InheritedParentalRatingValue { get; set; }
 600
 601        [JsonIgnore]
 602        public int? InheritedParentalRatingSubValue { get; set; }
 603
 604        /// <summary>
 605        /// Gets or sets the critic rating.
 606        /// </summary>
 607        /// <value>The critic rating.</value>
 608        [JsonIgnore]
 609        public float? CriticRating { get; set; }
 610
 611        /// <summary>
 612        /// Gets or sets the custom rating.
 613        /// </summary>
 614        /// <value>The custom rating.</value>
 615        [JsonIgnore]
 616        public string CustomRating { get; set; }
 617
 618        /// <summary>
 619        /// Gets or sets the overview.
 620        /// </summary>
 621        /// <value>The overview.</value>
 622        [JsonIgnore]
 623        public string Overview { get; set; }
 624
 625        /// <summary>
 626        /// Gets or sets the studios.
 627        /// </summary>
 628        /// <value>The studios.</value>
 629        [JsonIgnore]
 630        public string[] Studios { get; set; }
 631
 632        /// <summary>
 633        /// Gets or sets the genres.
 634        /// </summary>
 635        /// <value>The genres.</value>
 636        [JsonIgnore]
 637        public string[] Genres { get; set; }
 638
 639        /// <summary>
 640        /// Gets or sets the tags.
 641        /// </summary>
 642        /// <value>The tags.</value>
 643        [JsonIgnore]
 644        public string[] Tags { get; set; }
 645
 646        [JsonIgnore]
 647        public string[] ProductionLocations { get; set; }
 648
 649        /// <summary>
 650        /// Gets or sets the home page URL.
 651        /// </summary>
 652        /// <value>The home page URL.</value>
 653        [JsonIgnore]
 654        public string HomePageUrl { get; set; }
 655
 656        /// <summary>
 657        /// Gets or sets the community rating.
 658        /// </summary>
 659        /// <value>The community rating.</value>
 660        [JsonIgnore]
 661        public float? CommunityRating { get; set; }
 662
 663        /// <summary>
 664        /// Gets or sets the run time ticks.
 665        /// </summary>
 666        /// <value>The run time ticks.</value>
 667        [JsonIgnore]
 668        public long? RunTimeTicks { get; set; }
 669
 670        /// <summary>
 671        /// Gets or sets the production year.
 672        /// </summary>
 673        /// <value>The production year.</value>
 674        [JsonIgnore]
 675        public int? ProductionYear { get; set; }
 676
 677        /// <summary>
 678        /// Gets or sets the index number. If the item is part of a series, this is it's number in the series.
 679        /// This could be episode number, album track number, etc.
 680        /// </summary>
 681        /// <value>The index number.</value>
 682        [JsonIgnore]
 683        public int? IndexNumber { get; set; }
 684
 685        /// <summary>
 686        /// Gets or sets the parent index number. For an episode this could be the season number, or for a song this cou
 687        /// </summary>
 688        /// <value>The parent index number.</value>
 689        [JsonIgnore]
 690        public int? ParentIndexNumber { get; set; }
 691
 692        [JsonIgnore]
 0693        public virtual bool HasLocalAlternateVersions => false;
 694
 695        [JsonIgnore]
 696        public string OfficialRatingForComparison
 697        {
 698            get
 699            {
 176700                var officialRating = OfficialRating;
 176701                if (!string.IsNullOrEmpty(officialRating))
 702                {
 0703                    return officialRating;
 704                }
 705
 176706                var parent = DisplayParent;
 176707                if (parent is not null)
 708                {
 44709                    return parent.OfficialRatingForComparison;
 710                }
 711
 132712                return null;
 713            }
 714        }
 715
 716        [JsonIgnore]
 717        public string CustomRatingForComparison
 718        {
 719            get
 720            {
 132721                return GetCustomRatingForComparision();
 722            }
 723        }
 724
 725        /// <summary>
 726        /// Gets or sets the provider ids.
 727        /// </summary>
 728        /// <value>The provider ids.</value>
 729        [JsonIgnore]
 730        public Dictionary<string, string> ProviderIds { get; set; }
 731
 732        [JsonIgnore]
 0733        public virtual Folder LatestItemsIndexContainer => null;
 734
 735        [JsonIgnore]
 736        public string PresentationUniqueKey { get; set; }
 737
 738        [JsonIgnore]
 31739        public virtual bool EnableRememberingTrackSelections => true;
 740
 741        [JsonIgnore]
 742        public virtual bool IsTopParent
 743        {
 744            get
 745            {
 359746                if (this is BasePluginFolder || this is Channel)
 747                {
 61748                    return true;
 749                }
 750
 298751                if (this is IHasCollectionType view)
 752                {
 13753                    if (view.CollectionType == CollectionType.livetv)
 754                    {
 0755                        return true;
 756                    }
 757                }
 758
 298759                if (GetParent() is AggregateFolder)
 760                {
 0761                    return true;
 762                }
 763
 298764                return false;
 765            }
 766        }
 767
 768        [JsonIgnore]
 468769        public virtual bool SupportsAncestors => true;
 770
 771        [JsonIgnore]
 99772        protected virtual bool SupportsOwnedItems => !ParentId.IsEmpty() && IsFileProtocol;
 773
 774        [JsonIgnore]
 72775        public virtual bool SupportsPeople => false;
 776
 777        [JsonIgnore]
 0778        public virtual bool SupportsThemeMedia => false;
 779
 780        [JsonIgnore]
 0781        public virtual bool SupportsInheritedParentImages => false;
 782
 783        /// <summary>
 784        /// Gets a value indicating whether this instance is folder.
 785        /// </summary>
 786        /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
 787        [JsonIgnore]
 92788        public virtual bool IsFolder => false;
 789
 790        [JsonIgnore]
 0791        public virtual bool IsDisplayedAsFolder => false;
 792
 793        /// <summary>
 794        /// Gets or sets the remote trailers.
 795        /// </summary>
 796        /// <value>The remote trailers.</value>
 797        public IReadOnlyList<MediaUrl> RemoteTrailers { get; set; }
 798
 799        private string GetCustomRatingForComparision(HashSet<Guid> callstack = null)
 800        {
 176801            callstack ??= new();
 176802            var customRating = CustomRating;
 176803            if (!string.IsNullOrEmpty(customRating))
 804            {
 0805                return customRating;
 806            }
 807
 176808            callstack.Add(Id);
 809
 176810            var parent = DisplayParent;
 176811            if (parent is not null && !callstack.Contains(parent.Id))
 812            {
 44813                return parent.GetCustomRatingForComparision(callstack);
 814            }
 815
 132816            return null;
 817        }
 818
 819        public virtual double GetDefaultPrimaryImageAspectRatio()
 820        {
 0821            return 0;
 822        }
 823
 824        public virtual string CreatePresentationUniqueKey()
 825        {
 61826            return Id.ToString("N", CultureInfo.InvariantCulture);
 827        }
 828
 829        public virtual bool CanDelete()
 830        {
 0831            if (SourceType == SourceType.Channel)
 832            {
 0833                return ChannelManager.CanDelete(this);
 834            }
 835
 0836            return IsFileProtocol;
 837        }
 838
 839        public virtual bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders)
 840        {
 0841            if (user.HasPermission(PermissionKind.EnableContentDeletion))
 842            {
 0843                return true;
 844            }
 845
 0846            var allowed = user.GetPreferenceValues<Guid>(PreferenceKind.EnableContentDeletionFromFolders);
 847
 0848            if (SourceType == SourceType.Channel)
 849            {
 0850                return allowed.Contains(ChannelId);
 851            }
 852
 0853            var collectionFolders = LibraryManager.GetCollectionFolders(this, allCollectionFolders);
 854
 0855            foreach (var folder in collectionFolders)
 856            {
 0857                if (allowed.Contains(folder.Id))
 858                {
 0859                    return true;
 860                }
 861            }
 862
 0863            return false;
 0864        }
 865
 866        public BaseItem GetOwner()
 867        {
 667868            var ownerId = OwnerId;
 667869            return ownerId.IsEmpty() ? null : LibraryManager.GetItemById(ownerId);
 870        }
 871
 872        public bool CanDelete(User user, List<Folder> allCollectionFolders)
 873        {
 6874            return CanDelete() && IsAuthorizedToDelete(user, allCollectionFolders);
 875        }
 876
 877        public virtual bool CanDelete(User user)
 878        {
 6879            var allCollectionFolders = LibraryManager.GetUserRootFolder().Children.OfType<Folder>().ToList();
 880
 6881            return CanDelete(user, allCollectionFolders);
 882        }
 883
 884        public virtual bool CanDownload()
 885        {
 6886            return false;
 887        }
 888
 889        public virtual bool IsAuthorizedToDownload(User user)
 890        {
 0891            return user.HasPermission(PermissionKind.EnableContentDownloading);
 892        }
 893
 894        public bool CanDownload(User user)
 895        {
 6896            return CanDownload() && IsAuthorizedToDownload(user);
 897        }
 898
 899        /// <inheritdoc />
 900        public override string ToString()
 901        {
 69902            return Name;
 903        }
 904
 905        public virtual string GetInternalMetadataPath()
 906        {
 72907            var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath;
 908
 72909            return GetInternalMetadataPath(basePath);
 910        }
 911
 912        protected virtual string GetInternalMetadataPath(string basePath)
 913        {
 72914            if (SourceType == SourceType.Channel)
 915            {
 0916                return System.IO.Path.Join(basePath, "channels", ChannelId.ToString("N", CultureInfo.InvariantCulture), 
 917            }
 918
 72919            ReadOnlySpan<char> idString = Id.ToString("N", CultureInfo.InvariantCulture);
 920
 72921            return System.IO.Path.Join(basePath, "library", idString[..2], idString);
 922        }
 923
 924        /// <summary>
 925        /// Creates the name of the sort.
 926        /// </summary>
 927        /// <returns>System.String.</returns>
 928        protected virtual string CreateSortName()
 929        {
 106930            return GetSortName(Name, EnableAlphaNumericSorting, ConfigurationManager.Configuration);
 931        }
 932
 933        /// <summary>
 934        /// Cleans a raw name into its sortable form by applying the configured sort rules.
 935        /// </summary>
 936        /// <param name="name">The raw name to clean.</param>
 937        /// <param name="enableAlphaNumericSorting">Whether alphanumeric sorting rules should be applied.</param>
 938        /// <param name="configuration">The server configuration providing the sort rules.</param>
 939        /// <returns>The cleaned, sortable name, or <c>null</c> if <paramref name="name"/> is <c>null</c>.</returns>
 940        public static string GetSortName(string name, bool enableAlphaNumericSorting, ServerConfiguration configuration)
 941        {
 111942            if (name is null)
 943            {
 0944                return null; // some items may not have name filled in properly
 945            }
 946
 111947            if (!enableAlphaNumericSorting)
 948            {
 1949                return name.TrimStart();
 950            }
 951
 110952            var sortable = name.Trim().ToLowerInvariant();
 953
 880954            foreach (var search in configuration.SortRemoveWords)
 955            {
 956                // Remove from beginning if a space follows
 330957                if (sortable.StartsWith(search + " ", StringComparison.Ordinal))
 958                {
 4959                    sortable = sortable.Remove(0, search.Length + 1);
 960                }
 961
 962                // Remove from middle if surrounded by spaces
 330963                sortable = sortable.Replace(" " + search + " ", " ", StringComparison.Ordinal);
 964
 965                // Remove from end if preceeded by a space
 330966                if (sortable.EndsWith(" " + search, StringComparison.Ordinal))
 967                {
 0968                    sortable = sortable.Remove(sortable.Length - (search.Length + 1));
 969                }
 970            }
 971
 1540972            foreach (var removeChar in configuration.SortRemoveCharacters)
 973            {
 660974                sortable = sortable.Replace(removeChar, string.Empty, StringComparison.Ordinal);
 975            }
 976
 880977            foreach (var replaceChar in configuration.SortReplaceCharacters)
 978            {
 330979                sortable = sortable.Replace(replaceChar, " ", StringComparison.Ordinal);
 980            }
 981
 110982            return ModifySortChunks(sortable);
 983        }
 984
 985        internal static string ModifySortChunks(ReadOnlySpan<char> name)
 986        {
 987            static void AppendChunk(StringBuilder builder, bool isDigitChunk, ReadOnlySpan<char> chunk)
 988            {
 989                if (isDigitChunk && chunk.Length < 10)
 990                {
 991                    builder.Append('0', 10 - chunk.Length);
 992                }
 993
 994                builder.Append(chunk);
 995            }
 996
 116997            if (name.IsEmpty)
 998            {
 1999                return string.Empty;
 1000            }
 1001
 1151002            var builder = new StringBuilder(name.Length);
 1003
 1151004            int chunkStart = 0;
 1151005            bool isDigitChunk = char.IsDigit(name[0]);
 19081006            for (int i = 0; i < name.Length; i++)
 1007            {
 8391008                var isDigit = char.IsDigit(name[i]);
 8391009                if (isDigit != isDigitChunk)
 1010                {
 61011                    AppendChunk(builder, isDigitChunk, name.Slice(chunkStart, i - chunkStart));
 61012                    chunkStart = i;
 61013                    isDigitChunk = isDigit;
 1014                }
 1015            }
 1016
 1151017            AppendChunk(builder, isDigitChunk, name.Slice(chunkStart));
 1018
 1019            // logger.LogDebug("ModifySortChunks Start: {0} End: {1}", name, builder.ToString());
 1151020            var result = builder.ToString().RemoveDiacritics();
 1151021            if (!result.All(char.IsAscii))
 1022            {
 01023                result = result.Transliterated();
 1024            }
 1025
 1151026            return result;
 1027        }
 1028
 1029        public BaseItem GetParent()
 1030        {
 21431031            var parentId = ParentId;
 21431032            if (parentId.IsEmpty())
 1033            {
 18491034                return null;
 1035            }
 1036
 2941037            return LibraryManager.GetItemById(parentId);
 1038        }
 1039
 1040        public IEnumerable<BaseItem> GetParents()
 1041        {
 7091042            var parent = GetParent();
 1043
 7821044            while (parent is not null)
 1045            {
 731046                yield return parent;
 1047
 731048                parent = parent.GetParent();
 1049            }
 7091050        }
 1051
 1052        /// <summary>
 1053        /// Finds a parent of a given type.
 1054        /// </summary>
 1055        /// <typeparam name="T">Type of parent.</typeparam>
 1056        /// <returns>``0.</returns>
 1057        public T FindParent<T>()
 1058            where T : Folder
 1059        {
 01060            foreach (var parent in GetParents())
 1061            {
 01062                if (parent is T item)
 1063                {
 01064                    return item;
 1065                }
 1066            }
 1067
 01068            return null;
 01069        }
 1070
 1071        /// <summary>
 1072        /// Gets the play access.
 1073        /// </summary>
 1074        /// <param name="user">The user.</param>
 1075        /// <returns>PlayAccess.</returns>
 1076        public PlayAccess GetPlayAccess(User user)
 1077        {
 61078            if (!user.HasPermission(PermissionKind.EnableMediaPlayback))
 1079            {
 01080                return PlayAccess.None;
 1081            }
 1082
 1083            // if (!user.IsParentalScheduleAllowed())
 1084            // {
 1085            //    return PlayAccess.None;
 1086            // }
 1087
 61088            return PlayAccess.Full;
 1089        }
 1090
 1091        public virtual IReadOnlyList<MediaStream> GetMediaStreams()
 1092        {
 01093            return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
 01094            {
 01095                ItemId = Id
 01096            });
 1097        }
 1098
 1099        protected virtual bool IsActiveRecording()
 1100        {
 01101            return false;
 1102        }
 1103
 1104        public virtual IReadOnlyList<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
 1105        {
 61106            if (SourceType == SourceType.Channel)
 1107            {
 01108                var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
 01109                           .ToList();
 1110
 01111                if (sources.Count > 0)
 1112                {
 01113                    return sources;
 1114                }
 1115            }
 1116
 61117            var list = GetAllItemsForMediaSources().ToList();
 61118            var commonPrefix = GetCommonNamePrefix(list);
 61119            var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item, i.MediaSourceType, commonPrefix
 1120
 61121            if (IsActiveRecording())
 1122            {
 01123                foreach (var mediaSource in result)
 1124                {
 01125                    mediaSource.Type = MediaSourceType.Placeholder;
 1126                }
 1127            }
 1128
 1129            // The source belonging to the item being queried sorts first so it is the default the client plays.
 61130            var selfId = Id.ToString("N", CultureInfo.InvariantCulture);
 1131
 61132            return result
 61133                .OrderByDescending(i => string.Equals(i.Id, selfId, StringComparison.OrdinalIgnoreCase))
 61134                .ThenBy(i => i.VideoType == VideoType.VideoFile ? 0 : 1)
 61135                .ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
 61136                .ThenByDescending(i => i, new MediaSourceWidthComparator())
 61137                .ToArray();
 1138        }
 1139
 1140        protected virtual IEnumerable<(BaseItem Item, MediaSourceType MediaSourceType)> GetAllItemsForMediaSources()
 1141        {
 01142            return Enumerable.Empty<(BaseItem, MediaSourceType)>();
 1143        }
 1144
 1145        private MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, BaseItem item, MediaSourceType type, string 
 1146        {
 181147            ArgumentNullException.ThrowIfNull(item);
 1148
 181149            var protocol = item.PathProtocol;
 181150            var itemPath = item.Path;
 1151
 181152            var info = new MediaSourceInfo
 181153            {
 181154                Id = item.Id.ToString("N", CultureInfo.InvariantCulture),
 181155                Protocol = protocol ?? MediaProtocol.File,
 181156                MediaStreams = MediaSourceManager.GetMediaStreams(item.Id),
 181157                MediaAttachments = MediaSourceManager.GetMediaAttachments(item.Id),
 181158                Name = GetMediaSourceName(item, commonPrefix),
 181159                Path = enablePathSubstitution ? GetMappedPath(item, itemPath, protocol) : itemPath,
 181160                RunTimeTicks = item.RunTimeTicks,
 181161                Container = item.Container,
 181162                Size = item.Size,
 181163                Type = type,
 181164                HasSegments = MediaSegmentManager.IsTypeSupported(item)
 181165                    && (protocol is null or MediaProtocol.File)
 181166                    && MediaSegmentManager.HasSegments(item.Id)
 181167            };
 1168
 181169            if (string.IsNullOrEmpty(info.Path))
 1170            {
 01171                info.Type = MediaSourceType.Placeholder;
 1172            }
 1173
 181174            if (info.Protocol == MediaProtocol.File)
 1175            {
 181176                info.ETag = item.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N", Cultur
 1177            }
 1178
 181179            var video = item as Video;
 181180            if (video is not null)
 1181            {
 181182                info.IsoType = video.IsoType;
 181183                info.VideoType = video.VideoType;
 181184                info.Video3DFormat = video.Video3DFormat;
 181185                info.Timestamp = video.Timestamp;
 1186
 181187                if (video.IsShortcut && !string.IsNullOrEmpty(video.ShortcutPath))
 1188                {
 01189                    var shortcutProtocol = MediaSourceManager.GetPathProtocol(video.ShortcutPath);
 1190
 1191                    // Only allow remote shortcut paths — local file paths in .strm files
 1192                    // could be used to read arbitrary files from the server.
 01193                    if (shortcutProtocol != MediaProtocol.File)
 1194                    {
 01195                        info.IsRemote = true;
 01196                        info.Path = video.ShortcutPath;
 01197                        info.Protocol = shortcutProtocol;
 1198                    }
 1199                }
 1200
 181201                if (string.IsNullOrEmpty(info.Container))
 1202                {
 181203                    if (video.VideoType == VideoType.VideoFile || video.VideoType == VideoType.Iso)
 1204                    {
 181205                        if (protocol.HasValue && protocol.Value == MediaProtocol.File)
 1206                        {
 181207                            info.Container = System.IO.Path.GetExtension(item.Path).TrimStart('.');
 1208                        }
 1209                    }
 1210                }
 1211            }
 1212
 181213            if (string.IsNullOrEmpty(info.Container))
 1214            {
 01215                if (protocol.HasValue && protocol.Value == MediaProtocol.File)
 1216                {
 01217                    info.Container = System.IO.Path.GetExtension(item.Path).TrimStart('.');
 1218                }
 1219            }
 1220
 181221            if (info.SupportsDirectStream && !string.IsNullOrEmpty(info.Path))
 1222            {
 181223                info.SupportsDirectStream = MediaSourceManager.SupportsDirectStream(info.Path, info.Protocol);
 1224            }
 1225
 181226            if (video is not null && video.VideoType != VideoType.VideoFile)
 1227            {
 01228                info.SupportsDirectStream = false;
 1229            }
 1230
 181231            info.Bitrate = item.TotalBitrate;
 181232            info.InferTotalBitrate();
 1233
 181234            return info;
 1235        }
 1236
 1237        internal string GetMediaSourceName(BaseItem item, string commonPrefix = null)
 1238        {
 381239            var terms = new List<string>();
 1240
 381241            var path = item.Path;
 381242            if (item.IsFileProtocol && !string.IsNullOrEmpty(path))
 1243            {
 381244                var displayName = System.IO.Path.GetFileNameWithoutExtension(path);
 1245
 1246                // Prefer the suffix that differs from the other versions: strip the prefix shared by
 1247                // all sibling files. This works regardless of folder layout, so it also labels episode
 1248                // versions that share a season folder (e.g. "Greyscale" instead of the full
 1249                // "Show - S01E02 - Title - Greyscale"). The prefix is already retreated to a delimiter
 1250                // boundary (see GetCommonVersionPrefix).
 381251                if (!string.IsNullOrEmpty(commonPrefix)
 381252                    && displayName.Length > commonPrefix.Length
 381253                    && displayName.StartsWith(commonPrefix, StringComparison.OrdinalIgnoreCase))
 1254                {
 271255                    var name = displayName.AsSpan(commonPrefix.Length).TrimStart([' ', .. VersionDelimiters]);
 271256                    if (!name.IsWhiteSpace())
 1257                    {
 271258                        terms.Add(name.ToString());
 1259                    }
 1260                }
 1261
 1262                // Fall back to the containing folder name (the common layout for movie versions, and
 1263                // the path taken when no common prefix could be derived).
 381264                if (terms.Count == 0 && HasLocalAlternateVersions)
 1265                {
 81266                    var containingFolderName = System.IO.Path.GetFileName(ContainingFolderPath);
 81267                    if (displayName.Length > containingFolderName.Length && displayName.StartsWith(containingFolderName,
 1268                    {
 21269                        var name = displayName.AsSpan(containingFolderName.Length).TrimStart([' ', .. VersionDelimiters]
 21270                        if (!name.IsWhiteSpace())
 1271                        {
 21272                            terms.Add(name.ToString());
 1273                        }
 1274                    }
 1275                }
 1276
 381277                if (terms.Count == 0)
 1278                {
 91279                    terms.Add(displayName);
 1280                }
 1281            }
 1282
 381283            if (terms.Count == 0)
 1284            {
 01285                terms.Add(item.Name);
 1286            }
 1287
 381288            if (item is Video video)
 1289            {
 381290                if (video.Video3DFormat.HasValue)
 1291                {
 01292                    terms.Add("3D");
 1293                }
 1294
 381295                if (video.VideoType == VideoType.BluRay)
 1296                {
 01297                    terms.Add("Bluray");
 1298                }
 381299                else if (video.VideoType == VideoType.Dvd)
 1300                {
 01301                    terms.Add("DVD");
 1302                }
 381303                else if (video.VideoType == VideoType.Iso)
 1304                {
 01305                    if (video.IsoType.HasValue)
 1306                    {
 01307                        if (video.IsoType.Value == IsoType.BluRay)
 1308                        {
 01309                            terms.Add("Bluray");
 1310                        }
 01311                        else if (video.IsoType.Value == IsoType.Dvd)
 1312                        {
 01313                            terms.Add("DVD");
 1314                        }
 1315                    }
 1316                    else
 1317                    {
 01318                        terms.Add("ISO");
 1319                    }
 1320                }
 1321            }
 1322
 381323            return string.Join('/', terms);
 1324        }
 1325
 1326        /// <summary>
 1327        /// Derives the prefix shared by the supplied media source items' file names, used to strip the
 1328        /// common part and surface a short version label per source. Returns null when there are fewer
 1329        /// than two file-based sources, since there is nothing to differentiate.
 1330        /// </summary>
 1331        /// <param name="items">The media source items.</param>
 1332        /// <returns>The shared prefix, or null when no useful prefix exists.</returns>
 1333        private static string GetCommonNamePrefix(IReadOnlyList<(BaseItem Item, MediaSourceType MediaSourceType)> items)
 1334        {
 61335            var fileNames = new List<string>();
 481336            foreach (var (item, _) in items)
 1337            {
 181338                if (item.IsFileProtocol && !string.IsNullOrEmpty(item.Path))
 1339                {
 181340                    fileNames.Add(System.IO.Path.GetFileNameWithoutExtension(item.Path));
 1341                }
 1342            }
 1343
 61344            if (fileNames.Count < 2)
 1345            {
 01346                return null;
 1347            }
 1348
 61349            var prefix = GetCommonVersionPrefix(fileNames);
 61350            return string.IsNullOrEmpty(prefix) ? null : prefix;
 1351        }
 1352
 1353        /// <summary>
 1354        /// Computes the case-insensitive longest common prefix of the supplied version file names,
 1355        /// retreated to the last delimiter boundary. Retreating keeps the differing suffix intact:
 1356        /// it avoids slicing through a word every version shares (e.g. "Grey" in "Greyscale" and
 1357        /// "Greyish") while still trimming the common part when every version is suffixed (e.g.
 1358        /// "- Greyscale" / "- Colorized"). It prefers a structural delimiter ('-', '_', '.') so a
 1359        /// token shared by the descriptors but separated only by spaces (e.g. a common "2160p ") is
 1360        /// kept in the label, falling back to a space only when no structural delimiter is shared. The
 1361        /// separators mirror the version delimiters recognised by the naming layer (Emby.Naming
 1362        /// VideoFlagDelimiters).
 1363        /// </summary>
 1364        /// <param name="fileNames">The version file names without extension; must contain at least one entry.</param>
 1365        /// <returns>The shared prefix retreated to a separator boundary, or an empty string when none is shared.</retur
 1366        internal static string GetCommonVersionPrefix(IReadOnlyList<string> fileNames)
 1367        {
 141368            var prefix = fileNames[0];
 681369            for (var i = 1; i < fileNames.Count && prefix.Length > 0; i++)
 1370            {
 201371                var name = fileNames[i];
 201372                var length = Math.Min(prefix.Length, name.Length);
 201373                var common = 0;
 2531374                while (common < length && char.ToUpperInvariant(prefix[common]) == char.ToUpperInvariant(name[common]))
 1375                {
 2331376                    common++;
 1377                }
 1378
 201379                prefix = prefix[..common];
 1380            }
 1381
 1382            // If the common prefix is itself a whole file name then one version is unlabelled (the
 1383            // base name); the boundary already sits at the end of that name, so don't retreat into it.
 141384            var prefixIsWholeName = false;
 601385            for (var i = 0; i < fileNames.Count; i++)
 1386            {
 231387                if (fileNames[i].Length == prefix.Length)
 1388                {
 71389                    prefixIsWholeName = true;
 71390                    break;
 1391                }
 1392            }
 1393
 141394            if (!prefixIsWholeName)
 1395            {
 1396                // Retreat to the last structural delimiter ('-', '_', '.').
 71397                var cut = prefix.Length;
 461398                while (cut > 0 && Array.IndexOf(VersionDelimiters, prefix[cut - 1]) < 0)
 1399                {
 391400                    cut--;
 1401                }
 1402
 71403                if (cut == 0)
 1404                {
 11405                    cut = prefix.Length;
 21406                    while (cut > 0 && prefix[cut - 1] != ' ')
 1407                    {
 11408                        cut--;
 1409                    }
 1410                }
 1411
 71412                prefix = prefix[..cut];
 1413            }
 1414
 141415            return prefix;
 1416        }
 1417
 1418        public Task RefreshMetadata(CancellationToken cancellationToken)
 1419        {
 541420            return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken);
 1421        }
 1422
 1423        /// <summary>
 1424        /// The base implementation to refresh metadata.
 1425        /// </summary>
 1426        /// <param name="options">The options.</param>
 1427        /// <param name="cancellationToken">The cancellation token.</param>
 1428        /// <returns>true if a provider reports we changed.</returns>
 1429        public async Task<ItemUpdateType> RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellation
 1430        {
 611431            var requiresSave = false;
 1432
 611433            if (SupportsOwnedItems)
 1434            {
 1435                try
 1436                {
 381437                    if (IsFileProtocol)
 1438                    {
 381439                        requiresSave = await RefreshedOwnedItems(options, GetFileSystemChildren(options.DirectoryService
 1440                    }
 1441
 381442                    await LibraryManager.UpdateImagesAsync(this).ConfigureAwait(false); // ensure all image properties i
 381443                }
 01444                catch (Exception ex)
 1445                {
 01446                    Logger.LogError(ex, "Error refreshing owned items for {Path}", Path ?? Name);
 01447                }
 1448            }
 1449
 611450            var refreshOptions = requiresSave
 611451                ? new MetadataRefreshOptions(options)
 611452                {
 611453                    ForceSave = true
 611454                }
 611455                : options;
 1456
 611457            return await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false
 601458        }
 1459
 1460        protected bool IsVisibleStandaloneInternal(User user, bool checkFolders)
 1461        {
 01462            if (!IsVisible(user))
 1463            {
 01464                return false;
 1465            }
 1466
 01467            var parents = GetParents().ToList();
 01468            if (parents.Any(i => !i.IsVisible(user, true)))
 1469            {
 01470                return false;
 1471            }
 1472
 01473            if (checkFolders)
 1474            {
 01475                var topParent = parents.Count > 0 ? parents[^1] : this;
 1476
 01477                if (string.IsNullOrEmpty(topParent.Path))
 1478                {
 01479                    return true;
 1480                }
 1481
 01482                var itemCollectionFolders = LibraryManager.GetCollectionFolders(this).Select(i => i.Id).ToList();
 1483
 01484                if (itemCollectionFolders.Count > 0)
 1485                {
 01486                    var blockedMediaFolders = user.GetPreferenceValues<Guid>(PreferenceKind.BlockedMediaFolders);
 1487                    IEnumerable<Guid> userCollectionFolderIds;
 01488                    if (blockedMediaFolders.Length > 0)
 1489                    {
 1490                        // User has blocked folders - get all library folders and exclude blocked ones
 01491                        userCollectionFolderIds = LibraryManager.GetUserRootFolder().Children
 01492                            .Select(i => i.Id)
 01493                            .Where(id => !blockedMediaFolders.Contains(id));
 1494                    }
 01495                    else if (user.HasPermission(PermissionKind.EnableAllFolders))
 1496                    {
 1497                        // User can access all folders - no need to filter
 01498                        return true;
 1499                    }
 1500                    else
 1501                    {
 1502                        // User has specific enabled folders
 01503                        userCollectionFolderIds = user.GetPreferenceValues<Guid>(PreferenceKind.EnabledFolders);
 1504                    }
 1505
 01506                    if (!itemCollectionFolders.Any(userCollectionFolderIds.Contains))
 1507                    {
 01508                        return false;
 1509                    }
 1510                }
 1511            }
 1512
 01513            return true;
 1514        }
 1515
 1516        public void SetParent(Folder parent)
 1517        {
 91518            ParentId = parent is null ? Guid.Empty : parent.Id;
 91519        }
 1520
 1521        /// <summary>
 1522        /// Refreshes owned items such as trailers, theme videos, special features, etc.
 1523        /// Returns true or false indicating if changes were found.
 1524        /// </summary>
 1525        /// <param name="options">The metadata refresh options.</param>
 1526        /// <param name="fileSystemChildren">The list of filesystem children.</param>
 1527        /// <param name="cancellationToken">The cancellation token.</param>
 1528        /// <returns><c>true</c> if any items have changed, else <c>false</c>.</returns>
 1529        protected virtual async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, IReadOnlyList<FileSystemM
 1530        {
 381531            if (!IsFileProtocol || !SupportsOwnedItems || IsInMixedFolder || this is ICollectionFolder or UserRootFolder
 1532            {
 381533                return false;
 1534            }
 1535
 01536            return await RefreshExtras(this, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
 381537        }
 1538
 1539        protected virtual FileSystemMetadata[] GetFileSystemChildren(IDirectoryService directoryService)
 1540        {
 421541            return directoryService.GetFileSystemEntries(ContainingFolderPath);
 1542        }
 1543
 1544        private async Task<bool> RefreshExtras(BaseItem item, MetadataRefreshOptions options, IReadOnlyList<FileSystemMe
 1545        {
 01546            var extras = LibraryManager.FindExtras(item, fileSystemChildren, options.DirectoryService).ToArray();
 01547            var newExtraIds = Array.ConvertAll(extras, x => x.Id);
 1548
 01549            var currentExtras = LibraryManager.GetItemList(new InternalItemsQuery()
 01550            {
 01551                OwnerIds = [item.Id]
 01552            });
 1553
 01554            var currentExtraIds = currentExtras.Select(e => e.Id).ToArray();
 1555
 01556            var extrasChanged = !currentExtraIds.OrderBy(x => x).SequenceEqual(newExtraIds.OrderBy(x => x));
 1557
 01558            if (!extrasChanged && !options.ReplaceAllMetadata && options.MetadataRefreshMode != MetadataRefreshMode.Full
 1559            {
 1560                // The owner's dates may only have become known after its extras were created, so keep
 1561                // them in sync even when there is nothing to refresh.
 01562                foreach (var extra in currentExtras)
 1563                {
 01564                    if (extra.ExtraType is not null && InheritDatesFromOwner(item, extra))
 1565                    {
 01566                        await extra.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwa
 1567                    }
 1568                }
 1569
 01570                return false;
 1571            }
 1572
 01573            var ownerId = item.Id;
 1574
 01575            var tasks = extras.Select(i =>
 01576            {
 01577                var subOptions = new MetadataRefreshOptions(options);
 01578                if (!i.OwnerId.Equals(ownerId) || !i.ParentId.IsEmpty())
 01579                {
 01580                    subOptions.ForceSave = true;
 01581                }
 01582
 01583                i.OwnerId = ownerId;
 01584                i.ParentId = Guid.Empty;
 01585
 01586                return RefreshMetadataForOwnedItem(i, true, subOptions, cancellationToken);
 01587            });
 1588
 01589            var removedExtraIds = currentExtraIds.Where(e => !newExtraIds.Contains(e)).ToArray();
 01590            if (removedExtraIds.Length > 0)
 1591            {
 01592                var removedExtras = LibraryManager.GetItemList(new InternalItemsQuery()
 01593                {
 01594                    ItemIds = removedExtraIds
 01595                });
 01596                foreach (var removedExtra in removedExtras)
 1597                {
 1598                    // Only delete items that are actual extras (have ExtraType set)
 1599                    // Items with OwnerId but no ExtraType might be alternate versions, not extras
 01600                    if (removedExtra.ExtraType.HasValue)
 1601                    {
 01602                        LibraryManager.DeleteItem(removedExtra, new DeleteOptions()
 01603                        {
 01604                            DeleteFileLocation = false
 01605                        });
 1606                    }
 1607                }
 1608            }
 1609
 01610            await Task.WhenAll(tasks).ConfigureAwait(false);
 1611
 01612            return true;
 01613        }
 1614
 1615        public string GetPresentationUniqueKey()
 1616        {
 01617            return PresentationUniqueKey ?? CreatePresentationUniqueKey();
 1618        }
 1619
 1620        public virtual bool RequiresRefresh()
 1621        {
 611622            if (string.IsNullOrEmpty(Path) || DateModified == DateTime.MinValue)
 1623            {
 611624                return false;
 1625            }
 1626
 01627            var info = FileSystem.GetFileSystemInfo(Path);
 1628
 01629            return info.Exists && this.HasChanged(info.LastWriteTimeUtc);
 1630        }
 1631
 1632        public virtual List<string> GetUserDataKeys()
 1633        {
 1741634            var list = new List<string>();
 1635
 1741636            if (SourceType == SourceType.Channel)
 1637            {
 01638                if (!string.IsNullOrEmpty(ExternalId))
 1639                {
 01640                    list.Add(ExternalId);
 1641                }
 1642            }
 1643
 1741644            list.Add(Id.ToString());
 1741645            return list;
 1646        }
 1647
 1648        internal virtual ItemUpdateType UpdateFromResolvedItem(BaseItem newItem)
 1649        {
 51650            var updateType = ItemUpdateType.None;
 1651
 51652            if (IsInMixedFolder != newItem.IsInMixedFolder)
 1653            {
 01654                IsInMixedFolder = newItem.IsInMixedFolder;
 01655                updateType |= ItemUpdateType.MetadataImport;
 1656            }
 1657
 51658            return updateType;
 1659        }
 1660
 1661        public void AfterMetadataRefresh()
 1662        {
 601663            _sortName = null;
 601664        }
 1665
 1666        /// <summary>
 1667        /// Gets the preferred metadata language.
 1668        /// </summary>
 1669        /// <returns>System.String.</returns>
 1670        public string GetPreferredMetadataLanguage()
 1671        {
 361672            string lang = PreferredMetadataLanguage;
 1673
 361674            if (string.IsNullOrEmpty(lang))
 1675            {
 361676                lang = GetParents()
 361677                    .Select(i => i.PreferredMetadataLanguage)
 361678                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1679            }
 1680
 361681            if (string.IsNullOrEmpty(lang))
 1682            {
 361683                lang = LibraryManager.GetCollectionFolders(this)
 361684                    .Select(i => i.PreferredMetadataLanguage)
 361685                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1686            }
 1687
 361688            if (string.IsNullOrEmpty(lang))
 1689            {
 361690                lang = LibraryManager.GetLibraryOptions(this).PreferredMetadataLanguage;
 1691            }
 1692
 361693            if (string.IsNullOrEmpty(lang))
 1694            {
 361695                lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
 1696            }
 1697
 361698            return lang;
 1699        }
 1700
 1701        /// <summary>
 1702        /// Gets the preferred metadata country code.
 1703        /// </summary>
 1704        /// <returns>System.String.</returns>
 1705        public string GetPreferredMetadataCountryCode()
 1706        {
 361707            string lang = PreferredMetadataCountryCode;
 1708
 361709            if (string.IsNullOrEmpty(lang))
 1710            {
 361711                lang = GetParents()
 361712                    .Select(i => i.PreferredMetadataCountryCode)
 361713                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1714            }
 1715
 361716            if (string.IsNullOrEmpty(lang))
 1717            {
 361718                lang = LibraryManager.GetCollectionFolders(this)
 361719                    .Select(i => i.PreferredMetadataCountryCode)
 361720                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1721            }
 1722
 361723            if (string.IsNullOrEmpty(lang))
 1724            {
 361725                lang = LibraryManager.GetLibraryOptions(this).MetadataCountryCode;
 1726            }
 1727
 361728            if (string.IsNullOrEmpty(lang))
 1729            {
 361730                lang = ConfigurationManager.Configuration.MetadataCountryCode;
 1731            }
 1732
 361733            return lang;
 1734        }
 1735
 1736        /// <summary>
 1737        /// Gets the original language of the item, inheriting from parent items if necessary.
 1738        /// </summary>
 1739        /// <returns>System.String.</returns>
 1740        public virtual string GetInheritedOriginalLanguage()
 1741        {
 01742            return OriginalLanguage;
 1743        }
 1744
 1745        public virtual bool IsSaveLocalMetadataEnabled()
 1746        {
 881747            if (SourceType == SourceType.Channel)
 1748            {
 01749                return false;
 1750            }
 1751
 881752            var libraryOptions = LibraryManager.GetLibraryOptions(this);
 1753
 881754            return libraryOptions.SaveLocalMetadata;
 1755        }
 1756
 1757        /// <summary>
 1758        /// Determines if a given user has access to this item.
 1759        /// </summary>
 1760        /// <param name="user">The user.</param>
 1761        /// <param name="skipAllowedTagsCheck">Don't check for allowed tags.</param>
 1762        /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
 1763        /// <exception cref="ArgumentNullException">If user is null.</exception>
 1764        public bool IsParentalAllowed(User user, bool skipAllowedTagsCheck)
 1765        {
 101766            ArgumentNullException.ThrowIfNull(user);
 1767
 101768            if (!IsVisibleViaTags(user, skipAllowedTagsCheck))
 1769            {
 01770                return false;
 1771            }
 1772
 101773            var maxAllowedRating = user.MaxParentalRatingScore;
 101774            var maxAllowedSubRating = user.MaxParentalRatingSubScore;
 101775            var rating = CustomRatingForComparison;
 1776
 101777            if (string.IsNullOrEmpty(rating))
 1778            {
 101779                rating = OfficialRatingForComparison;
 1780            }
 1781
 101782            if (string.IsNullOrEmpty(rating))
 1783            {
 101784                return !GetBlockUnratedValue(user);
 1785            }
 1786
 01787            var ratingScore = LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode());
 1788
 1789            // Could not determine rating level
 01790            if (ratingScore is null)
 1791            {
 01792                var isAllowed = !GetBlockUnratedValue(user);
 1793
 01794                if (!isAllowed)
 1795                {
 01796                    Logger.LogDebug("{0} has an unrecognized parental rating of {1}.", Name, rating);
 1797                }
 1798
 01799                return isAllowed;
 1800            }
 1801
 01802            if (!maxAllowedRating.HasValue)
 1803            {
 01804                return true;
 1805            }
 1806
 01807            if (ratingScore.Score != maxAllowedRating.Value)
 1808            {
 01809                return ratingScore.Score < maxAllowedRating.Value;
 1810            }
 1811
 01812            return !maxAllowedSubRating.HasValue || (ratingScore.SubScore ?? 0) <= maxAllowedSubRating.Value;
 1813        }
 1814
 1815        public ParentalRatingScore GetParentalRatingScore()
 1816        {
 1221817            var rating = CustomRatingForComparison;
 1818
 1221819            if (string.IsNullOrEmpty(rating))
 1820            {
 1221821                rating = OfficialRatingForComparison;
 1822            }
 1823
 1221824            if (string.IsNullOrEmpty(rating))
 1825            {
 1221826                return null;
 1827            }
 1828
 01829            return LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode());
 1830        }
 1831
 1832        public List<string> GetInheritedTags()
 1833        {
 1171834            var list = new List<string>();
 1171835            list.AddRange(Tags);
 1836
 2901837            foreach (var parent in GetParents())
 1838            {
 281839                list.AddRange(parent.Tags);
 1840            }
 1841
 2341842            foreach (var folder in LibraryManager.GetCollectionFolders(this))
 1843            {
 01844                list.AddRange(folder.Tags);
 1845            }
 1846
 1171847            return list.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
 1848        }
 1849
 1850        protected bool IsVisibleViaTags(User user, bool skipAllowedTagsCheck)
 1851        {
 101852            var blockedTags = user.GetPreference(PreferenceKind.BlockedTags);
 101853            var allowedTags = user.GetPreference(PreferenceKind.AllowedTags);
 1854
 101855            if (blockedTags.Length == 0 && allowedTags.Length == 0)
 1856            {
 101857                return true;
 1858            }
 1859
 1860            // Normalize tags using the same logic as database queries
 01861            var normalizedBlockedTags = blockedTags
 01862                .Where(t => !string.IsNullOrWhiteSpace(t))
 01863                .Select(t => t.GetCleanValue())
 01864                .ToHashSet(StringComparer.Ordinal);
 1865
 01866            var normalizedItemTags = GetInheritedTags()
 01867                .Select(t => t.GetCleanValue())
 01868                .ToHashSet(StringComparer.Ordinal);
 1869
 1870            // Check blocked tags - item is hidden if it has any blocked tag
 01871            if (normalizedBlockedTags.Overlaps(normalizedItemTags))
 1872            {
 01873                return false;
 1874            }
 1875
 01876            var parent = GetParents().FirstOrDefault() ?? this;
 01877            if (parent is UserRootFolder or AggregateFolder or UserView)
 1878            {
 01879                return true;
 1880            }
 1881
 1882            // Check allowed tags - item must have at least one allowed tag
 01883            if (!skipAllowedTagsCheck && allowedTags.Length > 0)
 1884            {
 01885                var normalizedAllowedTags = allowedTags
 01886                    .Where(t => !string.IsNullOrWhiteSpace(t))
 01887                    .Select(t => t.GetCleanValue())
 01888                    .ToHashSet(StringComparer.Ordinal);
 1889
 01890                if (!normalizedAllowedTags.Overlaps(normalizedItemTags))
 1891                {
 01892                    return false;
 1893                }
 1894            }
 1895
 01896            return true;
 1897        }
 1898
 1899        public virtual UnratedItem GetBlockUnratedType()
 1900        {
 1171901            if (SourceType == SourceType.Channel)
 1902            {
 01903                return UnratedItem.ChannelContent;
 1904            }
 1905
 1171906            return UnratedItem.Other;
 1907        }
 1908
 1909        /// <summary>
 1910        /// Gets a bool indicating if access to the unrated item is blocked or not.
 1911        /// </summary>
 1912        /// <param name="user">The configuration.</param>
 1913        /// <returns><c>true</c> if blocked, <c>false</c> otherwise.</returns>
 1914        protected virtual bool GetBlockUnratedValue(User user)
 1915        {
 1916            // Don't block plain folders that are unrated. Let the media underneath get blocked
 1917            // Special folders like series and albums will override this method.
 101918            if (IsFolder || this is IItemByName)
 1919            {
 101920                return false;
 1921            }
 1922
 01923            return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(GetBlockUnratedType(
 1924        }
 1925
 1926        /// <summary>
 1927        /// Determines if this folder should be visible to a given user.
 1928        /// Default is just parental allowed. Can be overridden for more functionality.
 1929        /// </summary>
 1930        /// <param name="user">The user.</param>
 1931        /// <param name="skipAllowedTagsCheck">Don't check for allowed tags.</param>
 1932        /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
 1933        /// <exception cref="ArgumentNullException"><paramref name="user" /> is <c>null</c>.</exception>
 1934        public virtual bool IsVisible(User user, bool skipAllowedTagsCheck = false)
 1935        {
 101936            ArgumentNullException.ThrowIfNull(user);
 1937
 101938            return IsParentalAllowed(user, skipAllowedTagsCheck);
 1939        }
 1940
 1941        public virtual bool IsVisibleStandalone(User user)
 1942        {
 01943            if (SourceType == SourceType.Channel)
 1944            {
 01945                return IsVisibleStandaloneInternal(user, false) && Channel.IsChannelVisible(this, user);
 1946            }
 1947
 01948            return IsVisibleStandaloneInternal(user, true);
 1949        }
 1950
 1951        public virtual string GetClientTypeName()
 1952        {
 1211953            if (IsFolder && SourceType == SourceType.Channel && this is not Channel && this is not Season && this is not
 1954            {
 01955                return "ChannelFolderItem";
 1956            }
 1957
 1211958            return GetType().Name;
 1959        }
 1960
 1961        public BaseItemKind GetBaseItemKind()
 1962        {
 2581963            return _baseItemKind ??= Enum.Parse<BaseItemKind>(GetClientTypeName());
 1964        }
 1965
 1966        /// <summary>
 1967        /// Gets the linked child.
 1968        /// </summary>
 1969        /// <param name="info">The info.</param>
 1970        /// <returns>BaseItem.</returns>
 1971        protected BaseItem GetLinkedChild(LinkedChild info)
 1972        {
 1973            // First get using the cached Id
 01974            if (info.ItemId.HasValue)
 1975            {
 01976                if (info.ItemId.Value.IsEmpty())
 1977                {
 01978                    return null;
 1979                }
 1980
 01981                var itemById = LibraryManager.GetItemById(info.ItemId.Value);
 1982
 01983                if (itemById is not null)
 1984                {
 01985                    return itemById;
 1986                }
 1987            }
 1988
 01989            var item = FindLinkedChild(info);
 1990
 1991            // If still null, log
 01992            if (item is null)
 1993            {
 1994                // Don't keep searching over and over
 01995                info.ItemId = Guid.Empty;
 1996            }
 1997            else
 1998            {
 1999                // Cache the id for next time
 02000                info.ItemId = item.Id;
 2001            }
 2002
 02003            return item;
 2004        }
 2005
 2006#pragma warning disable CS0618 // Type or member is obsolete - fallback for legacy LinkedChild data
 2007        private BaseItem FindLinkedChild(LinkedChild info)
 2008        {
 2009            // First try to find by ItemId (new preferred method)
 02010            if (info.ItemId.HasValue && !info.ItemId.Value.Equals(Guid.Empty))
 2011            {
 02012                var item = LibraryManager.GetItemById(info.ItemId.Value);
 02013                if (item is not null)
 2014                {
 02015                    return item;
 2016                }
 2017
 02018                Logger.LogWarning("Unable to find linked item by ItemId {0}", info.ItemId);
 2019            }
 2020
 2021            // Fall back to Path (legacy method)
 02022            var path = info.Path;
 02023            if (!string.IsNullOrEmpty(path))
 2024            {
 02025                path = FileSystem.MakeAbsolutePath(ContainingFolderPath, path);
 2026
 02027                var itemByPath = LibraryManager.FindByPath(path, null);
 2028
 02029                if (itemByPath is null)
 2030                {
 02031                    Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
 2032                }
 2033
 02034                return itemByPath;
 2035            }
 2036
 2037            // Fall back to LibraryItemId (legacy method)
 02038            if (!string.IsNullOrEmpty(info.LibraryItemId))
 2039            {
 02040                var item = LibraryManager.GetItemById(info.LibraryItemId);
 2041
 02042                if (item is null)
 2043                {
 02044                    Logger.LogWarning("Unable to find linked item by LibraryItemId {0}", info.LibraryItemId);
 2045                }
 2046
 02047                return item;
 2048            }
 2049
 02050            return null;
 2051        }
 2052#pragma warning restore CS0618
 2053
 2054        /// <summary>
 2055        /// Adds a studio to the item.
 2056        /// </summary>
 2057        /// <param name="name">The name.</param>
 2058        /// <exception cref="ArgumentNullException">Throws if name is null.</exception>
 2059        public void AddStudio(string name)
 2060        {
 42061            ArgumentException.ThrowIfNullOrEmpty(name);
 42062            var current = Studios;
 2063
 42064            if (!current.Contains(name, StringComparison.OrdinalIgnoreCase))
 2065            {
 42066                int curLen = current.Length;
 42067                if (curLen == 0)
 2068                {
 42069                    Studios = [name];
 2070                }
 2071                else
 2072                {
 02073                    Studios = [.. current, name];
 2074                }
 2075            }
 02076        }
 2077
 2078        public void SetStudios(IEnumerable<string> names)
 2079        {
 52080            Studios = names.Trimmed().Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
 52081        }
 2082
 2083        /// <summary>
 2084        /// Adds a genre to the item.
 2085        /// </summary>
 2086        /// <param name="name">The name.</param>
 2087        /// <exception cref="ArgumentNullException">Throws if name is null.</exception>
 2088        public void AddGenre(string name)
 2089        {
 132090            ArgumentException.ThrowIfNullOrEmpty(name);
 2091
 132092            var genres = Genres;
 132093            if (!genres.Contains(name, StringComparison.OrdinalIgnoreCase))
 2094            {
 132095                Genres = [.. genres, name];
 2096            }
 132097        }
 2098
 2099        /// <summary>
 2100        /// Marks the played.
 2101        /// </summary>
 2102        /// <param name="user">The user.</param>
 2103        /// <param name="datePlayed">The date played.</param>
 2104        /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
 2105        /// <exception cref="ArgumentNullException">Throws if user is null.</exception>
 2106        public virtual void MarkPlayed(
 2107            User user,
 2108            DateTime? datePlayed,
 2109            bool resetPosition)
 2110        {
 02111            ArgumentNullException.ThrowIfNull(user);
 2112
 02113            var data = UserDataManager.GetUserData(user, this) ?? new UserItemData()
 02114            {
 02115                Key = GetUserDataKeys().First(),
 02116            };
 2117
 02118            if (datePlayed.HasValue)
 2119            {
 2120                // Increment
 02121                data.PlayCount++;
 2122            }
 2123
 2124            // Ensure it's at least one
 02125            data.PlayCount = Math.Max(data.PlayCount, 1);
 2126
 02127            if (resetPosition)
 2128            {
 02129                data.PlaybackPositionTicks = 0;
 2130            }
 2131
 02132            data.LastPlayedDate = datePlayed ?? data.LastPlayedDate ?? DateTime.UtcNow;
 02133            data.Played = true;
 2134
 02135            UserDataManager.SaveUserData(user, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None);
 02136        }
 2137
 2138        /// <summary>
 2139        /// Marks the unplayed.
 2140        /// </summary>
 2141        /// <param name="user">The user.</param>
 2142        /// <exception cref="ArgumentNullException">Throws if user is null.</exception>
 2143        public virtual void MarkUnplayed(User user)
 2144        {
 02145            ArgumentNullException.ThrowIfNull(user);
 2146
 02147            var data = UserDataManager.GetUserData(user, this);
 2148
 2149            // I think it is okay to do this here.
 2150            // if this is only called when a user is manually forcing something to un-played
 2151            // then it probably is what we want to do...
 02152            ResetPlayedState(data);
 2153
 02154            UserDataManager.SaveUserData(user, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None);
 02155        }
 2156
 2157        /// <summary>
 2158        /// Clears the played state on the supplied user data.
 2159        /// </summary>
 2160        /// <param name="data">The user data to reset.</param>
 2161        protected static void ResetPlayedState(UserItemData data)
 2162        {
 22163            ArgumentNullException.ThrowIfNull(data);
 2164
 22165            data.PlayCount = 0;
 22166            data.PlaybackPositionTicks = 0;
 22167            data.LastPlayedDate = null;
 22168            data.Played = false;
 22169        }
 2170
 2171        /// <summary>
 2172        /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
 2173        /// </summary>
 2174        public virtual void ChangedExternally()
 2175        {
 02176            ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(new DirectoryService(FileSystem)), RefreshPriori
 02177        }
 2178
 2179        /// <summary>
 2180        /// Gets an image.
 2181        /// </summary>
 2182        /// <param name="type">The type.</param>
 2183        /// <param name="imageIndex">Index of the image.</param>
 2184        /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
 2185        /// <exception cref="ArgumentException">Backdrops should be accessed using Item.Backdrops.</exception>
 2186        public bool HasImage(ImageType type, int imageIndex)
 2187        {
 1482188            return GetImageInfo(type, imageIndex) is not null;
 2189        }
 2190
 2191        public void SetImage(ItemImageInfo image, int index)
 2192        {
 222193            if (image.Type == ImageType.Chapter)
 2194            {
 02195                throw new ArgumentException("Cannot set chapter images using SetImagePath");
 2196            }
 2197
 222198            var existingImage = GetImageInfo(image.Type, index);
 2199
 222200            if (existingImage is null)
 2201            {
 192202                AddImage(image);
 2203            }
 2204            else
 2205            {
 32206                existingImage.Path = image.Path;
 32207                existingImage.DateModified = image.DateModified;
 32208                existingImage.Width = image.Width;
 32209                existingImage.Height = image.Height;
 32210                existingImage.BlurHash = image.BlurHash;
 2211            }
 32212        }
 2213
 2214        public void SetImagePath(ImageType type, int index, FileSystemMetadata file)
 2215        {
 462216            if (type == ImageType.Chapter)
 2217            {
 02218                throw new ArgumentException("Cannot set chapter images using SetImagePath");
 2219            }
 2220
 462221            var image = GetImageInfo(type, index);
 2222
 462223            if (image is null)
 2224            {
 452225                AddImage(GetImageInfo(file, type));
 2226            }
 2227            else
 2228            {
 12229                var imageInfo = GetImageInfo(file, type);
 2230
 12231                image.Path = file.FullName;
 12232                image.DateModified = imageInfo.DateModified;
 2233
 2234                // reset these values
 12235                image.Width = 0;
 12236                image.Height = 0;
 2237            }
 12238        }
 2239
 2240        /// <summary>
 2241        /// Deletes the image.
 2242        /// </summary>
 2243        /// <param name="type">The type.</param>
 2244        /// <param name="index">The index.</param>
 2245        /// <returns>A task.</returns>
 2246        public async Task DeleteImageAsync(ImageType type, int index)
 2247        {
 02248            var info = GetImageInfo(type, index);
 2249
 02250            if (info is null)
 2251            {
 2252                // Nothing to do
 02253                return;
 2254            }
 2255
 2256            // Remove from file system
 02257            var path = info.Path;
 02258            if (info.IsLocalFile && !string.IsNullOrWhiteSpace(path))
 2259            {
 02260                FileSystem.DeleteFile(path);
 2261            }
 2262
 2263            // Remove from item
 02264            RemoveImage(info);
 2265
 02266            await UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
 02267        }
 2268
 2269        public void RemoveImage(ItemImageInfo image)
 2270        {
 02271            RemoveImages([image]);
 02272        }
 2273
 2274        public void RemoveImages(IEnumerable<ItemImageInfo> deletedImages)
 2275        {
 92276            ImageInfos = ImageInfos.Except(deletedImages).ToArray();
 92277        }
 2278
 2279        public void AddImage(ItemImageInfo image)
 2280        {
 642281            ImageInfos = [.. ImageInfos, image];
 642282        }
 2283
 2284        public virtual async Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationTok
 1152285         => await LibraryManager.UpdateItemAsync(this, GetParent(), updateReason, cancellationToken).ConfigureAwait(fals
 2286
 2287        public async Task ReattachUserDataAsync(CancellationToken cancellationToken) =>
 352288            await LibraryManager.ReattachUserDataAsync(this, cancellationToken).ConfigureAwait(false);
 2289
 2290        /// <summary>
 2291        /// Validates that images within the item are still on the filesystem.
 2292        /// </summary>
 2293        /// <returns><c>true</c> if the images validate, <c>false</c> if not.</returns>
 2294        public bool ValidateImages()
 2295        {
 752296            List<ItemImageInfo> deletedImages = null;
 1802297            foreach (var imageInfo in ImageInfos)
 2298            {
 152299                if (!imageInfo.IsLocalFile)
 2300                {
 2301                    continue;
 2302                }
 2303
 152304                if (File.Exists(imageInfo.Path))
 2305                {
 2306                    continue;
 2307                }
 2308
 32309                (deletedImages ??= []).Add(imageInfo);
 2310            }
 2311
 752312            var anyImagesRemoved = deletedImages?.Count > 0;
 752313            if (anyImagesRemoved)
 2314            {
 22315                RemoveImages(deletedImages);
 2316            }
 2317
 752318            return anyImagesRemoved;
 2319        }
 2320
 2321        /// <summary>
 2322        /// Gets the image path.
 2323        /// </summary>
 2324        /// <param name="imageType">Type of the image.</param>
 2325        /// <param name="imageIndex">Index of the image.</param>
 2326        /// <returns>System.String.</returns>
 2327        /// <exception cref="ArgumentNullException">Item is null.</exception>
 2328        public string GetImagePath(ImageType imageType, int imageIndex)
 42329            => GetImageInfo(imageType, imageIndex)?.Path;
 2330
 2331        /// <summary>
 2332        /// Gets the image information.
 2333        /// </summary>
 2334        /// <param name="imageType">Type of the image.</param>
 2335        /// <param name="imageIndex">Index of the image.</param>
 2336        /// <returns>ItemImageInfo.</returns>
 2337        public ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex)
 2338        {
 3292339            if (imageType == ImageType.Chapter)
 2340            {
 02341                var chapter = ChapterManager.GetChapter(Id, imageIndex);
 2342
 02343                if (chapter is null)
 2344                {
 02345                    return null;
 2346                }
 2347
 02348                var path = chapter.ImagePath;
 2349
 02350                if (string.IsNullOrEmpty(path))
 2351                {
 02352                    return null;
 2353                }
 2354
 02355                return new ItemImageInfo
 02356                {
 02357                    Path = path,
 02358                    DateModified = chapter.ImageDateModified,
 02359                    Type = imageType
 02360                };
 2361            }
 2362
 3292363            return GetImages(imageType)
 3292364                .ElementAtOrDefault(imageIndex);
 2365        }
 2366
 2367        /// <summary>
 2368        /// Computes image index for given image or raises if no matching image found.
 2369        /// </summary>
 2370        /// <param name="image">Image to compute index for.</param>
 2371        /// <exception cref="ArgumentException">Image index cannot be computed as no matching image found.
 2372        /// </exception>
 2373        /// <returns>Image index.</returns>
 2374        public int GetImageIndex(ItemImageInfo image)
 2375        {
 02376            ArgumentNullException.ThrowIfNull(image);
 2377
 02378            if (image.Type == ImageType.Chapter)
 2379            {
 02380                var chapters = ChapterManager.GetChapters(Id);
 02381                for (var i = 0; i < chapters.Count; i++)
 2382                {
 02383                    if (chapters[i].ImagePath == image.Path)
 2384                    {
 02385                        return i;
 2386                    }
 2387                }
 2388
 02389                throw new ArgumentException("No chapter index found for image path", image.Path);
 2390            }
 2391
 02392            var images = GetImages(image.Type).ToArray();
 02393            for (var i = 0; i < images.Length; i++)
 2394            {
 02395                if (images[i].Path == image.Path)
 2396                {
 02397                    return i;
 2398                }
 2399            }
 2400
 02401            throw new ArgumentException("No image index found for image path", image.Path);
 2402        }
 2403
 2404        public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
 2405        {
 4392406            if (imageType == ImageType.Chapter)
 2407            {
 02408                throw new ArgumentException("No image info for chapter images");
 2409            }
 2410
 2411            // Yield return is more performant than LINQ Where on an Array
 14342412            for (var i = 0; i < ImageInfos.Length; i++)
 2413            {
 3072414                var imageInfo = ImageInfos[i];
 3072415                if (imageInfo.Type == imageType)
 2416                {
 1612417                    yield return imageInfo;
 2418                }
 2419            }
 4102420        }
 2421
 2422        /// <summary>
 2423        /// Adds the images, updating metadata if they already are part of this item.
 2424        /// </summary>
 2425        /// <param name="imageType">Type of the image.</param>
 2426        /// <param name="images">The images.</param>
 2427        /// <returns><c>true</c> if images were added or updated, <c>false</c> otherwise.</returns>
 2428        /// <exception cref="ArgumentException">Cannot call AddImages with chapter images.</exception>
 2429        public bool AddImages(ImageType imageType, List<FileSystemMetadata> images)
 2430        {
 42431            if (imageType == ImageType.Chapter)
 2432            {
 02433                throw new ArgumentException("Cannot call AddImages with chapter images");
 2434            }
 2435
 42436            var existingImages = GetImages(imageType)
 42437                .ToList();
 2438
 42439            var newImageList = new List<FileSystemMetadata>();
 42440            var imageUpdated = false;
 2441
 242442            foreach (var newImage in images)
 2443            {
 82444                if (newImage is null)
 2445                {
 02446                    throw new ArgumentException("null image found in list");
 2447                }
 2448
 82449                var existing = existingImages
 82450                    .Find(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase));
 2451
 82452                if (existing is null)
 2453                {
 42454                    newImageList.Add(newImage);
 2455                }
 2456                else
 2457                {
 42458                    if (existing.IsLocalFile)
 2459                    {
 42460                        var newDateModified = FileSystem.GetLastWriteTimeUtc(newImage);
 2461
 2462                        // If date changed then we need to reset saved image dimensions
 42463                        if (existing.DateModified != newDateModified && (existing.Width > 0 || existing.Height > 0))
 2464                        {
 22465                            existing.Width = 0;
 22466                            existing.Height = 0;
 22467                            imageUpdated = true;
 2468                        }
 2469
 42470                        existing.DateModified = newDateModified;
 2471                    }
 2472                }
 2473            }
 2474
 42475            if (newImageList.Count > 0)
 2476            {
 22477                ImageInfos = ImageInfos.Concat(newImageList.Select(i => GetImageInfo(i, imageType))).ToArray();
 2478            }
 2479
 42480            return imageUpdated || newImageList.Count > 0;
 2481        }
 2482
 2483        private ItemImageInfo GetImageInfo(FileSystemMetadata file, ImageType type)
 2484        {
 502485            return new ItemImageInfo
 502486            {
 502487                Path = file.FullName,
 502488                Type = type,
 502489                DateModified = FileSystem.GetLastWriteTimeUtc(file)
 502490            };
 2491        }
 2492
 2493        /// <summary>
 2494        /// Gets the file system path to delete when the item is to be deleted.
 2495        /// </summary>
 2496        /// <returns>The metadata for the deleted paths.</returns>
 2497        public virtual IEnumerable<FileSystemMetadata> GetDeletePaths()
 2498        {
 02499            return new[]
 02500            {
 02501                FileSystem.GetFileSystemInfo(Path)
 02502            }.Concat(GetLocalMetadataFilesToDelete());
 2503        }
 2504
 2505        protected List<FileSystemMetadata> GetLocalMetadataFilesToDelete()
 2506        {
 02507            if (IsFolder || !IsInMixedFolder)
 2508            {
 02509                return [];
 2510            }
 2511
 02512            var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
 2513
 02514            return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), _supportedExtensions, false, false)
 02515                .Where(i => System.IO.Path.GetFileNameWithoutExtension(i.FullName).StartsWith(filename, StringComparison
 02516                .ToList();
 2517        }
 2518
 2519        public bool AllowsMultipleImages(ImageType type)
 2520        {
 232521            return type == ImageType.Backdrop || type == ImageType.Chapter;
 2522        }
 2523
 2524        public Task SwapImagesAsync(ImageType type, int index1, int index2)
 2525        {
 02526            if (!AllowsMultipleImages(type))
 2527            {
 02528                throw new ArgumentException("The change index operation is only applicable to backdrops and screen shots
 2529            }
 2530
 02531            var info1 = GetImageInfo(type, index1);
 02532            var info2 = GetImageInfo(type, index2);
 2533
 02534            if (info1 is null || info2 is null)
 2535            {
 2536                // Nothing to do
 02537                return Task.CompletedTask;
 2538            }
 2539
 02540            if (!info1.IsLocalFile || !info2.IsLocalFile)
 2541            {
 2542                // TODO: Not supported  yet
 02543                return Task.CompletedTask;
 2544            }
 2545
 02546            var path1 = info1.Path;
 02547            var path2 = info2.Path;
 2548
 02549            FileSystem.SwapFiles(path1, path2);
 2550
 2551            // Refresh these values
 02552            info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
 02553            info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
 2554
 02555            info1.Width = 0;
 02556            info1.Height = 0;
 02557            info2.Width = 0;
 02558            info2.Height = 0;
 2559
 02560            return UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None);
 2561        }
 2562
 2563        public virtual bool IsPlayed(User user, UserItemData userItemData)
 2564        {
 02565            userItemData ??= UserDataManager.GetUserData(user, this);
 2566
 02567            return userItemData is not null && userItemData.Played;
 2568        }
 2569
 2570        public bool IsFavoriteOrLiked(User user, UserItemData userItemData)
 2571        {
 02572            userItemData ??= UserDataManager.GetUserData(user, this);
 2573
 02574            return userItemData is not null && (userItemData.IsFavorite || (userItemData.Likes ?? false));
 2575        }
 2576
 2577        public virtual bool IsUnplayed(User user, UserItemData userItemData)
 2578        {
 02579            ArgumentNullException.ThrowIfNull(user);
 2580
 02581            userItemData ??= UserDataManager.GetUserData(user, this);
 2582
 02583            return userItemData is null || !userItemData.Played;
 2584        }
 2585
 2586        ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
 2587        {
 362588            return GetItemLookupInfo<ItemLookupInfo>();
 2589        }
 2590
 2591        protected T GetItemLookupInfo<T>()
 2592            where T : ItemLookupInfo, new()
 2593        {
 362594            return new T
 362595            {
 362596                Path = Path,
 362597                MetadataCountryCode = GetPreferredMetadataCountryCode(),
 362598                MetadataLanguage = GetPreferredMetadataLanguage(),
 362599                Name = GetNameForMetadataLookup(),
 362600                OriginalTitle = OriginalTitle,
 362601                ProviderIds = ProviderIds,
 362602                IndexNumber = IndexNumber,
 362603                ParentIndexNumber = ParentIndexNumber,
 362604                Year = ProductionYear,
 362605                PremiereDate = PremiereDate
 362606            };
 2607        }
 2608
 2609        protected virtual string GetNameForMetadataLookup()
 2610        {
 362611            return Name;
 2612        }
 2613
 2614        /// <summary>
 2615        /// This is called before any metadata refresh and returns true if changes were made.
 2616        /// </summary>
 2617        /// <param name="replaceAllMetadata">Whether to replace all metadata.</param>
 2618        /// <returns>true if the item has change, else false.</returns>
 2619        public virtual bool BeforeMetadataRefresh(bool replaceAllMetadata)
 2620        {
 362621            _sortName = null;
 2622
 362623            var hasChanges = false;
 2624
 362625            if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Path))
 2626            {
 02627                Name = System.IO.Path.GetFileNameWithoutExtension(Path);
 02628                hasChanges = true;
 2629            }
 2630
 362631            return hasChanges;
 2632        }
 2633
 2634        protected static string GetMappedPath(BaseItem item, string path, MediaProtocol? protocol)
 2635        {
 02636            if (protocol == MediaProtocol.File)
 2637            {
 02638                return LibraryManager.GetPathAfterNetworkSubstitution(path, item);
 2639            }
 2640
 02641            return path;
 2642        }
 2643
 2644        public virtual void FillUserDataDtoValues(
 2645            UserItemDataDto dto,
 2646            UserItemData userData,
 2647            BaseItemDto itemDto,
 2648            User user,
 2649            DtoOptions fields,
 2650            (int Played, int Total)? precomputedCounts = null)
 2651        {
 02652            if (RunTimeTicks.HasValue)
 2653            {
 02654                double pct = RunTimeTicks.Value;
 2655
 02656                if (pct > 0)
 2657                {
 02658                    pct = userData.PlaybackPositionTicks / pct;
 2659
 02660                    if (pct > 0)
 2661                    {
 02662                        dto.PlayedPercentage = 100 * pct;
 2663                    }
 2664                }
 2665            }
 02666        }
 2667
 2668        /// <summary>
 2669        /// Applies the owner's premiere date and production year to an owned item, returning whether anything changed.
 2670        /// </summary>
 2671        /// <param name="owner">The owner.</param>
 2672        /// <param name="ownedItem">The owned item.</param>
 2673        /// <returns><c>true</c> if the owned item was changed, else <c>false</c>.</returns>
 2674        internal static bool InheritDatesFromOwner(BaseItem owner, BaseItem ownedItem)
 2675        {
 2676            // Extras have no release date of their own, so the owner's is authoritative.
 42677            var changed = false;
 2678
 42679            if (owner.ProductionYear is not null && ownedItem.ProductionYear != owner.ProductionYear)
 2680            {
 22681                ownedItem.ProductionYear = owner.ProductionYear;
 22682                changed = true;
 2683            }
 2684
 42685            if (owner.PremiereDate is not null && ownedItem.PremiereDate != owner.PremiereDate)
 2686            {
 22687                ownedItem.PremiereDate = owner.PremiereDate;
 22688                changed = true;
 2689            }
 2690
 42691            return changed;
 2692        }
 2693
 2694        protected async Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOpti
 2695        {
 02696            var newOptions = new MetadataRefreshOptions(options)
 02697            {
 02698                SearchResult = null
 02699            };
 2700
 02701            var item = this;
 2702
 02703            if (copyTitleMetadata)
 2704            {
 2705                // Take some data from the main item, for querying purposes
 02706                if (!item.Genres.SequenceEqual(ownedItem.Genres, StringComparer.Ordinal))
 2707                {
 02708                    newOptions.ForceSave = true;
 02709                    ownedItem.Genres = item.Genres;
 2710                }
 2711
 02712                if (!item.Studios.SequenceEqual(ownedItem.Studios, StringComparer.Ordinal))
 2713                {
 02714                    newOptions.ForceSave = true;
 02715                    ownedItem.Studios = item.Studios;
 2716                }
 2717
 02718                if (!item.ProductionLocations.SequenceEqual(ownedItem.ProductionLocations, StringComparer.Ordinal))
 2719                {
 02720                    newOptions.ForceSave = true;
 02721                    ownedItem.ProductionLocations = item.ProductionLocations;
 2722                }
 2723
 02724                if (item.CommunityRating != ownedItem.CommunityRating)
 2725                {
 02726                    ownedItem.CommunityRating = item.CommunityRating;
 02727                    newOptions.ForceSave = true;
 2728                }
 2729
 02730                if (item.CriticRating != ownedItem.CriticRating)
 2731                {
 02732                    ownedItem.CriticRating = item.CriticRating;
 02733                    newOptions.ForceSave = true;
 2734                }
 2735
 02736                if (!string.Equals(item.Overview, ownedItem.Overview, StringComparison.Ordinal))
 2737                {
 02738                    ownedItem.Overview = item.Overview;
 02739                    newOptions.ForceSave = true;
 2740                }
 2741
 02742                if (!string.Equals(item.OfficialRating, ownedItem.OfficialRating, StringComparison.Ordinal))
 2743                {
 02744                    ownedItem.OfficialRating = item.OfficialRating;
 02745                    newOptions.ForceSave = true;
 2746                }
 2747
 02748                if (!string.Equals(item.CustomRating, ownedItem.CustomRating, StringComparison.Ordinal))
 2749                {
 02750                    ownedItem.CustomRating = item.CustomRating;
 02751                    newOptions.ForceSave = true;
 2752                }
 2753
 02754                if (InheritDatesFromOwner(item, ownedItem))
 2755                {
 02756                    newOptions.ForceSave = true;
 2757                }
 2758            }
 2759
 02760            await ownedItem.RefreshMetadata(newOptions, cancellationToken).ConfigureAwait(false);
 02761        }
 2762
 2763        protected async Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, bool copyTitleMetadata, string
 2764        {
 02765            var newOptions = new MetadataRefreshOptions(options)
 02766            {
 02767                SearchResult = null
 02768            };
 2769
 02770            var id = LibraryManager.GetNewItemId(path, typeof(Video));
 2771
 2772            // Try to retrieve it from the db. If we don't find it, use the resolved version
 02773            if (LibraryManager.GetItemById(id) is not Video video)
 2774            {
 02775                video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video;
 2776
 02777                newOptions.ForceSave = true;
 2778            }
 2779
 02780            if (video is null)
 2781            {
 02782                return;
 2783            }
 2784
 02785            if (video.OwnerId.IsEmpty())
 2786            {
 02787                video.OwnerId = Id;
 2788            }
 2789
 02790            await RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken).ConfigureAwait(fa
 02791        }
 2792
 2793        public string GetEtag(User user)
 2794        {
 62795            var list = GetEtagValues(user);
 2796
 62797            return string.Join('|', list).GetMD5().ToString("N", CultureInfo.InvariantCulture);
 2798        }
 2799
 2800        protected virtual List<string> GetEtagValues(User user)
 2801        {
 62802            return
 62803            [
 62804                DateLastSaved.Ticks.ToString(CultureInfo.InvariantCulture)
 62805            ];
 2806        }
 2807
 2808        public virtual IEnumerable<Guid> GetAncestorIds()
 2809        {
 1172810            return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
 2811        }
 2812
 2813        public BaseItem GetTopParent()
 2814        {
 2012815            if (IsTopParent)
 2816            {
 222817                return this;
 2818            }
 2819
 1792820            return GetParents().FirstOrDefault(parent => parent.IsTopParent);
 2821        }
 2822
 2823        public virtual IEnumerable<Guid> GetIdsForAncestorQuery()
 2824        {
 452825            return [Id];
 2826        }
 2827
 2828        public virtual double? GetRefreshProgress()
 2829        {
 02830            return null;
 2831        }
 2832
 2833        public virtual ItemUpdateType OnMetadataChanged()
 2834        {
 1222835            var updateType = ItemUpdateType.None;
 2836
 1222837            var item = this;
 2838
 1222839            var rating = item.GetParentalRatingScore();
 1222840            if (rating is not null)
 2841            {
 02842                if (rating.Score != item.InheritedParentalRatingValue)
 2843                {
 02844                    item.InheritedParentalRatingValue = rating.Score;
 02845                    updateType |= ItemUpdateType.MetadataImport;
 2846                }
 2847
 02848                if (rating.SubScore != item.InheritedParentalRatingSubValue)
 2849                {
 02850                    item.InheritedParentalRatingSubValue = rating.SubScore;
 02851                    updateType |= ItemUpdateType.MetadataImport;
 2852                }
 2853            }
 2854            else
 2855            {
 1222856                if (item.InheritedParentalRatingValue is not null)
 2857                {
 02858                    item.InheritedParentalRatingValue = null;
 02859                    item.InheritedParentalRatingSubValue = null;
 02860                    updateType |= ItemUpdateType.MetadataImport;
 2861                }
 2862            }
 2863
 1222864            return updateType;
 2865        }
 2866
 2867        /// <summary>
 2868        /// Updates the official rating based on content and returns true or false indicating if it changed.
 2869        /// </summary>
 2870        /// <param name="children">Media children.</param>
 2871        /// <returns><c>true</c> if the rating was updated; otherwise <c>false</c>.</returns>
 2872        public bool UpdateRatingToItems(IReadOnlyList<BaseItem> children)
 2873        {
 02874            var currentOfficialRating = OfficialRating;
 2875
 2876            // Gather all possible ratings
 02877            var ratings = children
 02878                .Select(i => i.OfficialRating)
 02879                .Where(i => !string.IsNullOrEmpty(i))
 02880                .Distinct(StringComparer.OrdinalIgnoreCase)
 02881                .Select(rating => (rating, LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode())
 02882                .OrderBy(i => i.Item2 is null ? 1001 : i.Item2.Score)
 02883                .ThenBy(i => i.Item2 is null ? 1001 : i.Item2.SubScore)
 02884                .Select(i => i.rating);
 2885
 02886            OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
 2887
 02888            return !string.Equals(
 02889                currentOfficialRating ?? string.Empty,
 02890                OfficialRating ?? string.Empty,
 02891                StringComparison.OrdinalIgnoreCase);
 2892        }
 2893
 2894        public IReadOnlyList<BaseItem> GetThemeSongs(User user = null)
 2895        {
 02896            return GetThemeSongs(user, Array.Empty<(ItemSortBy, SortOrder)>());
 2897        }
 2898
 2899        public IReadOnlyList<BaseItem> GetThemeSongs(User user, IEnumerable<(ItemSortBy SortBy, SortOrder SortOrder)> or
 2900        {
 02901            return LibraryManager.Sort(GetExtras(user).Where(e => e.ExtraType == Model.Entities.ExtraType.ThemeSong), us
 2902        }
 2903
 2904        public IReadOnlyList<BaseItem> GetThemeVideos(User user = null)
 2905        {
 02906            return GetThemeVideos(user, Array.Empty<(ItemSortBy, SortOrder)>());
 2907        }
 2908
 2909        public IReadOnlyList<BaseItem> GetThemeVideos(User user, IEnumerable<(ItemSortBy SortBy, SortOrder SortOrder)> o
 2910        {
 02911            return LibraryManager.Sort(GetExtras(user).Where(e => e.ExtraType == Model.Entities.ExtraType.ThemeVideo), u
 2912        }
 2913
 2914        /// <summary>
 2915        /// Gets the ids of the items whose owned extras belong to this item.
 2916        /// </summary>
 2917        /// <returns>An array containing the owner ids.</returns>
 2918        protected virtual Guid[] GetExtraOwnerIds()
 2919        {
 62920            return [Id];
 2921        }
 2922
 2923        /// <summary>
 2924        /// Get all extras associated with this item, sorted by <see cref="SortName"/>.
 2925        /// </summary>
 2926        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 2927        /// <returns>An enumerable containing the items.</returns>
 2928        public IEnumerable<BaseItem> GetExtras(User user = null)
 2929        {
 62930            return LibraryManager.GetItemList(new InternalItemsQuery(user)
 62931            {
 62932                OwnerIds = GetExtraOwnerIds(),
 62933                OrderBy = [(ItemSortBy.SortName, SortOrder.Ascending)]
 62934            });
 2935        }
 2936
 2937        /// <summary>
 2938        /// Get all extras with specific types that are associated with this item.
 2939        /// </summary>
 2940        /// <param name="extraTypes">The types of extras to retrieve.</param>
 2941        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 2942        /// <returns>An enumerable containing the extras.</returns>
 2943        public IEnumerable<BaseItem> GetExtras(IReadOnlyCollection<ExtraType> extraTypes, User user = null)
 2944        {
 02945            return LibraryManager.GetItemList(new InternalItemsQuery(user)
 02946            {
 02947                OwnerIds = GetExtraOwnerIds(),
 02948                ExtraTypes = extraTypes.ToArray(),
 02949                OrderBy = [(ItemSortBy.SortName, SortOrder.Ascending)]
 02950            });
 2951        }
 2952
 2953        public virtual long GetRunTimeTicksForPlayState()
 2954        {
 02955            return RunTimeTicks ?? 0;
 2956        }
 2957
 2958        /// <inheritdoc />
 2959        public override bool Equals(object obj)
 2960        {
 982961            return obj is BaseItem baseItem && this.Equals(baseItem);
 2962        }
 2963
 2964        /// <inheritdoc />
 2572965        public bool Equals(BaseItem other) => other is not null && other.Id.Equals(Id);
 2966
 2967        /// <inheritdoc />
 1022968        public override int GetHashCode() => HashCode.Combine(Id);
 2969    }
 2970}

Methods/Properties

.cctor()
.ctor()
get_SupportsAddingToPlaylist()
get_AlwaysScanInternalMetadataPath()
get_SupportsPlayedStatus()
get_SupportsPositionTicksResume()
get_SupportsRemoteImageDownloading()
get_Name()
set_Name(System.String)
get_IsUnaired()
get_IsThemeMedia()
get_OriginalLanguage()
set_OriginalLanguage(System.String)
get_DisplayPreferencesId()
get_SourceType()
get_ContainingFolderPath()
get_IsHidden()
get_LocationType()
get_PathProtocol()
get_IsFileProtocol()
get_HasPathProtocol()
get_SupportsLocalMetadata()
get_FileNameWithoutExtension()
get_EnableAlphaNumericSorting()
get_IsHD()
get_PrimaryImagePath()
get_MediaType()
get_PhysicalLocations()
get_EnableMediaSourceDisplay()
get_ForcedSortName()
set_ForcedSortName(System.String)
get_SortName()
set_SortName(System.String)
get_DisplayParentId()
get_DisplayParent()
get_HasLocalAlternateVersions()
get_OfficialRatingForComparison()
get_CustomRatingForComparison()
get_LatestItemsIndexContainer()
get_EnableRememberingTrackSelections()
get_IsTopParent()
get_SupportsAncestors()
get_SupportsOwnedItems()
get_SupportsPeople()
get_SupportsThemeMedia()
get_SupportsInheritedParentImages()
get_IsFolder()
get_IsDisplayedAsFolder()
GetCustomRatingForComparision(System.Collections.Generic.HashSet`1<System.Guid>)
GetDefaultPrimaryImageAspectRatio()
CreatePresentationUniqueKey()
CanDelete()
IsAuthorizedToDelete(Jellyfin.Database.Implementations.Entities.User,System.Collections.Generic.List`1<MediaBrowser.Controller.Entities.Folder>)
GetOwner()
CanDelete(Jellyfin.Database.Implementations.Entities.User,System.Collections.Generic.List`1<MediaBrowser.Controller.Entities.Folder>)
CanDelete(Jellyfin.Database.Implementations.Entities.User)
CanDownload()
IsAuthorizedToDownload(Jellyfin.Database.Implementations.Entities.User)
CanDownload(Jellyfin.Database.Implementations.Entities.User)
ToString()
GetInternalMetadataPath()
GetInternalMetadataPath(System.String)
CreateSortName()
GetSortName(System.String,System.Boolean,MediaBrowser.Model.Configuration.ServerConfiguration)
ModifySortChunks(System.ReadOnlySpan`1<System.Char>)
GetParent()
GetParents()
FindParent()
GetPlayAccess(Jellyfin.Database.Implementations.Entities.User)
GetMediaStreams()
IsActiveRecording()
GetMediaSources(System.Boolean)
GetAllItemsForMediaSources()
GetVersionInfo(System.Boolean,MediaBrowser.Controller.Entities.BaseItem,MediaBrowser.Model.Dto.MediaSourceType,System.String)
GetMediaSourceName(MediaBrowser.Controller.Entities.BaseItem,System.String)
GetCommonNamePrefix(System.Collections.Generic.IReadOnlyList`1<System.ValueTuple`2<MediaBrowser.Controller.Entities.BaseItem,MediaBrowser.Model.Dto.MediaSourceType>>)
GetCommonVersionPrefix(System.Collections.Generic.IReadOnlyList`1<System.String>)
RefreshMetadata(System.Threading.CancellationToken)
RefreshMetadata()
IsVisibleStandaloneInternal(Jellyfin.Database.Implementations.Entities.User,System.Boolean)
SetParent(MediaBrowser.Controller.Entities.Folder)
RefreshedOwnedItems()
GetFileSystemChildren(MediaBrowser.Controller.Providers.IDirectoryService)
RefreshExtras()
GetPresentationUniqueKey()
RequiresRefresh()
GetUserDataKeys()
UpdateFromResolvedItem(MediaBrowser.Controller.Entities.BaseItem)
AfterMetadataRefresh()
GetPreferredMetadataLanguage()
GetPreferredMetadataCountryCode()
GetInheritedOriginalLanguage()
IsSaveLocalMetadataEnabled()
IsParentalAllowed(Jellyfin.Database.Implementations.Entities.User,System.Boolean)
GetParentalRatingScore()
GetInheritedTags()
IsVisibleViaTags(Jellyfin.Database.Implementations.Entities.User,System.Boolean)
GetBlockUnratedType()
GetBlockUnratedValue(Jellyfin.Database.Implementations.Entities.User)
IsVisible(Jellyfin.Database.Implementations.Entities.User,System.Boolean)
IsVisibleStandalone(Jellyfin.Database.Implementations.Entities.User)
GetClientTypeName()
GetBaseItemKind()
GetLinkedChild(MediaBrowser.Controller.Entities.LinkedChild)
FindLinkedChild(MediaBrowser.Controller.Entities.LinkedChild)
AddStudio(System.String)
SetStudios(System.Collections.Generic.IEnumerable`1<System.String>)
AddGenre(System.String)
MarkPlayed(Jellyfin.Database.Implementations.Entities.User,System.Nullable`1<System.DateTime>,System.Boolean)
MarkUnplayed(Jellyfin.Database.Implementations.Entities.User)
ResetPlayedState(MediaBrowser.Controller.Entities.UserItemData)
ChangedExternally()
HasImage(MediaBrowser.Model.Entities.ImageType,System.Int32)
SetImage(MediaBrowser.Controller.Entities.ItemImageInfo,System.Int32)
SetImagePath(MediaBrowser.Model.Entities.ImageType,System.Int32,MediaBrowser.Model.IO.FileSystemMetadata)
DeleteImageAsync()
RemoveImage(MediaBrowser.Controller.Entities.ItemImageInfo)
RemoveImages(System.Collections.Generic.IEnumerable`1<MediaBrowser.Controller.Entities.ItemImageInfo>)
AddImage(MediaBrowser.Controller.Entities.ItemImageInfo)
UpdateToRepositoryAsync()
ReattachUserDataAsync()
ValidateImages()
GetImagePath(MediaBrowser.Model.Entities.ImageType,System.Int32)
GetImageInfo(MediaBrowser.Model.Entities.ImageType,System.Int32)
GetImageIndex(MediaBrowser.Controller.Entities.ItemImageInfo)
GetImages()
AddImages(MediaBrowser.Model.Entities.ImageType,System.Collections.Generic.List`1<MediaBrowser.Model.IO.FileSystemMetadata>)
GetImageInfo(MediaBrowser.Model.IO.FileSystemMetadata,MediaBrowser.Model.Entities.ImageType)
GetDeletePaths()
GetLocalMetadataFilesToDelete()
AllowsMultipleImages(MediaBrowser.Model.Entities.ImageType)
SwapImagesAsync(MediaBrowser.Model.Entities.ImageType,System.Int32,System.Int32)
IsPlayed(Jellyfin.Database.Implementations.Entities.User,MediaBrowser.Controller.Entities.UserItemData)
IsFavoriteOrLiked(Jellyfin.Database.Implementations.Entities.User,MediaBrowser.Controller.Entities.UserItemData)
IsUnplayed(Jellyfin.Database.Implementations.Entities.User,MediaBrowser.Controller.Entities.UserItemData)
MediaBrowser.Controller.Providers.IHasLookupInfo<MediaBrowser.Controller.Providers.ItemLookupInfo>.GetLookupInfo()
GetItemLookupInfo()
GetNameForMetadataLookup()
BeforeMetadataRefresh(System.Boolean)
GetMappedPath(MediaBrowser.Controller.Entities.BaseItem,System.String,System.Nullable`1<MediaBrowser.Model.MediaInfo.MediaProtocol>)
FillUserDataDtoValues(MediaBrowser.Model.Dto.UserItemDataDto,MediaBrowser.Controller.Entities.UserItemData,MediaBrowser.Model.Dto.BaseItemDto,Jellyfin.Database.Implementations.Entities.User,MediaBrowser.Controller.Dto.DtoOptions,System.Nullable`1<System.ValueTuple`2<System.Int32,System.Int32>>)
InheritDatesFromOwner(MediaBrowser.Controller.Entities.BaseItem,MediaBrowser.Controller.Entities.BaseItem)
RefreshMetadataForOwnedItem()
RefreshMetadataForOwnedVideo()
GetEtag(Jellyfin.Database.Implementations.Entities.User)
GetEtagValues(Jellyfin.Database.Implementations.Entities.User)
GetAncestorIds()
GetTopParent()
GetIdsForAncestorQuery()
GetRefreshProgress()
OnMetadataChanged()
UpdateRatingToItems(System.Collections.Generic.IReadOnlyList`1<MediaBrowser.Controller.Entities.BaseItem>)
GetThemeSongs(Jellyfin.Database.Implementations.Entities.User)
GetThemeSongs(Jellyfin.Database.Implementations.Entities.User,System.Collections.Generic.IEnumerable`1<System.ValueTuple`2<Jellyfin.Data.Enums.ItemSortBy,Jellyfin.Database.Implementations.Enums.SortOrder>>)
GetThemeVideos(Jellyfin.Database.Implementations.Entities.User)
GetThemeVideos(Jellyfin.Database.Implementations.Entities.User,System.Collections.Generic.IEnumerable`1<System.ValueTuple`2<Jellyfin.Data.Enums.ItemSortBy,Jellyfin.Database.Implementations.Enums.SortOrder>>)
GetExtraOwnerIds()
GetExtras(Jellyfin.Database.Implementations.Entities.User)
GetExtras(System.Collections.Generic.IReadOnlyCollection`1<MediaBrowser.Model.Entities.ExtraType>,Jellyfin.Database.Implementations.Entities.User)
GetRunTimeTicksForPlayState()
Equals(System.Object)
Equals(MediaBrowser.Controller.Entities.BaseItem)
GetHashCode()