< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Video
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Video.cs
Line coverage
25%
Covered lines: 69
Uncovered lines: 199
Coverable lines: 268
Total lines: 795
Line coverage: 25.7%
Branch coverage
27%
Covered branches: 39
Total branches: 142
Branch coverage: 27.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 4/9/2026 - 12:14:15 AM Line coverage: 13% (20/153) Branch coverage: 14.1% (11/78) Total lines: 5664/19/2026 - 12:14:27 AM Line coverage: 11% (20/181) Branch coverage: 12.5% (11/88) Total lines: 5665/4/2026 - 12:15:16 AM Line coverage: 8.6% (20/232) Branch coverage: 9.8% (11/112) Total lines: 6685/8/2026 - 12:15:13 AM Line coverage: 9% (21/232) Branch coverage: 9.8% (11/112) Total lines: 6685/20/2026 - 12:15:44 AM Line coverage: 9% (21/232) Branch coverage: 8.9% (10/112) Total lines: 6685/27/2026 - 12:15:38 AM Line coverage: 9.7% (23/235) Branch coverage: 11.6% (14/120) Total lines: 6796/6/2026 - 12:15:50 AM Line coverage: 9.8% (23/234) Branch coverage: 11.6% (14/120) Total lines: 6807/6/2026 - 12:16:28 AM Line coverage: 25.7% (69/268) Branch coverage: 27.4% (39/142) Total lines: 795 4/9/2026 - 12:14:15 AM Line coverage: 13% (20/153) Branch coverage: 14.1% (11/78) Total lines: 5664/19/2026 - 12:14:27 AM Line coverage: 11% (20/181) Branch coverage: 12.5% (11/88) Total lines: 5665/4/2026 - 12:15:16 AM Line coverage: 8.6% (20/232) Branch coverage: 9.8% (11/112) Total lines: 6685/8/2026 - 12:15:13 AM Line coverage: 9% (21/232) Branch coverage: 9.8% (11/112) Total lines: 6685/20/2026 - 12:15:44 AM Line coverage: 9% (21/232) Branch coverage: 8.9% (10/112) Total lines: 6685/27/2026 - 12:15:38 AM Line coverage: 9.7% (23/235) Branch coverage: 11.6% (14/120) Total lines: 6796/6/2026 - 12:15:50 AM Line coverage: 9.8% (23/234) Branch coverage: 11.6% (14/120) Total lines: 6807/6/2026 - 12:16:28 AM Line coverage: 25.7% (69/268) Branch coverage: 27.4% (39/142) Total lines: 795

Coverage delta

Coverage delta 16 -16

Metrics

