< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.BaseItem
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/BaseItem.cs
Line coverage
54%
Covered lines: 519
Uncovered lines: 433
Coverable lines: 952
Total lines: 3002
Line coverage: 54.5%
Branch coverage
41%
Covered branches: 258
Total branches: 618
Branch coverage: 41.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 4/27/2026 - 12:15:04 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: 29708/3/2026 - 12:16:46 AM Line coverage: 54.5% (519/952) Branch coverage: 41.7% (258/618) Total lines: 3002 4/27/2026 - 12:15:04 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: 29708/3/2026 - 12:16:46 AM Line coverage: 54.5% (519/952) Branch coverage: 41.7% (258/618) Total lines: 3002

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%506220%
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%
GetOwnedVersionIds()100%210%
GetOwnerIdForExtra(...)100%210%
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 protected 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        {
 1319105            Tags = Array.Empty<string>();
 1319106            Genres = Array.Empty<string>();
 1319107            Studios = Array.Empty<string>();
 1319108            ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 1319109            LockedFields = Array.Empty<MetadataField>();
 1319110            ImageInfos = Array.Empty<ItemImageInfo>();
 1319111            ProductionLocations = Array.Empty<string>();
 1319112            RemoteTrailers = Array.Empty<MediaUrl>();
 1319113            UserData = [];
 1319114        }
 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        {
 1033198            get => _name;
 199            set
 200            {
 503201                _name = value;
 202
 203                // lazy load this again
 503204                _sortName = null;
 503205            }
 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;
 233227            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            {
 2393274                if (!ChannelId.IsEmpty())
 275                {
 0276                    return SourceType.Channel;
 277                }
 278
 2393279                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            {
 485292                if (IsFolder)
 293                {
 414294                    return Path;
 295                }
 296
 71297                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            {
 2657352                var path = Path;
 353
 2657354                if (string.IsNullOrEmpty(path))
 355                {
 116356                    return null;
 357                }
 358
 2541359                return MediaSourceManager.GetPathProtocol(path);
 360            }
 361        }
 362
 363        [JsonIgnore]
 2618364        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        {
 502523            get => _forcedSortName;
 524            set
 525            {
 98526                _forcedSortName = value;
 98527                _sortName = null;
 98528            }
 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
 134556            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]
 104788        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        {
 666868            var ownerId = OwnerId;
 666869            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        {
 21571031            var parentId = ParentId;
 21571032            if (parentId.IsEmpty())
 1033            {
 18631034                return null;
 1035            }
 1036
 2941037            return LibraryManager.GetItemById(parentId);
 1038        }
 1039
 1040        public IEnumerable<BaseItem> GetParents()
 1041        {
 7241042            var parent = GetParent();
 1043
 7971044            while (parent is not null)
 1045            {
 731046                yield return parent;
 1047
 731048                parent = parent.GetParent();
 1049            }
 7241050        }
 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        {
 1546            // An extra is owned by the version it is named after, so all of them are maintained together.
 01547            var currentExtras = LibraryManager.GetItemList(new InternalItemsQuery()
 01548            {
 01549                OwnerIds = item.GetOwnedVersionIds()
 01550            }).Where(e => e.ExtraType.HasValue).ToList();
 1551
 01552            var currentExtraIds = currentExtras.Select(e => e.Id).ToArray();
 1553
 1554            // Snapshot the persisted names before resolving, as FindExtras corrects the name on the
 1555            // items it hands back and may well hand back these very instances.
 01556            var currentExtraNames = new Dictionary<Guid, string>();
 01557            foreach (var extra in currentExtras)
 1558            {
 01559                currentExtraNames[extra.Id] = extra.Name;
 1560            }
 1561
 01562            var extras = LibraryManager.FindExtras(item, fileSystemChildren, options.DirectoryService).ToArray();
 01563            var newExtraIds = Array.ConvertAll(extras, x => x.Id);
 1564
 01565            var renamedExtraIds = extras
 01566                .Where(e => currentExtraNames.TryGetValue(e.Id, out var oldName) && !string.Equals(oldName, e.Name, Stri
 01567                .Select(e => e.Id)
 01568                .ToHashSet();
 1569
 01570            var extrasChanged = !currentExtraIds.OrderBy(x => x).SequenceEqual(newExtraIds.OrderBy(x => x));
 1571
 01572            if (!extrasChanged && renamedExtraIds.Count == 0 && !options.ReplaceAllMetadata && options.MetadataRefreshMo
 1573            {
 1574                // The owner's dates may only have become known after its extras were created, so keep
 1575                // them in sync even when there is nothing to refresh.
 01576                foreach (var extra in currentExtras)
 1577                {
 01578                    if (extra.ExtraType is not null && InheritDatesFromOwner(item, extra))
 1579                    {
 01580                        await extra.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwa
 1581                    }
 1582                }
 1583
 01584                return false;
 1585            }
 1586
 01587            var tasks = extras.Select(i =>
 01588            {
 01589                var ownerId = item.GetOwnerIdForExtra(i);
 01590                var subOptions = new MetadataRefreshOptions(options);
 01591                if (!i.OwnerId.Equals(ownerId) || !i.ParentId.IsEmpty() || renamedExtraIds.Contains(i.Id))
 01592                {
 01593                    subOptions.ForceSave = true;
 01594                }
 01595
 01596                i.OwnerId = ownerId;
 01597                i.ParentId = Guid.Empty;
 01598
 01599                return RefreshMetadataForOwnedItem(i, true, subOptions, cancellationToken);
 01600            });
 1601
 01602            var removedExtraIds = currentExtraIds.Where(e => !newExtraIds.Contains(e)).ToArray();
 01603            if (removedExtraIds.Length > 0)
 1604            {
 01605                var removedExtras = LibraryManager.GetItemList(new InternalItemsQuery()
 01606                {
 01607                    ItemIds = removedExtraIds
 01608                });
 01609                foreach (var removedExtra in removedExtras)
 1610                {
 1611                    // Only delete items that are actual extras (have ExtraType set)
 1612                    // Items with OwnerId but no ExtraType might be alternate versions, not extras
 01613                    if (removedExtra.ExtraType.HasValue)
 1614                    {
 01615                        LibraryManager.DeleteItem(removedExtra, new DeleteOptions()
 01616                        {
 01617                            DeleteFileLocation = false
 01618                        });
 1619                    }
 1620                }
 1621            }
 1622
 01623            await Task.WhenAll(tasks).ConfigureAwait(false);
 1624
 01625            return true;
 01626        }
 1627
 1628        public string GetPresentationUniqueKey()
 1629        {
 01630            return PresentationUniqueKey ?? CreatePresentationUniqueKey();
 1631        }
 1632
 1633        public virtual bool RequiresRefresh()
 1634        {
 611635            if (string.IsNullOrEmpty(Path) || DateModified == DateTime.MinValue)
 1636            {
 611637                return false;
 1638            }
 1639
 01640            var info = FileSystem.GetFileSystemInfo(Path);
 1641
 01642            return info.Exists && this.HasChanged(info.LastWriteTimeUtc);
 1643        }
 1644
 1645        public virtual List<string> GetUserDataKeys()
 1646        {
 1731647            var list = new List<string>();
 1648
 1731649            if (SourceType == SourceType.Channel)
 1650            {
 01651                if (!string.IsNullOrEmpty(ExternalId))
 1652                {
 01653                    list.Add(ExternalId);
 1654                }
 1655            }
 1656
 1731657            list.Add(Id.ToString());
 1731658            return list;
 1659        }
 1660
 1661        internal virtual ItemUpdateType UpdateFromResolvedItem(BaseItem newItem)
 1662        {
 51663            var updateType = ItemUpdateType.None;
 1664
 51665            if (IsInMixedFolder != newItem.IsInMixedFolder)
 1666            {
 01667                IsInMixedFolder = newItem.IsInMixedFolder;
 01668                updateType |= ItemUpdateType.MetadataImport;
 1669            }
 1670
 51671            return updateType;
 1672        }
 1673
 1674        public void AfterMetadataRefresh()
 1675        {
 601676            _sortName = null;
 601677        }
 1678
 1679        /// <summary>
 1680        /// Gets the preferred metadata language.
 1681        /// </summary>
 1682        /// <returns>System.String.</returns>
 1683        public string GetPreferredMetadataLanguage()
 1684        {
 361685            string lang = PreferredMetadataLanguage;
 1686
 361687            if (string.IsNullOrEmpty(lang))
 1688            {
 361689                lang = GetParents()
 361690                    .Select(i => i.PreferredMetadataLanguage)
 361691                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1692            }
 1693
 361694            if (string.IsNullOrEmpty(lang))
 1695            {
 361696                lang = LibraryManager.GetCollectionFolders(this)
 361697                    .Select(i => i.PreferredMetadataLanguage)
 361698                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1699            }
 1700
 361701            if (string.IsNullOrEmpty(lang))
 1702            {
 361703                lang = LibraryManager.GetLibraryOptions(this).PreferredMetadataLanguage;
 1704            }
 1705
 361706            if (string.IsNullOrEmpty(lang))
 1707            {
 361708                lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
 1709            }
 1710
 361711            return lang;
 1712        }
 1713
 1714        /// <summary>
 1715        /// Gets the preferred metadata country code.
 1716        /// </summary>
 1717        /// <returns>System.String.</returns>
 1718        public string GetPreferredMetadataCountryCode()
 1719        {
 361720            string lang = PreferredMetadataCountryCode;
 1721
 361722            if (string.IsNullOrEmpty(lang))
 1723            {
 361724                lang = GetParents()
 361725                    .Select(i => i.PreferredMetadataCountryCode)
 361726                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1727            }
 1728
 361729            if (string.IsNullOrEmpty(lang))
 1730            {
 361731                lang = LibraryManager.GetCollectionFolders(this)
 361732                    .Select(i => i.PreferredMetadataCountryCode)
 361733                    .FirstOrDefault(i => !string.IsNullOrEmpty(i));
 1734            }
 1735
 361736            if (string.IsNullOrEmpty(lang))
 1737            {
 361738                lang = LibraryManager.GetLibraryOptions(this).MetadataCountryCode;
 1739            }
 1740
 361741            if (string.IsNullOrEmpty(lang))
 1742            {
 361743                lang = ConfigurationManager.Configuration.MetadataCountryCode;
 1744            }
 1745
 361746            return lang;
 1747        }
 1748
 1749        /// <summary>
 1750        /// Gets the original language of the item, inheriting from parent items if necessary.
 1751        /// </summary>
 1752        /// <returns>System.String.</returns>
 1753        public virtual string GetInheritedOriginalLanguage()
 1754        {
 01755            return OriginalLanguage;
 1756        }
 1757
 1758        public virtual bool IsSaveLocalMetadataEnabled()
 1759        {
 881760            if (SourceType == SourceType.Channel)
 1761            {
 01762                return false;
 1763            }
 1764
 881765            var libraryOptions = LibraryManager.GetLibraryOptions(this);
 1766
 881767            return libraryOptions.SaveLocalMetadata;
 1768        }
 1769
 1770        /// <summary>
 1771        /// Determines if a given user has access to this item.
 1772        /// </summary>
 1773        /// <param name="user">The user.</param>
 1774        /// <param name="skipAllowedTagsCheck">Don't check for allowed tags.</param>
 1775        /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns>
 1776        /// <exception cref="ArgumentNullException">If user is null.</exception>
 1777        public bool IsParentalAllowed(User user, bool skipAllowedTagsCheck)
 1778        {
 101779            ArgumentNullException.ThrowIfNull(user);
 1780
 101781            if (!IsVisibleViaTags(user, skipAllowedTagsCheck))
 1782            {
 01783                return false;
 1784            }
 1785
 101786            var maxAllowedRating = user.MaxParentalRatingScore;
 101787            var maxAllowedSubRating = user.MaxParentalRatingSubScore;
 101788            var rating = CustomRatingForComparison;
 1789
 101790            if (string.IsNullOrEmpty(rating))
 1791            {
 101792                rating = OfficialRatingForComparison;
 1793            }
 1794
 101795            if (string.IsNullOrEmpty(rating))
 1796            {
 101797                return !GetBlockUnratedValue(user);
 1798            }
 1799
 01800            var ratingScore = LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode());
 1801
 1802            // Could not determine rating level
 01803            if (ratingScore is null)
 1804            {
 01805                var isAllowed = !GetBlockUnratedValue(user);
 1806
 01807                if (!isAllowed)
 1808                {
 01809                    Logger.LogDebug("{0} has an unrecognized parental rating of {1}.", Name, rating);
 1810                }
 1811
 01812                return isAllowed;
 1813            }
 1814
 01815            if (!maxAllowedRating.HasValue)
 1816            {
 01817                return true;
 1818            }
 1819
 01820            if (ratingScore.Score != maxAllowedRating.Value)
 1821            {
 01822                return ratingScore.Score < maxAllowedRating.Value;
 1823            }
 1824
 01825            return !maxAllowedSubRating.HasValue || (ratingScore.SubScore ?? 0) <= maxAllowedSubRating.Value;
 1826        }
 1827
 1828        public ParentalRatingScore GetParentalRatingScore()
 1829        {
 1221830            var rating = CustomRatingForComparison;
 1831
 1221832            if (string.IsNullOrEmpty(rating))
 1833            {
 1221834                rating = OfficialRatingForComparison;
 1835            }
 1836
 1221837            if (string.IsNullOrEmpty(rating))
 1838            {
 1221839                return null;
 1840            }
 1841
 01842            return LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode());
 1843        }
 1844
 1845        public List<string> GetInheritedTags()
 1846        {
 1171847            var list = new List<string>();
 1171848            list.AddRange(Tags);
 1849
 2901850            foreach (var parent in GetParents())
 1851            {
 281852                list.AddRange(parent.Tags);
 1853            }
 1854
 2341855            foreach (var folder in LibraryManager.GetCollectionFolders(this))
 1856            {
 01857                list.AddRange(folder.Tags);
 1858            }
 1859
 1171860            return list.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
 1861        }
 1862
 1863        protected bool IsVisibleViaTags(User user, bool skipAllowedTagsCheck)
 1864        {
 101865            var blockedTags = user.GetPreference(PreferenceKind.BlockedTags);
 101866            var allowedTags = user.GetPreference(PreferenceKind.AllowedTags);
 1867
 101868            if (blockedTags.Length == 0 && allowedTags.Length == 0)
 1869            {
 101870                return true;
 1871            }
 1872
 1873            // Normalize tags using the same logic as database queries
 01874            var normalizedBlockedTags = blockedTags
 01875                .Where(t => !string.IsNullOrWhiteSpace(t))
 01876                .Select(t => t.GetCleanValue())
 01877                .ToHashSet(StringComparer.Ordinal);
 1878
 01879            var normalizedItemTags = GetInheritedTags()
 01880                .Select(t => t.GetCleanValue())
 01881                .ToHashSet(StringComparer.Ordinal);
 1882
 1883            // Check blocked tags - item is hidden if it has any blocked tag
 01884            if (normalizedBlockedTags.Overlaps(normalizedItemTags))
 1885            {
 01886                return false;
 1887            }
 1888
 01889            var parent = GetParents().FirstOrDefault() ?? this;
 01890            if (parent is UserRootFolder or AggregateFolder or UserView)
 1891            {
 01892                return true;
 1893            }
 1894
 1895            // Check allowed tags - item must have at least one allowed tag
 01896            if (!skipAllowedTagsCheck && allowedTags.Length > 0)
 1897            {
 01898                var normalizedAllowedTags = allowedTags
 01899                    .Where(t => !string.IsNullOrWhiteSpace(t))
 01900                    .Select(t => t.GetCleanValue())
 01901                    .ToHashSet(StringComparer.Ordinal);
 1902
 01903                if (!normalizedAllowedTags.Overlaps(normalizedItemTags))
 1904                {
 01905                    return false;
 1906                }
 1907            }
 1908
 01909            return true;
 1910        }
 1911
 1912        public virtual UnratedItem GetBlockUnratedType()
 1913        {
 1171914            if (SourceType == SourceType.Channel)
 1915            {
 01916                return UnratedItem.ChannelContent;
 1917            }
 1918
 1171919            return UnratedItem.Other;
 1920        }
 1921
 1922        /// <summary>
 1923        /// Gets a bool indicating if access to the unrated item is blocked or not.
 1924        /// </summary>
 1925        /// <param name="user">The configuration.</param>
 1926        /// <returns><c>true</c> if blocked, <c>false</c> otherwise.</returns>
 1927        protected virtual bool GetBlockUnratedValue(User user)
 1928        {
 1929            // Don't block plain folders that are unrated. Let the media underneath get blocked
 1930            // Special folders like series and albums will override this method.
 101931            if (IsFolder || this is IItemByName)
 1932            {
 101933                return false;
 1934            }
 1935
 01936            return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(GetBlockUnratedType(
 1937        }
 1938
 1939        /// <summary>
 1940        /// Determines if this folder should be visible to a given user.
 1941        /// Default is just parental allowed. Can be overridden for more functionality.
 1942        /// </summary>
 1943        /// <param name="user">The user.</param>
 1944        /// <param name="skipAllowedTagsCheck">Don't check for allowed tags.</param>
 1945        /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns>
 1946        /// <exception cref="ArgumentNullException"><paramref name="user" /> is <c>null</c>.</exception>
 1947        public virtual bool IsVisible(User user, bool skipAllowedTagsCheck = false)
 1948        {
 101949            ArgumentNullException.ThrowIfNull(user);
 1950
 101951            return IsParentalAllowed(user, skipAllowedTagsCheck);
 1952        }
 1953
 1954        public virtual bool IsVisibleStandalone(User user)
 1955        {
 01956            if (SourceType == SourceType.Channel)
 1957            {
 01958                return IsVisibleStandaloneInternal(user, false) && Channel.IsChannelVisible(this, user);
 1959            }
 1960
 01961            return IsVisibleStandaloneInternal(user, true);
 1962        }
 1963
 1964        public virtual string GetClientTypeName()
 1965        {
 1211966            if (IsFolder && SourceType == SourceType.Channel && this is not Channel && this is not Season && this is not
 1967            {
 01968                return "ChannelFolderItem";
 1969            }
 1970
 1211971            return GetType().Name;
 1972        }
 1973
 1974        public BaseItemKind GetBaseItemKind()
 1975        {
 2551976            return _baseItemKind ??= Enum.Parse<BaseItemKind>(GetClientTypeName());
 1977        }
 1978
 1979        /// <summary>
 1980        /// Gets the linked child.
 1981        /// </summary>
 1982        /// <param name="info">The info.</param>
 1983        /// <returns>BaseItem.</returns>
 1984        protected BaseItem GetLinkedChild(LinkedChild info)
 1985        {
 1986            // First get using the cached Id
 01987            if (info.ItemId.HasValue)
 1988            {
 01989                if (info.ItemId.Value.IsEmpty())
 1990                {
 01991                    return null;
 1992                }
 1993
 01994                var itemById = LibraryManager.GetItemById(info.ItemId.Value);
 1995
 01996                if (itemById is not null)
 1997                {
 01998                    return itemById;
 1999                }
 2000            }
 2001
 02002            var item = FindLinkedChild(info);
 2003
 2004            // If still null, log
 02005            if (item is null)
 2006            {
 2007                // Don't keep searching over and over
 02008                info.ItemId = Guid.Empty;
 2009            }
 2010            else
 2011            {
 2012                // Cache the id for next time
 02013                info.ItemId = item.Id;
 2014            }
 2015
 02016            return item;
 2017        }
 2018
 2019#pragma warning disable CS0618 // Type or member is obsolete - fallback for legacy LinkedChild data
 2020        private BaseItem FindLinkedChild(LinkedChild info)
 2021        {
 2022            // First try to find by ItemId (new preferred method)
 02023            if (info.ItemId.HasValue && !info.ItemId.Value.Equals(Guid.Empty))
 2024            {
 02025                var item = LibraryManager.GetItemById(info.ItemId.Value);
 02026                if (item is not null)
 2027                {
 02028                    return item;
 2029                }
 2030
 02031                Logger.LogWarning("Unable to find linked item by ItemId {0}", info.ItemId);
 2032            }
 2033
 2034            // Fall back to Path (legacy method)
 02035            var path = info.Path;
 02036            if (!string.IsNullOrEmpty(path))
 2037            {
 02038                path = FileSystem.MakeAbsolutePath(ContainingFolderPath, path);
 2039
 02040                var itemByPath = LibraryManager.FindByPath(path, null);
 2041
 02042                if (itemByPath is null)
 2043                {
 02044                    Logger.LogWarning("Unable to find linked item at path {0}", info.Path);
 2045                }
 2046
 02047                return itemByPath;
 2048            }
 2049
 2050            // Fall back to LibraryItemId (legacy method)
 02051            if (!string.IsNullOrEmpty(info.LibraryItemId))
 2052            {
 02053                var item = LibraryManager.GetItemById(info.LibraryItemId);
 2054
 02055                if (item is null)
 2056                {
 02057                    Logger.LogWarning("Unable to find linked item by LibraryItemId {0}", info.LibraryItemId);
 2058                }
 2059
 02060                return item;
 2061            }
 2062
 02063            return null;
 2064        }
 2065#pragma warning restore CS0618
 2066
 2067        /// <summary>
 2068        /// Adds a studio to the item.
 2069        /// </summary>
 2070        /// <param name="name">The name.</param>
 2071        /// <exception cref="ArgumentNullException">Throws if name is null.</exception>
 2072        public void AddStudio(string name)
 2073        {
 42074            ArgumentException.ThrowIfNullOrEmpty(name);
 42075            var current = Studios;
 2076
 42077            if (!current.Contains(name, StringComparison.OrdinalIgnoreCase))
 2078            {
 42079                int curLen = current.Length;
 42080                if (curLen == 0)
 2081                {
 42082                    Studios = [name];
 2083                }
 2084                else
 2085                {
 02086                    Studios = [.. current, name];
 2087                }
 2088            }
 02089        }
 2090
 2091        public void SetStudios(IEnumerable<string> names)
 2092        {
 52093            Studios = names.Trimmed().Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
 52094        }
 2095
 2096        /// <summary>
 2097        /// Adds a genre to the item.
 2098        /// </summary>
 2099        /// <param name="name">The name.</param>
 2100        /// <exception cref="ArgumentNullException">Throws if name is null.</exception>
 2101        public void AddGenre(string name)
 2102        {
 132103            ArgumentException.ThrowIfNullOrEmpty(name);
 2104
 132105            var genres = Genres;
 132106            if (!genres.Contains(name, StringComparison.OrdinalIgnoreCase))
 2107            {
 132108                Genres = [.. genres, name];
 2109            }
 132110        }
 2111
 2112        /// <summary>
 2113        /// Marks the played.
 2114        /// </summary>
 2115        /// <param name="user">The user.</param>
 2116        /// <param name="datePlayed">The date played.</param>
 2117        /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
 2118        /// <exception cref="ArgumentNullException">Throws if user is null.</exception>
 2119        public virtual void MarkPlayed(
 2120            User user,
 2121            DateTime? datePlayed,
 2122            bool resetPosition)
 2123        {
 02124            ArgumentNullException.ThrowIfNull(user);
 2125
 02126            var data = UserDataManager.GetUserData(user, this) ?? new UserItemData()
 02127            {
 02128                Key = GetUserDataKeys().First(),
 02129            };
 2130
 02131            if (datePlayed.HasValue)
 2132            {
 2133                // Increment
 02134                data.PlayCount++;
 2135            }
 2136
 2137            // Ensure it's at least one
 02138            data.PlayCount = Math.Max(data.PlayCount, 1);
 2139
 02140            if (resetPosition)
 2141            {
 02142                data.PlaybackPositionTicks = 0;
 2143            }
 2144
 02145            data.LastPlayedDate = datePlayed ?? data.LastPlayedDate ?? DateTime.UtcNow;
 02146            data.Played = true;
 2147
 02148            UserDataManager.SaveUserData(user, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None);
 02149        }
 2150
 2151        /// <summary>
 2152        /// Marks the unplayed.
 2153        /// </summary>
 2154        /// <param name="user">The user.</param>
 2155        /// <exception cref="ArgumentNullException">Throws if user is null.</exception>
 2156        public virtual void MarkUnplayed(User user)
 2157        {
 02158            ArgumentNullException.ThrowIfNull(user);
 2159
 02160            var data = UserDataManager.GetUserData(user, this);
 2161
 2162            // I think it is okay to do this here.
 2163            // if this is only called when a user is manually forcing something to un-played
 2164            // then it probably is what we want to do...
 02165            ResetPlayedState(data);
 2166
 02167            UserDataManager.SaveUserData(user, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None);
 02168        }
 2169
 2170        /// <summary>
 2171        /// Clears the played state on the supplied user data.
 2172        /// </summary>
 2173        /// <param name="data">The user data to reset.</param>
 2174        protected static void ResetPlayedState(UserItemData data)
 2175        {
 22176            ArgumentNullException.ThrowIfNull(data);
 2177
 22178            data.PlayCount = 0;
 22179            data.PlaybackPositionTicks = 0;
 22180            data.LastPlayedDate = null;
 22181            data.Played = false;
 22182        }
 2183
 2184        /// <summary>
 2185        /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
 2186        /// </summary>
 2187        public virtual void ChangedExternally()
 2188        {
 02189            ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(new DirectoryService(FileSystem)), RefreshPriori
 02190        }
 2191
 2192        /// <summary>
 2193        /// Gets an image.
 2194        /// </summary>
 2195        /// <param name="type">The type.</param>
 2196        /// <param name="imageIndex">Index of the image.</param>
 2197        /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
 2198        /// <exception cref="ArgumentException">Backdrops should be accessed using Item.Backdrops.</exception>
 2199        public bool HasImage(ImageType type, int imageIndex)
 2200        {
 1482201            return GetImageInfo(type, imageIndex) is not null;
 2202        }
 2203
 2204        public void SetImage(ItemImageInfo image, int index)
 2205        {
 222206            if (image.Type == ImageType.Chapter)
 2207            {
 02208                throw new ArgumentException("Cannot set chapter images using SetImagePath");
 2209            }
 2210
 222211            var existingImage = GetImageInfo(image.Type, index);
 2212
 222213            if (existingImage is null)
 2214            {
 192215                AddImage(image);
 2216            }
 2217            else
 2218            {
 32219                existingImage.Path = image.Path;
 32220                existingImage.DateModified = image.DateModified;
 32221                existingImage.Width = image.Width;
 32222                existingImage.Height = image.Height;
 32223                existingImage.BlurHash = image.BlurHash;
 2224            }
 32225        }
 2226
 2227        public void SetImagePath(ImageType type, int index, FileSystemMetadata file)
 2228        {
 462229            if (type == ImageType.Chapter)
 2230            {
 02231                throw new ArgumentException("Cannot set chapter images using SetImagePath");
 2232            }
 2233
 462234            var image = GetImageInfo(type, index);
 2235
 462236            if (image is null)
 2237            {
 452238                AddImage(GetImageInfo(file, type));
 2239            }
 2240            else
 2241            {
 12242                var imageInfo = GetImageInfo(file, type);
 2243
 12244                image.Path = file.FullName;
 12245                image.DateModified = imageInfo.DateModified;
 2246
 2247                // reset these values
 12248                image.Width = 0;
 12249                image.Height = 0;
 2250            }
 12251        }
 2252
 2253        /// <summary>
 2254        /// Deletes the image.
 2255        /// </summary>
 2256        /// <param name="type">The type.</param>
 2257        /// <param name="index">The index.</param>
 2258        /// <returns>A task.</returns>
 2259        public async Task DeleteImageAsync(ImageType type, int index)
 2260        {
 02261            var info = GetImageInfo(type, index);
 2262
 02263            if (info is null)
 2264            {
 2265                // Nothing to do
 02266                return;
 2267            }
 2268
 2269            // Remove from file system
 02270            var path = info.Path;
 02271            if (info.IsLocalFile && !string.IsNullOrWhiteSpace(path))
 2272            {
 02273                FileSystem.DeleteFile(path);
 2274            }
 2275
 2276            // Remove from item
 02277            RemoveImage(info);
 2278
 02279            await UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
 02280        }
 2281
 2282        public void RemoveImage(ItemImageInfo image)
 2283        {
 02284            RemoveImages([image]);
 02285        }
 2286
 2287        public void RemoveImages(IEnumerable<ItemImageInfo> deletedImages)
 2288        {
 92289            ImageInfos = ImageInfos.Except(deletedImages).ToArray();
 92290        }
 2291
 2292        public void AddImage(ItemImageInfo image)
 2293        {
 642294            ImageInfos = [.. ImageInfos, image];
 642295        }
 2296
 2297        public virtual async Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationTok
 1152298         => await LibraryManager.UpdateItemAsync(this, GetParent(), updateReason, cancellationToken).ConfigureAwait(fals
 2299
 2300        public async Task ReattachUserDataAsync(CancellationToken cancellationToken) =>
 352301            await LibraryManager.ReattachUserDataAsync(this, cancellationToken).ConfigureAwait(false);
 2302
 2303        /// <summary>
 2304        /// Validates that images within the item are still on the filesystem.
 2305        /// </summary>
 2306        /// <returns><c>true</c> if the images validate, <c>false</c> if not.</returns>
 2307        public bool ValidateImages()
 2308        {
 752309            List<ItemImageInfo> deletedImages = null;
 1802310            foreach (var imageInfo in ImageInfos)
 2311            {
 152312                if (!imageInfo.IsLocalFile)
 2313                {
 2314                    continue;
 2315                }
 2316
 152317                if (File.Exists(imageInfo.Path))
 2318                {
 2319                    continue;
 2320                }
 2321
 32322                (deletedImages ??= []).Add(imageInfo);
 2323            }
 2324
 752325            var anyImagesRemoved = deletedImages?.Count > 0;
 752326            if (anyImagesRemoved)
 2327            {
 22328                RemoveImages(deletedImages);
 2329            }
 2330
 752331            return anyImagesRemoved;
 2332        }
 2333
 2334        /// <summary>
 2335        /// Gets the image path.
 2336        /// </summary>
 2337        /// <param name="imageType">Type of the image.</param>
 2338        /// <param name="imageIndex">Index of the image.</param>
 2339        /// <returns>System.String.</returns>
 2340        /// <exception cref="ArgumentNullException">Item is null.</exception>
 2341        public string GetImagePath(ImageType imageType, int imageIndex)
 42342            => GetImageInfo(imageType, imageIndex)?.Path;
 2343
 2344        /// <summary>
 2345        /// Gets the image information.
 2346        /// </summary>
 2347        /// <param name="imageType">Type of the image.</param>
 2348        /// <param name="imageIndex">Index of the image.</param>
 2349        /// <returns>ItemImageInfo.</returns>
 2350        public ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex)
 2351        {
 3292352            if (imageType == ImageType.Chapter)
 2353            {
 02354                var chapter = ChapterManager.GetChapter(Id, imageIndex);
 2355
 02356                if (chapter is null)
 2357                {
 02358                    return null;
 2359                }
 2360
 02361                var path = chapter.ImagePath;
 2362
 02363                if (string.IsNullOrEmpty(path))
 2364                {
 02365                    return null;
 2366                }
 2367
 02368                return new ItemImageInfo
 02369                {
 02370                    Path = path,
 02371                    DateModified = chapter.ImageDateModified,
 02372                    Type = imageType
 02373                };
 2374            }
 2375
 3292376            return GetImages(imageType)
 3292377                .ElementAtOrDefault(imageIndex);
 2378        }
 2379
 2380        /// <summary>
 2381        /// Computes image index for given image or raises if no matching image found.
 2382        /// </summary>
 2383        /// <param name="image">Image to compute index for.</param>
 2384        /// <exception cref="ArgumentException">Image index cannot be computed as no matching image found.
 2385        /// </exception>
 2386        /// <returns>Image index.</returns>
 2387        public int GetImageIndex(ItemImageInfo image)
 2388        {
 02389            ArgumentNullException.ThrowIfNull(image);
 2390
 02391            if (image.Type == ImageType.Chapter)
 2392            {
 02393                var chapters = ChapterManager.GetChapters(Id);
 02394                for (var i = 0; i < chapters.Count; i++)
 2395                {
 02396                    if (chapters[i].ImagePath == image.Path)
 2397                    {
 02398                        return i;
 2399                    }
 2400                }
 2401
 02402                throw new ArgumentException("No chapter index found for image path", image.Path);
 2403            }
 2404
 02405            var images = GetImages(image.Type).ToArray();
 02406            for (var i = 0; i < images.Length; i++)
 2407            {
 02408                if (images[i].Path == image.Path)
 2409                {
 02410                    return i;
 2411                }
 2412            }
 2413
 02414            throw new ArgumentException("No image index found for image path", image.Path);
 2415        }
 2416
 2417        public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
 2418        {
 4392419            if (imageType == ImageType.Chapter)
 2420            {
 02421                throw new ArgumentException("No image info for chapter images");
 2422            }
 2423
 2424            // Yield return is more performant than LINQ Where on an Array
 14342425            for (var i = 0; i < ImageInfos.Length; i++)
 2426            {
 3072427                var imageInfo = ImageInfos[i];
 3072428                if (imageInfo.Type == imageType)
 2429                {
 1612430                    yield return imageInfo;
 2431                }
 2432            }
 4102433        }
 2434
 2435        /// <summary>
 2436        /// Adds the images, updating metadata if they already are part of this item.
 2437        /// </summary>
 2438        /// <param name="imageType">Type of the image.</param>
 2439        /// <param name="images">The images.</param>
 2440        /// <returns><c>true</c> if images were added or updated, <c>false</c> otherwise.</returns>
 2441        /// <exception cref="ArgumentException">Cannot call AddImages with chapter images.</exception>
 2442        public bool AddImages(ImageType imageType, List<FileSystemMetadata> images)
 2443        {
 42444            if (imageType == ImageType.Chapter)
 2445            {
 02446                throw new ArgumentException("Cannot call AddImages with chapter images");
 2447            }
 2448
 42449            var existingImages = GetImages(imageType)
 42450                .ToList();
 2451
 42452            var newImageList = new List<FileSystemMetadata>();
 42453            var imageUpdated = false;
 2454
 242455            foreach (var newImage in images)
 2456            {
 82457                if (newImage is null)
 2458                {
 02459                    throw new ArgumentException("null image found in list");
 2460                }
 2461
 82462                var existing = existingImages
 82463                    .Find(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase));
 2464
 82465                if (existing is null)
 2466                {
 42467                    newImageList.Add(newImage);
 2468                }
 2469                else
 2470                {
 42471                    if (existing.IsLocalFile)
 2472                    {
 42473                        var newDateModified = FileSystem.GetLastWriteTimeUtc(newImage);
 2474
 2475                        // If date changed then we need to reset saved image dimensions
 42476                        if (existing.DateModified != newDateModified && (existing.Width > 0 || existing.Height > 0))
 2477                        {
 22478                            existing.Width = 0;
 22479                            existing.Height = 0;
 22480                            imageUpdated = true;
 2481                        }
 2482
 42483                        existing.DateModified = newDateModified;
 2484                    }
 2485                }
 2486            }
 2487
 42488            if (newImageList.Count > 0)
 2489            {
 22490                ImageInfos = ImageInfos.Concat(newImageList.Select(i => GetImageInfo(i, imageType))).ToArray();
 2491            }
 2492
 42493            return imageUpdated || newImageList.Count > 0;
 2494        }
 2495
 2496        private ItemImageInfo GetImageInfo(FileSystemMetadata file, ImageType type)
 2497        {
 502498            return new ItemImageInfo
 502499            {
 502500                Path = file.FullName,
 502501                Type = type,
 502502                DateModified = FileSystem.GetLastWriteTimeUtc(file)
 502503            };
 2504        }
 2505
 2506        /// <summary>
 2507        /// Gets the file system path to delete when the item is to be deleted.
 2508        /// </summary>
 2509        /// <returns>The metadata for the deleted paths.</returns>
 2510        public virtual IEnumerable<FileSystemMetadata> GetDeletePaths()
 2511        {
 02512            return new[]
 02513            {
 02514                FileSystem.GetFileSystemInfo(Path)
 02515            }.Concat(GetLocalMetadataFilesToDelete());
 2516        }
 2517
 2518        protected List<FileSystemMetadata> GetLocalMetadataFilesToDelete()
 2519        {
 02520            if (IsFolder || !IsInMixedFolder)
 2521            {
 02522                return [];
 2523            }
 2524
 02525            var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
 2526
 02527            return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), _supportedExtensions, false, false)
 02528                .Where(i => System.IO.Path.GetFileNameWithoutExtension(i.FullName).StartsWith(filename, StringComparison
 02529                .ToList();
 2530        }
 2531
 2532        public bool AllowsMultipleImages(ImageType type)
 2533        {
 232534            return type == ImageType.Backdrop || type == ImageType.Chapter;
 2535        }
 2536
 2537        public Task SwapImagesAsync(ImageType type, int index1, int index2)
 2538        {
 02539            if (!AllowsMultipleImages(type))
 2540            {
 02541                throw new ArgumentException("The change index operation is only applicable to backdrops and screen shots
 2542            }
 2543
 02544            var info1 = GetImageInfo(type, index1);
 02545            var info2 = GetImageInfo(type, index2);
 2546
 02547            if (info1 is null || info2 is null)
 2548            {
 2549                // Nothing to do
 02550                return Task.CompletedTask;
 2551            }
 2552
 02553            if (!info1.IsLocalFile || !info2.IsLocalFile)
 2554            {
 2555                // TODO: Not supported  yet
 02556                return Task.CompletedTask;
 2557            }
 2558
 02559            var path1 = info1.Path;
 02560            var path2 = info2.Path;
 2561
 02562            FileSystem.SwapFiles(path1, path2);
 2563
 2564            // Refresh these values
 02565            info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
 02566            info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
 2567
 02568            info1.Width = 0;
 02569            info1.Height = 0;
 02570            info2.Width = 0;
 02571            info2.Height = 0;
 2572
 02573            return UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None);
 2574        }
 2575
 2576        public virtual bool IsPlayed(User user, UserItemData userItemData)
 2577        {
 02578            userItemData ??= UserDataManager.GetUserData(user, this);
 2579
 02580            return userItemData is not null && userItemData.Played;
 2581        }
 2582
 2583        public bool IsFavoriteOrLiked(User user, UserItemData userItemData)
 2584        {
 02585            userItemData ??= UserDataManager.GetUserData(user, this);
 2586
 02587            return userItemData is not null && (userItemData.IsFavorite || (userItemData.Likes ?? false));
 2588        }
 2589
 2590        public virtual bool IsUnplayed(User user, UserItemData userItemData)
 2591        {
 02592            ArgumentNullException.ThrowIfNull(user);
 2593
 02594            userItemData ??= UserDataManager.GetUserData(user, this);
 2595
 02596            return userItemData is null || !userItemData.Played;
 2597        }
 2598
 2599        ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo()
 2600        {
 362601            return GetItemLookupInfo<ItemLookupInfo>();
 2602        }
 2603
 2604        protected T GetItemLookupInfo<T>()
 2605            where T : ItemLookupInfo, new()
 2606        {
 362607            return new T
 362608            {
 362609                Path = Path,
 362610                MetadataCountryCode = GetPreferredMetadataCountryCode(),
 362611                MetadataLanguage = GetPreferredMetadataLanguage(),
 362612                Name = GetNameForMetadataLookup(),
 362613                OriginalTitle = OriginalTitle,
 362614                ProviderIds = ProviderIds,
 362615                IndexNumber = IndexNumber,
 362616                ParentIndexNumber = ParentIndexNumber,
 362617                Year = ProductionYear,
 362618                PremiereDate = PremiereDate
 362619            };
 2620        }
 2621
 2622        protected virtual string GetNameForMetadataLookup()
 2623        {
 362624            return Name;
 2625        }
 2626
 2627        /// <summary>
 2628        /// This is called before any metadata refresh and returns true if changes were made.
 2629        /// </summary>
 2630        /// <param name="replaceAllMetadata">Whether to replace all metadata.</param>
 2631        /// <returns>true if the item has change, else false.</returns>
 2632        public virtual bool BeforeMetadataRefresh(bool replaceAllMetadata)
 2633        {
 362634            _sortName = null;
 2635
 362636            var hasChanges = false;
 2637
 362638            if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Path))
 2639            {
 02640                Name = System.IO.Path.GetFileNameWithoutExtension(Path);
 02641                hasChanges = true;
 2642            }
 2643
 362644            return hasChanges;
 2645        }
 2646
 2647        protected static string GetMappedPath(BaseItem item, string path, MediaProtocol? protocol)
 2648        {
 02649            if (protocol == MediaProtocol.File)
 2650            {
 02651                return LibraryManager.GetPathAfterNetworkSubstitution(path, item);
 2652            }
 2653
 02654            return path;
 2655        }
 2656
 2657        public virtual void FillUserDataDtoValues(
 2658            UserItemDataDto dto,
 2659            UserItemData userData,
 2660            BaseItemDto itemDto,
 2661            User user,
 2662            DtoOptions fields,
 2663            (int Played, int Total)? precomputedCounts = null)
 2664        {
 02665            if (RunTimeTicks.HasValue)
 2666            {
 02667                double pct = RunTimeTicks.Value;
 2668
 02669                if (pct > 0)
 2670                {
 02671                    pct = userData.PlaybackPositionTicks / pct;
 2672
 02673                    if (pct > 0)
 2674                    {
 02675                        dto.PlayedPercentage = 100 * pct;
 2676                    }
 2677                }
 2678            }
 02679        }
 2680
 2681        /// <summary>
 2682        /// Applies the owner's premiere date and production year to an owned item, returning whether anything changed.
 2683        /// </summary>
 2684        /// <param name="owner">The owner.</param>
 2685        /// <param name="ownedItem">The owned item.</param>
 2686        /// <returns><c>true</c> if the owned item was changed, else <c>false</c>.</returns>
 2687        internal static bool InheritDatesFromOwner(BaseItem owner, BaseItem ownedItem)
 2688        {
 2689            // Extras have no release date of their own, so the owner's is authoritative.
 42690            var changed = false;
 2691
 42692            if (owner.ProductionYear is not null && ownedItem.ProductionYear != owner.ProductionYear)
 2693            {
 22694                ownedItem.ProductionYear = owner.ProductionYear;
 22695                changed = true;
 2696            }
 2697
 42698            if (owner.PremiereDate is not null && ownedItem.PremiereDate != owner.PremiereDate)
 2699            {
 22700                ownedItem.PremiereDate = owner.PremiereDate;
 22701                changed = true;
 2702            }
 2703
 42704            return changed;
 2705        }
 2706
 2707        protected async Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOpti
 2708        {
 02709            var newOptions = new MetadataRefreshOptions(options)
 02710            {
 02711                SearchResult = null
 02712            };
 2713
 02714            var item = this;
 2715
 02716            if (copyTitleMetadata)
 2717            {
 2718                // Take some data from the main item, for querying purposes
 02719                if (!item.Genres.SequenceEqual(ownedItem.Genres, StringComparer.Ordinal))
 2720                {
 02721                    newOptions.ForceSave = true;
 02722                    ownedItem.Genres = item.Genres;
 2723                }
 2724
 02725                if (!item.Studios.SequenceEqual(ownedItem.Studios, StringComparer.Ordinal))
 2726                {
 02727                    newOptions.ForceSave = true;
 02728                    ownedItem.Studios = item.Studios;
 2729                }
 2730
 02731                if (!item.ProductionLocations.SequenceEqual(ownedItem.ProductionLocations, StringComparer.Ordinal))
 2732                {
 02733                    newOptions.ForceSave = true;
 02734                    ownedItem.ProductionLocations = item.ProductionLocations;
 2735                }
 2736
 02737                if (item.CommunityRating != ownedItem.CommunityRating)
 2738                {
 02739                    ownedItem.CommunityRating = item.CommunityRating;
 02740                    newOptions.ForceSave = true;
 2741                }
 2742
 02743                if (item.CriticRating != ownedItem.CriticRating)
 2744                {
 02745                    ownedItem.CriticRating = item.CriticRating;
 02746                    newOptions.ForceSave = true;
 2747                }
 2748
 02749                if (!string.Equals(item.Overview, ownedItem.Overview, StringComparison.Ordinal))
 2750                {
 02751                    ownedItem.Overview = item.Overview;
 02752                    newOptions.ForceSave = true;
 2753                }
 2754
 02755                if (!string.Equals(item.OfficialRating, ownedItem.OfficialRating, StringComparison.Ordinal))
 2756                {
 02757                    ownedItem.OfficialRating = item.OfficialRating;
 02758                    newOptions.ForceSave = true;
 2759                }
 2760
 02761                if (!string.Equals(item.CustomRating, ownedItem.CustomRating, StringComparison.Ordinal))
 2762                {
 02763                    ownedItem.CustomRating = item.CustomRating;
 02764                    newOptions.ForceSave = true;
 2765                }
 2766
 02767                if (InheritDatesFromOwner(item, ownedItem))
 2768                {
 02769                    newOptions.ForceSave = true;
 2770                }
 2771            }
 2772
 02773            await ownedItem.RefreshMetadata(newOptions, cancellationToken).ConfigureAwait(false);
 02774        }
 2775
 2776        protected async Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, bool copyTitleMetadata, string
 2777        {
 02778            var newOptions = new MetadataRefreshOptions(options)
 02779            {
 02780                SearchResult = null
 02781            };
 2782
 02783            var id = LibraryManager.GetNewItemId(path, typeof(Video));
 2784
 2785            // Try to retrieve it from the db. If we don't find it, use the resolved version
 02786            if (LibraryManager.GetItemById(id) is not Video video)
 2787            {
 02788                video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video;
 2789
 02790                newOptions.ForceSave = true;
 2791            }
 2792
 02793            if (video is null)
 2794            {
 02795                return;
 2796            }
 2797
 02798            if (video.OwnerId.IsEmpty())
 2799            {
 02800                video.OwnerId = Id;
 2801            }
 2802
 02803            await RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken).ConfigureAwait(fa
 02804        }
 2805
 2806        public string GetEtag(User user)
 2807        {
 62808            var list = GetEtagValues(user);
 2809
 62810            return string.Join('|', list).GetMD5().ToString("N", CultureInfo.InvariantCulture);
 2811        }
 2812
 2813        protected virtual List<string> GetEtagValues(User user)
 2814        {
 62815            return
 62816            [
 62817                DateLastSaved.Ticks.ToString(CultureInfo.InvariantCulture)
 62818            ];
 2819        }
 2820
 2821        public virtual IEnumerable<Guid> GetAncestorIds()
 2822        {
 1172823            return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
 2824        }
 2825
 2826        public BaseItem GetTopParent()
 2827        {
 2012828            if (IsTopParent)
 2829            {
 222830                return this;
 2831            }
 2832
 1792833            return GetParents().FirstOrDefault(parent => parent.IsTopParent);
 2834        }
 2835
 2836        public virtual IEnumerable<Guid> GetIdsForAncestorQuery()
 2837        {
 452838            return [Id];
 2839        }
 2840
 2841        public virtual double? GetRefreshProgress()
 2842        {
 02843            return null;
 2844        }
 2845
 2846        public virtual ItemUpdateType OnMetadataChanged()
 2847        {
 1222848            var updateType = ItemUpdateType.None;
 2849
 1222850            var item = this;
 2851
 1222852            var rating = item.GetParentalRatingScore();
 1222853            if (rating is not null)
 2854            {
 02855                if (rating.Score != item.InheritedParentalRatingValue)
 2856                {
 02857                    item.InheritedParentalRatingValue = rating.Score;
 02858                    updateType |= ItemUpdateType.MetadataImport;
 2859                }
 2860
 02861                if (rating.SubScore != item.InheritedParentalRatingSubValue)
 2862                {
 02863                    item.InheritedParentalRatingSubValue = rating.SubScore;
 02864                    updateType |= ItemUpdateType.MetadataImport;
 2865                }
 2866            }
 2867            else
 2868            {
 1222869                if (item.InheritedParentalRatingValue is not null)
 2870                {
 02871                    item.InheritedParentalRatingValue = null;
 02872                    item.InheritedParentalRatingSubValue = null;
 02873                    updateType |= ItemUpdateType.MetadataImport;
 2874                }
 2875            }
 2876
 1222877            return updateType;
 2878        }
 2879
 2880        /// <summary>
 2881        /// Updates the official rating based on content and returns true or false indicating if it changed.
 2882        /// </summary>
 2883        /// <param name="children">Media children.</param>
 2884        /// <returns><c>true</c> if the rating was updated; otherwise <c>false</c>.</returns>
 2885        public bool UpdateRatingToItems(IReadOnlyList<BaseItem> children)
 2886        {
 02887            var currentOfficialRating = OfficialRating;
 2888
 2889            // Gather all possible ratings
 02890            var ratings = children
 02891                .Select(i => i.OfficialRating)
 02892                .Where(i => !string.IsNullOrEmpty(i))
 02893                .Distinct(StringComparer.OrdinalIgnoreCase)
 02894                .Select(rating => (rating, LocalizationManager.GetRatingScore(rating, GetPreferredMetadataCountryCode())
 02895                .OrderBy(i => i.Item2 is null ? 1001 : i.Item2.Score)
 02896                .ThenBy(i => i.Item2 is null ? 1001 : i.Item2.SubScore)
 02897                .Select(i => i.rating);
 2898
 02899            OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
 2900
 02901            return !string.Equals(
 02902                currentOfficialRating ?? string.Empty,
 02903                OfficialRating ?? string.Empty,
 02904                StringComparison.OrdinalIgnoreCase);
 2905        }
 2906
 2907        public IReadOnlyList<BaseItem> GetThemeSongs(User user = null)
 2908        {
 02909            return GetThemeSongs(user, Array.Empty<(ItemSortBy, SortOrder)>());
 2910        }
 2911
 2912        public IReadOnlyList<BaseItem> GetThemeSongs(User user, IEnumerable<(ItemSortBy SortBy, SortOrder SortOrder)> or
 2913        {
 02914            return LibraryManager.Sort(GetExtras(user).Where(e => e.ExtraType == Model.Entities.ExtraType.ThemeSong), us
 2915        }
 2916
 2917        public IReadOnlyList<BaseItem> GetThemeVideos(User user = null)
 2918        {
 02919            return GetThemeVideos(user, Array.Empty<(ItemSortBy, SortOrder)>());
 2920        }
 2921
 2922        public IReadOnlyList<BaseItem> GetThemeVideos(User user, IEnumerable<(ItemSortBy SortBy, SortOrder SortOrder)> o
 2923        {
 02924            return LibraryManager.Sort(GetExtras(user).Where(e => e.ExtraType == Model.Entities.ExtraType.ThemeVideo), u
 2925        }
 2926
 2927        /// <summary>
 2928        /// Gets the ids of the items whose owned extras belong to this item.
 2929        /// </summary>
 2930        /// <returns>An array containing the owner ids.</returns>
 2931        protected virtual Guid[] GetExtraOwnerIds()
 2932        {
 62933            return [Id];
 2934        }
 2935
 2936        /// <summary>
 2937        /// Gets the ids of this item and the versions of it whose extras it maintains.
 2938        /// </summary>
 2939        /// <returns>An array containing the version ids.</returns>
 2940        protected virtual Guid[] GetOwnedVersionIds()
 2941        {
 02942            return [Id];
 2943        }
 2944
 2945        /// <summary>
 2946        /// Gets the id of the version an extra belongs to.
 2947        /// </summary>
 2948        /// <param name="extra">The extra.</param>
 2949        /// <returns>The id of the owning version.</returns>
 2950        protected virtual Guid GetOwnerIdForExtra(BaseItem extra)
 2951        {
 02952            return Id;
 2953        }
 2954
 2955        /// <summary>
 2956        /// Get all extras associated with this item, sorted by <see cref="SortName"/>.
 2957        /// </summary>
 2958        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 2959        /// <returns>An enumerable containing the items.</returns>
 2960        public IEnumerable<BaseItem> GetExtras(User user = null)
 2961        {
 62962            return LibraryManager.GetItemList(new InternalItemsQuery(user)
 62963            {
 62964                OwnerIds = GetExtraOwnerIds(),
 62965                OrderBy = [(ItemSortBy.SortName, SortOrder.Ascending)]
 62966            });
 2967        }
 2968
 2969        /// <summary>
 2970        /// Get all extras with specific types that are associated with this item.
 2971        /// </summary>
 2972        /// <param name="extraTypes">The types of extras to retrieve.</param>
 2973        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 2974        /// <returns>An enumerable containing the extras.</returns>
 2975        public IEnumerable<BaseItem> GetExtras(IReadOnlyCollection<ExtraType> extraTypes, User user = null)
 2976        {
 02977            return LibraryManager.GetItemList(new InternalItemsQuery(user)
 02978            {
 02979                OwnerIds = GetExtraOwnerIds(),
 02980                ExtraTypes = extraTypes.ToArray(),
 02981                OrderBy = [(ItemSortBy.SortName, SortOrder.Ascending)]
 02982            });
 2983        }
 2984
 2985        public virtual long GetRunTimeTicksForPlayState()
 2986        {
 02987            return RunTimeTicks ?? 0;
 2988        }
 2989
 2990        /// <inheritdoc />
 2991        public override bool Equals(object obj)
 2992        {
 1382993            return obj is BaseItem baseItem && this.Equals(baseItem);
 2994        }
 2995
 2996        /// <inheritdoc />
 2972997        public bool Equals(BaseItem other) => other is not null && other.Id.Equals(Id);
 2998
 2999        /// <inheritdoc />
 1023000        public override int GetHashCode() => HashCode.Combine(Id);
 3001    }
 3002}

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()
GetOwnedVersionIds()
GetOwnerIdForExtra(MediaBrowser.Controller.Entities.BaseItem)
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()