< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Video
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Video.cs
Line coverage
9%
Covered lines: 23
Uncovered lines: 211
Coverable lines: 234
Total lines: 680
Line coverage: 9.8%
Branch coverage
11%
Covered branches: 14
Total branches: 120
Branch coverage: 11.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/16/2026 - 12:14:00 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: 680 3/16/2026 - 12:14:00 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: 680

Coverage delta

Coverage delta 3 -3

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    {
 49535        public Video()
 36        {
 49537            AdditionalParts = Array.Empty<string>();
 49538            LocalAlternateVersions = Array.Empty<string>();
 49539            SubtitleFiles = Array.Empty<string>();
 49540            AudioFiles = Array.Empty<string>();
 49541            LinkedAlternateVersions = Array.Empty<LinkedChild>();
 49542        }
 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]
 55162        public bool IsStacked => AdditionalParts.Length > 0;
 163
 164        [JsonIgnore]
 4165        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            {
 37174                if (IsActiveRecording())
 175                {
 0176                    return SourceType.LiveTV;
 177                }
 178
 37179                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            {
 55205                if (IsStacked)
 206                {
 0207                    return System.IO.Path.GetDirectoryName(Path);
 208                }
 209
 55210                if (!IsPlaceHolder)
 211                {
 55212                    if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
 213                    {
 1214                        return Path;
 215                    }
 216                }
 217
 54218                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]
 25253        public override MediaType MediaType => MediaType.Video;
 254
 255        private int GetMediaSourceCount(HashSet<Guid> callstack = null)
 256        {
 0257            callstack ??= new();
 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        {
 22285            if (ExtraType.GetValueOrDefault() == Model.Entities.ExtraType.Trailer)
 286            {
 0287                return GetOwner()?.GetInheritedOriginalLanguage();
 288            }
 289
 22290            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        public override string CreatePresentationUniqueKey()
 339        {
 0340            if (PrimaryVersionId.HasValue)
 341            {
 0342                return PrimaryVersionId.Value.ToString("N", CultureInfo.InvariantCulture);
 343            }
 344
 0345            return base.CreatePresentationUniqueKey();
 346        }
 347
 348        public override bool CanDownload()
 349        {
 0350            if (VideoType == VideoType.Dvd || VideoType == VideoType.BluRay)
 351            {
 0352                return false;
 353            }
 354
 0355            return IsFileProtocol;
 356        }
 357
 358        protected override bool IsActiveRecording()
 359        {
 37360            return RecordingsManager.GetActiveRecordingInfo(Path) is not null;
 361        }
 362
 363        public override bool CanDelete()
 364        {
 0365            if (IsActiveRecording())
 366            {
 0367                return false;
 368            }
 369
 0370            return base.CanDelete();
 371        }
 372
 373        public IEnumerable<Guid> GetAdditionalPartIds()
 374        {
 0375            return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
 376        }
 377
 378        private string GetUserDataKey(string providerId)
 379        {
 0380            var key = providerId + "-" + ExtraType.ToString().ToLowerInvariant();
 381
 382            // Make sure different trailers have their own data.
 0383            if (RunTimeTicks.HasValue)
 384            {
 0385                key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
 386            }
 387
 0388            return key;
 389        }
 390
 391        /// <summary>
 392        /// Gets the additional parts.
 393        /// </summary>
 394        /// <param name="user">The user to apply parental restrictions for, or <c>null</c> to skip restriction checks.</
 395        /// <returns>IEnumerable{Video}.</returns>
 396        public IOrderedEnumerable<Video> GetAdditionalParts(User user = null)
 397        {
 0398            return GetAdditionalPartIds()
 0399                .Select(i => LibraryManager.GetItemById<Video>(i, user))
 0400                .Where(i => i is not null)
 0401                .OrderBy(i => i.SortName);
 402        }
 403
 404        internal override ItemUpdateType UpdateFromResolvedItem(BaseItem newItem)
 405        {
 0406            var updateType = base.UpdateFromResolvedItem(newItem);
 407
 0408            if (newItem is Video newVideo)
 409            {
 0410                if (!AdditionalParts.SequenceEqual(newVideo.AdditionalParts, StringComparer.Ordinal))
 411                {
 0412                    AdditionalParts = newVideo.AdditionalParts;
 0413                    updateType |= ItemUpdateType.MetadataImport;
 414                }
 415
 0416                if (!LocalAlternateVersions.SequenceEqual(newVideo.LocalAlternateVersions, StringComparer.Ordinal))
 417                {
 0418                    LocalAlternateVersions = newVideo.LocalAlternateVersions;
 0419                    updateType |= ItemUpdateType.MetadataImport;
 420                }
 421
 0422                if (VideoType != newVideo.VideoType)
 423                {
 0424                    VideoType = newVideo.VideoType;
 0425                    updateType |= ItemUpdateType.MetadataImport;
 426                }
 427            }
 428
 0429            return updateType;
 430        }
 431
 432        protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, IReadOnlyList<FileSystem
 433        {
 0434            var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwa
 435
 436            // Clean up LocalAlternateVersions - remove paths that no longer exist
 0437            if (LocalAlternateVersions.Length > 0)
 438            {
 0439                var validPaths = LocalAlternateVersions.Where(FileSystem.FileExists).ToArray();
 0440                if (validPaths.Length != LocalAlternateVersions.Length)
 441                {
 0442                    LocalAlternateVersions = validPaths;
 0443                    hasChanges = true;
 444                }
 445            }
 446
 0447            if (IsStacked)
 448            {
 0449                var tasks = AdditionalParts
 0450                    .Select(i => RefreshMetadataForOwnedVideo(options, true, i, typeof(Video), cancellationToken));
 451
 0452                await Task.WhenAll(tasks).ConfigureAwait(false);
 453            }
 454
 455            // Must have a parent to have additional parts or alternate versions
 456            // In other words, it must be part of the Parent/Child tree
 457            // The additional parts won't have additional parts themselves
 0458            if (IsFileProtocol && SupportsOwnedItems)
 459            {
 460                // Check if LinkedChildren are in sync before processing
 0461                var existingVersionCount = LibraryManager.GetLocalAlternateVersionIds(this).Count();
 0462                var tasks = LocalAlternateVersions
 0463                    .Select(i => RefreshMetadataForVersions(options, false, i, cancellationToken));
 464
 0465                await Task.WhenAll(tasks).ConfigureAwait(false);
 466
 0467                if (existingVersionCount != LocalAlternateVersions.Length)
 468                {
 0469                    hasChanges = true;
 470                }
 471            }
 472
 0473            return hasChanges;
 0474        }
 475
 476        private async Task RefreshMetadataForVersions(
 477            MetadataRefreshOptions options,
 478            bool copyTitleMetadata,
 479            string path,
 480            CancellationToken cancellationToken)
 481        {
 482            // Ensure the alternate version exists with the correct type (e.g. Movie, not Video)
 483            // before refreshing. This must happen here rather than in RefreshMetadataForOwnedVideo
 484            // because that method is also used for stacked parts which should keep their resolved type.
 0485            var id = LibraryManager.GetNewItemId(path, GetType());
 0486            if (LibraryManager.GetItemById(id) is not Video && FileSystem.FileExists(path))
 487            {
 0488                var parentFolder = GetParent() as Folder;
 0489                var collectionType = LibraryManager.GetContentType(this);
 0490                var altVideo = LibraryManager.ResolveAlternateVersion(path, GetType(), parentFolder, collectionType);
 0491                if (altVideo is not null)
 492                {
 0493                    altVideo.OwnerId = Id;
 0494                    altVideo.SetPrimaryVersionId(Id);
 0495                    LibraryManager.CreateItem(altVideo, GetParent());
 496                }
 497            }
 498
 0499            await RefreshMetadataForOwnedVideo(options, copyTitleMetadata, path, cancellationToken).ConfigureAwait(false
 500
 501            // Create LinkedChild entry for this local alternate version
 502            // This ensures the relationship exists in the database even if the alternate version
 503            // was created after the primary video was first saved
 0504            if (LibraryManager.GetItemById(id) is Video video)
 505            {
 0506                LibraryManager.UpsertLinkedChild(Id, video.Id, LinkedChildType.LocalAlternateVersion);
 507
 508                // Ensure PrimaryVersionId is set for existing alternate versions that may not have it
 0509                if (!video.PrimaryVersionId.HasValue)
 510                {
 0511                    video.SetPrimaryVersionId(Id);
 0512                    await video.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(f
 513                }
 514            }
 0515        }
 516
 517        private new Task RefreshMetadataForOwnedVideo(
 518            MetadataRefreshOptions options,
 519            bool copyTitleMetadata,
 520            string path,
 521            CancellationToken cancellationToken)
 0522            => RefreshMetadataForOwnedVideo(options, copyTitleMetadata, path, GetType(), cancellationToken);
 523
 524        private async Task RefreshMetadataForOwnedVideo(
 525            MetadataRefreshOptions options,
 526            bool copyTitleMetadata,
 527            string path,
 528            Type itemType,
 529            CancellationToken cancellationToken)
 530        {
 0531            var newOptions = new MetadataRefreshOptions(options)
 0532            {
 0533                SearchResult = null
 0534            };
 535
 0536            var id = LibraryManager.GetNewItemId(path, itemType);
 537
 538            // Check if the file still exists
 0539            if (!FileSystem.FileExists(path))
 540            {
 541                // File was removed - clean up any orphaned database entry
 0542                if (LibraryManager.GetItemById(id) is Video orphanedVideo && orphanedVideo.OwnerId.Equals(Id))
 543                {
 0544                    Logger.LogInformation("Owned video file no longer exists, removing orphaned item: {Path}", path);
 0545                    LibraryManager.DeleteItem(orphanedVideo, new DeleteOptions { DeleteFileLocation = false });
 546                }
 547
 0548                return;
 549            }
 550
 0551            if (LibraryManager.GetItemById(id) is not Video video)
 552            {
 0553                var parentFolder = GetParent() as Folder;
 0554                var collectionType = LibraryManager.GetContentType(this);
 0555                video = LibraryManager.ResolvePath(
 0556                    FileSystem.GetFileSystemInfo(path),
 0557                    parentFolder,
 0558                    collectionType: collectionType) as Video;
 559
 0560                if (video is null)
 561                {
 0562                    return;
 563                }
 564
 565                // Ensure parts use the expected base type (e.g. Video, not Movie)
 0566                if (video.GetType() != itemType && Activator.CreateInstance(itemType) is Video correctVideo)
 567                {
 0568                    correctVideo.Path = video.Path;
 0569                    correctVideo.Name = video.Name;
 0570                    correctVideo.VideoType = video.VideoType;
 0571                    correctVideo.ProductionYear = video.ProductionYear;
 0572                    correctVideo.ExtraType = video.ExtraType;
 0573                    video = correctVideo;
 574                }
 575
 0576                video.Id = id;
 0577                video.OwnerId = Id;
 0578                LibraryManager.CreateItem(video, parentFolder);
 0579                newOptions.ForceSave = true;
 580            }
 581
 0582            if (video.OwnerId.IsEmpty())
 583            {
 0584                video.OwnerId = Id;
 585            }
 586
 0587            await RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken).ConfigureAwait(fa
 0588        }
 589
 590        /// <inheritdoc />
 591        public override async Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationTo
 592        {
 0593            await base.UpdateToRepositoryAsync(updateReason, cancellationToken).ConfigureAwait(false);
 594
 0595            var localAlternates = LibraryManager.GetLocalAlternateVersionIds(this)
 0596                .Select(i => LibraryManager.GetItemById(i))
 0597                .Where(i => i is not null);
 598
 0599            foreach (var item in localAlternates)
 600            {
 0601                item.ImageInfos = ImageInfos;
 0602                item.Overview = Overview;
 0603                item.ProductionYear = ProductionYear;
 0604                item.PremiereDate = PremiereDate;
 0605                item.CommunityRating = CommunityRating;
 0606                item.OfficialRating = OfficialRating;
 0607                item.Genres = Genres;
 0608                item.ProviderIds = ProviderIds;
 609
 0610                await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(fa
 611            }
 0612        }
 613
 614        public override IEnumerable<FileSystemMetadata> GetDeletePaths()
 615        {
 0616            if (!IsInMixedFolder)
 617            {
 0618                return new[]
 0619                {
 0620                    new FileSystemMetadata
 0621                    {
 0622                        FullName = ContainingFolderPath,
 0623                        IsDirectory = true
 0624                    }
 0625                };
 626            }
 627
 0628            return base.GetDeletePaths();
 629        }
 630
 631        public virtual MediaStream GetDefaultVideoStream()
 632        {
 0633            if (!DefaultVideoStreamIndex.HasValue)
 634            {
 0635                return null;
 636            }
 637
 0638            return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
 0639            {
 0640                ItemId = Id,
 0641                Index = DefaultVideoStreamIndex.Value
 0642            }).FirstOrDefault();
 643        }
 644
 645        protected override IEnumerable<(BaseItem Item, MediaSourceType MediaSourceType)> GetAllItemsForMediaSources()
 646        {
 0647            var list = new List<(BaseItem, MediaSourceType)>
 0648            {
 0649                (this, MediaSourceType.Default)
 0650            };
 651
 0652            list.AddRange(
 0653                LibraryManager.GetLinkedAlternateVersions(this)
 0654                    .Select(i => ((BaseItem)i, MediaSourceType.Grouping)));
 655
 0656            if (PrimaryVersionId.HasValue)
 657            {
 0658                if (LibraryManager.GetItemById(PrimaryVersionId.Value) is Video primary)
 659                {
 0660                    var existingIds = list.Select(i => i.Item1.Id).ToList();
 0661                    list.Add((primary, MediaSourceType.Grouping));
 0662                    list.AddRange(LibraryManager.GetLinkedAlternateVersions(primary).Where(i => !existingIds.Contains(i.
 663                }
 664            }
 665
 0666            var localAlternates = list
 0667                .SelectMany(i =>
 0668                {
 0669                    return i.Item1 is Video video ? LibraryManager.GetLocalAlternateVersionIds(video) : Enumerable.Empty
 0670                })
 0671                .Select(LibraryManager.GetItemById)
 0672                .Where(i => i is not null)
 0673                .ToList();
 674
 0675            list.AddRange(localAlternates.Select(i => (i, MediaSourceType.Default)));
 676
 0677            return list;
 678        }
 679    }
 680}