File(s)

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

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Linq;
 9using System.Text.Json.Serialization;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Jellyfin.Data.Enums;
 13using Jellyfin.Database.Implementations.Entities;
 14using Jellyfin.Extensions;
 15using MediaBrowser.Controller.Library;
 16using MediaBrowser.Controller.LiveTv;
 17using MediaBrowser.Controller.Persistence;
 18using MediaBrowser.Controller.Providers;
 19using MediaBrowser.Model.Dto;
 20using MediaBrowser.Model.Entities;
 21using MediaBrowser.Model.IO;
 22using MediaBrowser.Model.MediaInfo;
 23using Microsoft.Extensions.Logging;
 24
 25namespace MediaBrowser.Controller.Entities
 26{
 27    /// <summary>
 28    /// Class Video.
 29    /// </summary>
 30    public class Video : BaseItem,
 31        IHasAspectRatio,
 32        ISupportsPlaceHolders,
 33        IHasMediaSources
 34    {
 55135        public Video()
 36        {
 55137            AdditionalParts = [];
 55138            LocalAlternateVersions = [];
 55139            SubtitleFiles = [];
 55140            AudioFiles = [];
 55141            LinkedAlternateVersions = [];
 55142        }
 43
 44        [JsonIgnore]
 45        public Guid? PrimaryVersionId { get; set; }
 46
 47        public string[] AdditionalParts { get; set; }
 48
 49        public string[] LocalAlternateVersions { get; set; }
 50
 51        public LinkedChild[] LinkedAlternateVersions { get; set; }
 52
 53        [JsonIgnore]
 054        public override bool SupportsPlayedStatus => true;
 55
 56        [JsonIgnore]
 057        public override bool SupportsPeople => true;
 58
 59        [JsonIgnore]
 060        public override bool SupportsInheritedParentImages => true;
 61
 62        [JsonIgnore]
 63        public override bool SupportsPositionTicksResume
 64        {
 65            get
 66            {
 067                var extraType = ExtraType;
 068                if (extraType.HasValue)
 69                {
 070                    if (extraType.Value == Model.Entities.ExtraType.Sample)
 71                    {
 072                        return false;
 73                    }
 74
 075                    if (extraType.Value == Model.Entities.ExtraType.ThemeVideo)
 76                    {
 077                        return false;
 78                    }
 79
 080                    if (extraType.Value == Model.Entities.ExtraType.Trailer)
 81                    {
 082                        return false;
 83                    }
 84                }
 85
 086                return true;
 87            }
 88        }
 89
 90        [JsonIgnore]
 091        public override bool SupportsThemeMedia => true;
 92
 93        /// <summary>
 94        /// Gets or sets the timestamp.
 95        /// </summary>
 96        /// <value>The timestamp.</value>
 97        public TransportStreamTimestamp? Timestamp { get; set; }
 98
 99        /// <summary>
 100        /// Gets or sets the subtitle paths.
 101        /// </summary>
 102        /// <value>The subtitle paths.</value>
 103        public string[] SubtitleFiles { get; set; }
 104
 105        /// <summary>
 106        /// Gets or sets the audio paths.
 107        /// </summary>
 108        /// <value>The audio paths.</value>
 109        public string[] AudioFiles { get; set; }
 110
 111        /// <summary>
 112        /// Gets or sets a value indicating whether this instance has subtitles.
 113        /// </summary>
 114        /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
 115        public bool HasSubtitles { get; set; }
 116
 117        public bool IsPlaceHolder { get; set; }
 118
 119        /// <summary>
 120        /// Gets or sets the default index of the video stream.
 121        /// </summary>
 122        /// <value>The default index of the video stream.</value>
 123        public int? DefaultVideoStreamIndex { get; set; }
 124
 125        /// <summary>
 126        /// Gets or sets the type of the video.
 127        /// </summary>
 128        /// <value>The type of the video.</value>
 129        public VideoType VideoType { get; set; }
 130
 131        /// <summary>
 132        /// Gets or sets the type of the iso.
 133        /// </summary>
 134        /// <value>The type of the iso.</value>
 135        public IsoType? IsoType { get; set; }
 136
 137        /// <summary>
 138        /// Gets or sets the video3 D format.
 139        /// </summary>
 140        /// <value>The video3 D format.</value>
 141        public Video3DFormat? Video3DFormat { get; set; }
 142
 143        /// <summary>
 144        /// Gets or sets the aspect ratio.
 145        /// </summary>
 146        /// <value>The aspect ratio.</value>
 147        public string AspectRatio { get; set; }
 148
 149        [JsonIgnore]
 0150        public override bool SupportsAddingToPlaylist => true;
 151
 152        [JsonIgnore]
 153        public int MediaSourceCount
 154        {
 155            get
 156            {
 0157                return GetMediaSourceCount();
 158            }
 159        }
 160
 161        [JsonIgnore]
 59162        public bool IsStacked => AdditionalParts.Length > 0;
 163
 164        [JsonIgnore]
 15165        public override bool HasLocalAlternateVersions => LibraryManager.GetLocalAlternateVersionIds(this).Any();
 166
 167        public static IRecordingsManager RecordingsManager { get; set; }
 168
 169        [JsonIgnore]
 170        public override SourceType SourceType
 171        {
 172            get
 173            {
 45174                if (IsActiveRecording())
 175                {
 0176                    return SourceType.LiveTV;
 177                }
 178
 45179                return base.SourceType;
 180            }
 181        }
 182
 183        [JsonIgnore]
 184        public bool IsCompleteMedia
 185        {
 186            get
 187            {
 0188                if (SourceType == SourceType.Channel)
 189                {
 0190                    return !Tags.Contains("livestream", StringComparison.OrdinalIgnoreCase);
 191                }
 192
 0193                return !IsActiveRecording();
 194            }
 195        }
 196
 197        [JsonIgnore]
 0198        protected virtual bool EnableDefaultVideoUserDataKeys => true;
 199
 200        [JsonIgnore]
 201        public override string ContainingFolderPath
 202        {
 203            get
 204            {
 59205                if (IsStacked)
 206                {
 0207                    return System.IO.Path.GetDirectoryName(Path);
 208                }
 209
 59210                if (!IsPlaceHolder)
 211                {
 59212                    if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
 213                    {
 1214                        return Path;
 215                    }
 216                }
 217
 58218                return base.ContainingFolderPath;
 219            }
 220        }
 221
 222        [JsonIgnore]
 223        public override string FileNameWithoutExtension
 224        {
 225            get
 226            {
 31227                if (IsFileProtocol)
 228                {
 31229                    if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
 230                    {
 0231                        return System.IO.Path.GetFileName(Path);
 232                    }
 233
 31234                    return System.IO.Path.GetFileNameWithoutExtension(Path);
 235                }
 236
 0237                return null;
 238            }
 239        }
 240
 241        /// <summary>
 242        /// Gets a value indicating whether [is3 D].
 243        /// </summary>
 244        /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
 245        [JsonIgnore]
 0246        public bool Is3D => Video3DFormat.HasValue;
 247
 248        /// <summary>
 249        /// Gets the type of the media.
 250        /// </summary>
 251        /// <value>The type of the media.</value>
 252        [JsonIgnore]
 52253        public override MediaType MediaType => MediaType.Video;
 254
 255        private int GetMediaSourceCount(HashSet<Guid> callstack = null)
 256        {
 0257            callstack ??= [];
 0258            if (PrimaryVersionId.HasValue)
 259            {
 0260                var item = LibraryManager.GetItemById(PrimaryVersionId.Value);
 0261                if (item is Video video)
 262                {
 0263                    if (callstack.Contains(video.Id))
 264                    {
 265                        // Count alternate versions using LibraryManager
 0266                        var linkedCount = LibraryManager.GetLinkedAlternateVersions(video).Count();
 0267                        var localCount = LibraryManager.GetLocalAlternateVersionIds(video).Count();
 0268                        return linkedCount + localCount + 1;
 269                    }
 270
 0271                    callstack.Add(video.Id);
 0272                    return video.GetMediaSourceCount(callstack);
 273                }
 274            }
 275
 276            // Count alternate versions using LibraryManager
 0277            var linkedVersionCount = LibraryManager.GetLinkedAlternateVersions(this).Count();
 0278            var localVersionCount = LibraryManager.GetLocalAlternateVersionIds(this).Count();
 0279            return linkedVersionCount + localVersionCount + 1;
 280        }
 281
 282        /// <inheritdoc />
 283        public override string GetInheritedOriginalLanguage()
 284        {
 31285            if (ExtraType.GetValueOrDefault() == Model.Entities.ExtraType.Trailer)
 286            {
 0287                return GetOwner()?.GetInheritedOriginalLanguage();
 288            }
 289
 31290            return OriginalLanguage ?? GetOwner()?.GetInheritedOriginalLanguage();
 291        }
 292
 293        public override List<string> GetUserDataKeys()
 294        {
 0295            var list = base.GetUserDataKeys();
 296
 0297            if (EnableDefaultVideoUserDataKeys)
 298            {
 0299                if (ExtraType.HasValue)
 300                {
 0301                    var key = this.GetProviderId(MetadataProvider.Tmdb);
 0302                    if (!string.IsNullOrEmpty(key))
 303                    {
 0304                        list.Insert(0, GetUserDataKey(key));
 305                    }
 306
 0307                    key = this.GetProviderId(MetadataProvider.Imdb);
 0308                    if (!string.IsNullOrEmpty(key))
 309                    {
 0310                        list.Insert(0, GetUserDataKey(key));
 311                    }
 312                }
 313                else
 314                {
 0315                    var key = this.GetProviderId(MetadataProvider.Imdb);
 0316                    if (!string.IsNullOrEmpty(key))
 317                    {
 0318                        list.Insert(0, key);
 319                    }
 320
 0321                    key = this.GetProviderId(MetadataProvider.Tmdb);
 0322                    if (!string.IsNullOrEmpty(key))
 323                    {
 0324                        list.Insert(0, key);
 325                    }
 326                }
 327            }
 328
 0329            return list;
 330        }
 331
 332        public void SetPrimaryVersionId(Guid? id)
 333        {
 0334            PrimaryVersionId = id;
 0335            PresentationUniqueKey = CreatePresentationUniqueKey();
 0336        }
 337
 338        /// <summary>
 339        /// Marks the played status of this video and propagates it to its alternate versions.
 340        /// </summary>
 341        /// <param name="user">The user.</param>
 342        /// <param name="datePlayed">The date played.</param>
 343        /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
 344        public override void MarkPlayed(User user, DateTime? datePlayed, bool resetPosition)
 345        {
 0346            base.MarkPlayed(user, datePlayed, resetPosition);
 0347            PropagatePlayedState(user, true, resetPosition);
 0348        }
 349
 350        /// <summary>
 351        /// Marks this video unplayed and propagates the change to its alternate versions.
 352        /// </summary>
 353        /// <param name="user">The user.</param>
 354        public override void MarkUnplayed(User user)
 355        {
 0356            base.MarkUnplayed(user);
 357
 358            // MarkUnplayed always clears the position on this video, so reset the versions too.
 0359            PropagatePlayedState(user, false, true);
 0360        }
 361
 362        /// <summary>
 363        /// Propagates the played status to every alternate version of this video.
 364        /// </summary>
 365        /// <param name="user">The user.</param>
 366        /// <param name="played">The played status to apply to the alternate versions.</param>
 367        /// <param name="resetPosition">When marking played, controls whether each version's resume point
 368        /// is also reset (<c>true</c>) or left untouched (<c>false</c>). Ignored when marking unplayed,
 369        /// which always fully resets every version.</param>
 370        public void PropagatePlayedState(User user, bool played, bool resetPosition = true)
 371        {
 4372            ArgumentNullException.ThrowIfNull(user);
 373
 4374            if (!PrimaryVersionId.HasValue && LinkedAlternateVersions.Length == 0 && !HasLocalAlternateVersions)
 375            {
 1376                return;
 377            }
 378
 24379            foreach (var (item, _) in GetAllItemsForMediaSources())
 380            {
 9381                if (item.Id.Equals(Id) || item is not Video)
 382                {
 383                    continue;
 384                }
 385
 6386                if (played)
 387                {
 4388                    var dto = new UpdateUserItemDataDto { Played = true };
 4389                    if (resetPosition)
 390                    {
 2391                        dto.PlaybackPositionTicks = 0;
 392                    }
 393
 394                    // SaveUserData only writes the fields set on the DTO, so play count and other state are preserved.
 4395                    UserDataManager.SaveUserData(user, item, dto, UserDataSaveReason.TogglePlayed);
 396                }
 397                else
 398                {
 2399                    var data = UserDataManager.GetUserData(user, item);
 2400                    if (data is null)
 401                    {
 402                        continue;
 403                    }
 404
 2405                    ResetPlayedState(data);
 2406                    UserDataManager.SaveUserData(user, item, data, UserDataSaveReason.TogglePlayed, CancellationToken.No
 407                }
 408            }
 3409        }
 410
 411        /// <summary>
 412        /// Gets this video together with all of its alternate versions (local and linked and, when this
 413        /// is itself an alternate, the primary and the primary's other versions), deduplicated.
 414        /// </summary>
 415        /// <returns>This video and every alternate version of it.</returns>
 416        public IReadOnlyList<Video> GetAllVersions()
 417        {
 10418            return GetAllItemsForMediaSources()
 10419                .Select(i => i.Item)
 10420                .OfType<Video>()
 10421                .ToList();
 422        }
 423
 424        /// <summary>
 425        /// Gets the alternate version of this video that matches the supplied item id.
 426        /// </summary>
 427        /// <param name="itemId">The version item id (the playback media source id).</param>
 428        /// <returns>The matching version, or <c>null</c> when the id is not a version of this video.</returns>
 429        public Video GetAlternateVersion(Guid itemId)
 430        {
 4431            return GetAllVersions().FirstOrDefault(i => i.Id.Equals(itemId));
 432        }
 433
 434        public override string CreatePresentationUniqueKey()
 435        {
 0436            if (PrimaryVersionId.HasValue)
 437            {
 0438                return PrimaryVersionId.Value.ToString("N", CultureInfo.InvariantCulture);
 439            }
 440
 0441            return base.CreatePresentationUniqueKey();
 442        }
 443
 444        public override bool CanDownload()
 445        {
 0446            if (VideoType == VideoType.Dvd || VideoType == VideoType.BluRay)
 447            {
 0448                return false;
 449            }
 450
 0451            return IsFileProtocol;
 452        }
 453
 454        protected override bool IsActiveRecording()
 455        {
 51456            return RecordingsManager.GetActiveRecordingInfo(Path) is not null;
 457        }
 458
 459        public override bool CanDelete()
 460        {
 0461            if (IsActiveRecording())
 462            {
 0463                return false;
 464            }
 465
 0466            return base.CanDelete();
 467        }
 468
 469        public IEnumerable<Guid> GetAdditionalPartIds()
 470        {
 0471            return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
 472        }
 473
 474        private string GetUserDataKey(string providerId)
 475        {
 0476            var key = providerId + "-" + ExtraType.ToString().ToLowerInvariant();
 477
 478            // Make sure different trailers have their own data.
 0479            if (RunTimeTicks.HasValue)
 480            {
 0481                key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
 482            }
 483
 0484            return key;
 485        }
 486
 487        /// <summary>
 488        /// Gets the additional parts.
 489        /// </summary>
 490        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 491        /// <returns>IEnumerable{Video}.</returns>
 492        public IOrderedEnumerable<Video> GetAdditionalParts(User user = null)
 493        {
 0494            return GetAdditionalPartIds()
 0495                .Select(i => LibraryManager.GetItemById<Video>(i))
 0496                .Where(i => i is not null && (user is null || i.IsVisible(user)))
 0497                .OrderBy(i => i.SortName);
 498        }
 499
 500        internal override ItemUpdateType UpdateFromResolvedItem(BaseItem newItem)
 501        {
 0502            var updateType = base.UpdateFromResolvedItem(newItem);
 503
 0504            if (newItem is Video newVideo)
 505            {
 0506                if (!AdditionalParts.SequenceEqual(newVideo.AdditionalParts, StringComparer.Ordinal))
 507                {
 0508                    AdditionalParts = newVideo.AdditionalParts;
 0509                    updateType |= ItemUpdateType.MetadataImport;
 510                }
 511
 0512                if (!LocalAlternateVersions.SequenceEqual(newVideo.LocalAlternateVersions, StringComparer.Ordinal))
 513                {
 0514                    LocalAlternateVersions = newVideo.LocalAlternateVersions;
 0515                    updateType |= ItemUpdateType.MetadataImport;
 516                }
 517
 0518                if (VideoType != newVideo.VideoType)
 519                {
 0520                    VideoType = newVideo.VideoType;
 0521                    updateType |= ItemUpdateType.MetadataImport;
 522                }
 523            }
 524
 0525            return updateType;
 526        }
 527
 528        protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, IReadOnlyList<FileSystem
 529        {
 0530            var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwa
 531
 532            // Clean up LocalAlternateVersions - remove paths that no longer exist
 0533            if (LocalAlternateVersions.Length > 0)
 534            {
 0535                var validPaths = LocalAlternateVersions.Where(FileSystem.FileExists).ToArray();
 0536                if (validPaths.Length != LocalAlternateVersions.Length)
 537                {
 0538                    LocalAlternateVersions = validPaths;
 0539                    hasChanges = true;
 540                }
 541            }
 542
 0543            if (IsStacked)
 544            {
 0545                var tasks = AdditionalParts
 0546                    .Select(i => RefreshMetadataForOwnedVideo(options, true, i, typeof(Video), cancellationToken));
 547
 0548                await Task.WhenAll(tasks).ConfigureAwait(false);
 549            }
 550
 551            // Must have a parent to have additional parts or alternate versions
 552            // In other words, it must be part of the Parent/Child tree
 553            // The additional parts won't have additional parts themselves
 0554            if (IsFileProtocol && SupportsOwnedItems)
 555            {
 556                // Check if LinkedChildren are in sync before processing
 0557                var existingVersionCount = LibraryManager.GetLocalAlternateVersionIds(this).Count();
 0558                var tasks = LocalAlternateVersions
 0559                    .Select(i => RefreshMetadataForVersions(options, false, i, cancellationToken));
 560
 0561                await Task.WhenAll(tasks).ConfigureAwait(false);
 562
 0563                if (existingVersionCount != LocalAlternateVersions.Length)
 564                {
 0565                    hasChanges = true;
 566                }
 567            }
 568
 0569            return hasChanges;
 0570        }
 571
 572        private async Task RefreshMetadataForVersions(
 573            MetadataRefreshOptions options,
 574            bool copyTitleMetadata,
 575            string path,
 576            CancellationToken cancellationToken)
 577        {
 578            // Ensure the alternate version exists with the correct type (e.g. Movie, not Video)
 579            // before refreshing. This must happen here rather than in RefreshMetadataForOwnedVideo
 580            // because that method is also used for stacked parts which should keep their resolved type.
 0581            var id = LibraryManager.GetNewItemId(path, GetType());
 0582            if (LibraryManager.GetItemById(id) is not Video && FileSystem.FileExists(path))
 583            {
 0584                var parentFolder = GetParent() as Folder;
 0585                var collectionType = LibraryManager.GetContentType(this);
 0586                var altVideo = LibraryManager.ResolveAlternateVersion(path, GetType(), parentFolder, collectionType);
 0587                if (altVideo is not null)
 588                {
 0589                    altVideo.OwnerId = Id;
 0590                    altVideo.SetPrimaryVersionId(Id);
 0591                    LibraryManager.CreateItem(altVideo, GetParent());
 592                }
 593            }
 594
 0595            await RefreshMetadataForOwnedVideo(options, copyTitleMetadata, path, cancellationToken).ConfigureAwait(false
 596
 597            // Create LinkedChild entry for this local alternate version
 598            // This ensures the relationship exists in the database even if the alternate version
 599            // was created after the primary video was first saved
 0600            if (LibraryManager.GetItemById(id) is Video video)
 601            {
 0602                LibraryManager.UpsertLinkedChild(Id, video.Id, LinkedChildType.LocalAlternateVersion);
 603
 604                // Ensure PrimaryVersionId is set for existing alternate versions that may not have it
 0605                if (!video.PrimaryVersionId.HasValue)
 606                {
 0607                    video.SetPrimaryVersionId(Id);
 0608                    await video.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(f
 609                }
 610            }
 0611        }
 612
 613        private new Task RefreshMetadataForOwnedVideo(
 614            MetadataRefreshOptions options,
 615            bool copyTitleMetadata,
 616            string path,
 617            CancellationToken cancellationToken)
 0618            => RefreshMetadataForOwnedVideo(options, copyTitleMetadata, path, GetType(), cancellationToken);
 619
 620        private async Task RefreshMetadataForOwnedVideo(
 621            MetadataRefreshOptions options,
 622            bool copyTitleMetadata,
 623            string path,
 624            Type itemType,
 625            CancellationToken cancellationToken)
 626        {
 0627            var newOptions = new MetadataRefreshOptions(options)
 0628            {
 0629                SearchResult = null
 0630            };
 631
 0632            var id = LibraryManager.GetNewItemId(path, itemType);
 633
 634            // Check if the file still exists
 0635            if (!FileSystem.FileExists(path))
 636            {
 637                // File was removed - clean up any orphaned database entry
 0638                if (LibraryManager.GetItemById(id) is Video orphanedVideo && orphanedVideo.OwnerId.Equals(Id))
 639                {
 0640                    Logger.LogInformation("Owned video file no longer exists, removing orphaned item: {Path}", path);
 0641                    LibraryManager.DeleteItem(orphanedVideo, new DeleteOptions { DeleteFileLocation = false });
 642                }
 643
 0644                return;
 645            }
 646
 0647            if (LibraryManager.GetItemById(id) is not Video video)
 648            {
 0649                var parentFolder = GetParent() as Folder;
 0650                var collectionType = LibraryManager.GetContentType(this);
 0651                video = LibraryManager.ResolvePath(
 0652                    FileSystem.GetFileSystemInfo(path),
 0653                    parentFolder,
 0654                    collectionType: collectionType) as Video;
 655
 0656                if (video is null)
 657                {
 0658                    return;
 659                }
 660
 661                // Ensure parts use the expected base type (e.g. Video, not Movie)
 0662                if (video.GetType() != itemType && Activator.CreateInstance(itemType) is Video correctVideo)
 663                {
 0664                    correctVideo.Path = video.Path;
 0665                    correctVideo.Name = video.Name;
 0666                    correctVideo.VideoType = video.VideoType;
 0667                    correctVideo.ProductionYear = video.ProductionYear;
 0668                    correctVideo.ExtraType = video.ExtraType;
 0669                    video = correctVideo;
 670                }
 671
 0672                video.Id = id;
 0673                video.OwnerId = Id;
 0674                LibraryManager.CreateItem(video, parentFolder);
 0675                newOptions.ForceSave = true;
 676            }
 677
 0678            if (video.OwnerId.IsEmpty())
 679            {
 0680                video.OwnerId = Id;
 681            }
 682
 0683            await RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken).ConfigureAwait(fa
 0684        }
 685
 686        /// <inheritdoc />
 687        public override async Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationTo
 688        {
 0689            await base.UpdateToRepositoryAsync(updateReason, cancellationToken).ConfigureAwait(false);
 690
 0691            var localAlternates = LibraryManager.GetLocalAlternateVersionIds(this)
 0692                .Select(i => LibraryManager.GetItemById(i))
 0693                .Where(i => i is not null);
 694
 0695            foreach (var item in localAlternates)
 696            {
 0697                item.ImageInfos = ImageInfos;
 0698                item.Overview = Overview;
 0699                item.ProductionYear = ProductionYear;
 0700                item.PremiereDate = PremiereDate;
 0701                item.CommunityRating = CommunityRating;
 0702                item.OfficialRating = OfficialRating;
 0703                item.Genres = Genres;
 0704                item.ProviderIds = ProviderIds;
 705
 0706                await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(fa
 707            }
 0708        }
 709
 710        public override IEnumerable<FileSystemMetadata> GetDeletePaths()
 711        {
 0712            if (!IsInMixedFolder)
 713            {
 0714                return new[]
 0715                {
 0716                    new FileSystemMetadata
 0717                    {
 0718                        FullName = ContainingFolderPath,
 0719                        IsDirectory = true
 0720                    }
 0721                };
 722            }
 723
 0724            return base.GetDeletePaths();
 725        }
 726
 727        public virtual MediaStream GetDefaultVideoStream()
 728        {
 0729            if (!DefaultVideoStreamIndex.HasValue)
 730            {
 0731                return null;
 732            }
 733
 0734            return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
 0735            {
 0736                ItemId = Id,
 0737                Index = DefaultVideoStreamIndex.Value
 0738            }).FirstOrDefault();
 739        }
 740
 741        /// <summary>
 742        /// Gets the ids of the items whose owned extras belong to this item.
 743        /// Extras are linked to a single version but need tp be surfaced for all versions.
 744        /// </summary>
 745        /// <returns>An array containing the owner ids.</returns>
 746        protected override Guid[] GetExtraOwnerIds()
 747        {
 0748            return GetAllItemsForMediaSources()
 0749                .Select(i => i.Item.Id)
 0750                .Distinct()
 0751                .ToArray();
 752        }
 753
 754        protected override IEnumerable<(BaseItem Item, MediaSourceType MediaSourceType)> GetAllItemsForMediaSources()
 755        {
 22756            var primary = PrimaryVersionId.HasValue
 22757                ? LibraryManager.GetItemById(PrimaryVersionId.Value) as Video
 22758                : null;
 759
 22760            var primaryLinked = primary is null
 22761                ? []
 22762                : LibraryManager.GetLinkedAlternateVersions(primary).ToList();
 763
 764            // Grouping marks user-merged (splittable) sources. The primary is only such a source when
 765            // this video is linked onto it; for local (file-based) alternates the primary is just
 766            // another default source.
 22767            var primaryType = primaryLinked.Any(i => i.Id.Equals(Id))
 22768                ? MediaSourceType.Grouping
 22769                : MediaSourceType.Default;
 770
 771            // This video and its linked alternates, when this is itself an alternate, the primary and the primary's lin
 22772            var grouped = new[] { ((BaseItem)this, MediaSourceType.Default) }
 22773                .Concat(LibraryManager.GetLinkedAlternateVersions(this).Select(i => ((BaseItem)i, MediaSourceType.Groupi
 22774                .Concat(primary is null
 22775                    ? []
 22776                    : primaryLinked.Select(i => ((BaseItem)i, MediaSourceType.Grouping)).Prepend(((BaseItem)primary, pri
 22777                .ToList();
 778
 779            // The local (file-based) alternate versions of every grouped item.
 22780            var localAlternates = grouped
 22781                .Select(i => i.Item1)
 22782                .OfType<Video>()
 22783                .SelectMany(LibraryManager.GetLocalAlternateVersionIds)
 22784                .Select(LibraryManager.GetItemById)
 22785                .Where(i => i is not null)
 22786                .Select(i => (i, MediaSourceType.Default));
 787
 788            // Deduplicate
 22789            return grouped
 22790                .Concat(localAlternates)
 22791                .DistinctBy(i => i.Item1.Id)
 22792                .ToList();
 793        }
 794    }
 795}

Methods/Properties

.ctor()
get_SupportsPlayedStatus()
get_SupportsPeople()
get_SupportsInheritedParentImages()
get_SupportsPositionTicksResume()
get_SupportsThemeMedia()
get_SupportsAddingToPlaylist()
get_MediaSourceCount()
get_IsStacked()
get_HasLocalAlternateVersions()
get_SourceType()
get_IsCompleteMedia()
get_EnableDefaultVideoUserDataKeys()
get_ContainingFolderPath()
get_FileNameWithoutExtension()
get_Is3D()
get_MediaType()
GetMediaSourceCount(System.Collections.Generic.HashSet`1<System.Guid>)
GetInheritedOriginalLanguage()
GetUserDataKeys()
SetPrimaryVersionId(System.Nullable`1<System.Guid>)
MarkPlayed(Jellyfin.Database.Implementations.Entities.User,System.Nullable`1<System.DateTime>,System.Boolean)
MarkUnplayed(Jellyfin.Database.Implementations.Entities.User)
PropagatePlayedState(Jellyfin.Database.Implementations.Entities.User,System.Boolean,System.Boolean)
GetAllVersions()
GetAlternateVersion(System.Guid)
CreatePresentationUniqueKey()
CanDownload()
IsActiveRecording()
CanDelete()
GetAdditionalPartIds()
GetUserDataKey(System.String)
GetAdditionalParts(Jellyfin.Database.Implementations.Entities.User)
UpdateFromResolvedItem(MediaBrowser.Controller.Entities.BaseItem)
RefreshedOwnedItems()
RefreshMetadataForVersions()
RefreshMetadataForOwnedVideo(MediaBrowser.Controller.Providers.MetadataRefreshOptions,System.Boolean,System.String,System.Threading.CancellationToken)
RefreshMetadataForOwnedVideo()
UpdateToRepositoryAsync()
GetDeletePaths()
GetDefaultVideoStream()
GetExtraOwnerIds()
GetAllItemsForMediaSources()