< Summary - Jellyfin

Information
Class: MediaBrowser.MediaEncoding.BdInfo.BdInfoExaminer
Assembly: MediaBrowser.MediaEncoding
File(s): /srv/git/jellyfin/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
Line coverage
2%
Covered lines: 2
Uncovered lines: 76
Coverable lines: 78
Total lines: 183
Line coverage: 2.5%
Branch coverage
0%
Covered branches: 0
Total branches: 44
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetDiscInfo(...)0%342180%
AddVideoStream(...)0%620%
AddAudioStream(...)0%620%
AddSubtitleStream(...)100%210%
GetNormalizedCodec(...)0%506220%

File(s)

/srv/git/jellyfin/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.Linq;
 5using BDInfo;
 6using Jellyfin.Extensions;
 7using MediaBrowser.Model.Entities;
 8using MediaBrowser.Model.IO;
 9using MediaBrowser.Model.MediaInfo;
 10
 11namespace MediaBrowser.MediaEncoding.BdInfo;
 12
 13/// <summary>
 14/// Class BdInfoExaminer.
 15/// </summary>
 16public class BdInfoExaminer : IBlurayExaminer
 17{
 18    private readonly IFileSystem _fileSystem;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
 22    /// </summary>
 23    /// <param name="fileSystem">The filesystem.</param>
 24    public BdInfoExaminer(IFileSystem fileSystem)
 25    {
 2226        _fileSystem = fileSystem;
 2227    }
 28
 29    /// <summary>
 30    /// Gets the disc info.
 31    /// </summary>
 32    /// <param name="path">The path.</param>
 33    /// <returns>BlurayDiscInfo.</returns>
 34    public BlurayDiscInfo GetDiscInfo(string path)
 35    {
 036        if (string.IsNullOrWhiteSpace(path))
 37        {
 038            throw new ArgumentNullException(nameof(path));
 39        }
 40
 041        var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
 42
 043        bdrom.Scan();
 44
 45        // Get the longest playlist
 046        var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
 47
 048        var outputStream = new BlurayDiscInfo
 049        {
 050            MediaStreams = Array.Empty<MediaStream>()
 051        };
 52
 053        if (playlist is null)
 54        {
 055            return outputStream;
 56        }
 57
 058        outputStream.Chapters = playlist.Chapters.ToArray();
 59
 060        outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
 61
 062        var sortedStreams = playlist.SortedStreams;
 063        var mediaStreams = new List<MediaStream>(sortedStreams.Count);
 64
 065        for (int i = 0; i < sortedStreams.Count; i++)
 66        {
 067            var stream = sortedStreams[i];
 68            switch (stream)
 69            {
 70                case TSVideoStream videoStream:
 071                    AddVideoStream(mediaStreams, i, videoStream);
 072                    break;
 73                case TSAudioStream audioStream:
 074                    AddAudioStream(mediaStreams, i, audioStream);
 075                    break;
 76                case TSTextStream:
 77                case TSGraphicsStream:
 078                    AddSubtitleStream(mediaStreams, i, stream);
 79                    break;
 80            }
 81        }
 82
 083        outputStream.MediaStreams = mediaStreams.ToArray();
 84
 085        outputStream.PlaylistName = playlist.Name;
 86
 087        if (playlist.StreamClips is not null && playlist.StreamClips.Count > 0)
 88        {
 89            // Get the files in the playlist
 090            outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.FileInfo.FullName).ToArray();
 91        }
 92
 093        return outputStream;
 94    }
 95
 96    /// <summary>
 97    /// Adds the video stream.
 98    /// </summary>
 99    /// <param name="streams">The streams.</param>
 100    /// <param name="index">The stream index.</param>
 101    /// <param name="videoStream">The video stream.</param>
 102    private void AddVideoStream(List<MediaStream> streams, int index, TSVideoStream videoStream)
 103    {
 0104        var mediaStream = new MediaStream
 0105        {
 0106            BitRate = Convert.ToInt32(videoStream.BitRate),
 0107            Width = videoStream.Width,
 0108            Height = videoStream.Height,
 0109            Codec = GetNormalizedCodec(videoStream),
 0110            IsInterlaced = videoStream.IsInterlaced,
 0111            Type = MediaStreamType.Video,
 0112            Index = index
 0113        };
 114
 0115        if (videoStream.FrameRateDenominator > 0)
 116        {
 0117            float frameRateEnumerator = videoStream.FrameRateEnumerator;
 0118            float frameRateDenominator = videoStream.FrameRateDenominator;
 119
 0120            mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
 121        }
 122
 0123        streams.Add(mediaStream);
 0124    }
 125
 126    /// <summary>
 127    /// Adds the audio stream.
 128    /// </summary>
 129    /// <param name="streams">The streams.</param>
 130    /// <param name="index">The stream index.</param>
 131    /// <param name="audioStream">The audio stream.</param>
 132    private void AddAudioStream(List<MediaStream> streams, int index, TSAudioStream audioStream)
 133    {
 0134        var stream = new MediaStream
 0135        {
 0136            Codec = GetNormalizedCodec(audioStream),
 0137            Language = audioStream.LanguageCode,
 0138            ChannelLayout = string.Format(CultureInfo.InvariantCulture, "{0:D}.{1:D}", audioStream.ChannelCount, audioSt
 0139            Channels = audioStream.ChannelCount + audioStream.LFE,
 0140            SampleRate = audioStream.SampleRate,
 0141            Type = MediaStreamType.Audio,
 0142            Index = index
 0143        };
 144
 0145        var bitrate = Convert.ToInt32(audioStream.BitRate);
 146
 0147        if (bitrate > 0)
 148        {
 0149            stream.BitRate = bitrate;
 150        }
 151
 0152        streams.Add(stream);
 0153    }
 154
 155    /// <summary>
 156    /// Adds the subtitle stream.
 157    /// </summary>
 158    /// <param name="streams">The streams.</param>
 159    /// <param name="index">The stream index.</param>
 160    /// <param name="stream">The stream.</param>
 161    private void AddSubtitleStream(List<MediaStream> streams, int index, TSStream stream)
 162    {
 0163        streams.Add(new MediaStream
 0164        {
 0165            Language = stream.LanguageCode,
 0166            Codec = GetNormalizedCodec(stream),
 0167            Type = MediaStreamType.Subtitle,
 0168            Index = index
 0169        });
 0170    }
 171
 172    private string GetNormalizedCodec(TSStream stream)
 0173        => stream.StreamType switch
 0174        {
 0175            TSStreamType.MPEG1_VIDEO => "mpeg1video",
 0176            TSStreamType.MPEG2_VIDEO => "mpeg2video",
 0177            TSStreamType.VC1_VIDEO => "vc1",
 0178            TSStreamType.AC3_PLUS_AUDIO or TSStreamType.AC3_PLUS_SECONDARY_AUDIO => "eac3",
 0179            TSStreamType.DTS_AUDIO or TSStreamType.DTS_HD_AUDIO or TSStreamType.DTS_HD_MASTER_AUDIO or TSStreamType.DTS_
 0180            TSStreamType.PRESENTATION_GRAPHICS => "pgssub",
 0181            _ => stream.CodecShortName
 0182        };
 183}