aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/BdInfo
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2023-02-18 14:42:35 +0100
committerShadowghost <Ghost_of_Stone@web.de>2023-03-10 15:27:17 +0100
commit0da5255f1291ba510f829d36a3ca1a9eb65590dc (patch)
tree52792d3cdd252c72eed5a5a50fe269b9f1bfd7be /MediaBrowser.MediaEncoding/BdInfo
parent47aa07c3424ce0041e0a79eea1ab7f6621485b94 (diff)
Apply review suggestions
Diffstat (limited to 'MediaBrowser.MediaEncoding/BdInfo')
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs160
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs283
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs81
3 files changed, 292 insertions, 232 deletions
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs
index 7e026b42e..ea520b1d6 100644
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs
+++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs
@@ -1,83 +1,123 @@
-#pragma warning disable CS1591
-
using System;
+using System.IO;
using System.Linq;
using BDInfo.IO;
using MediaBrowser.Model.IO;
-namespace MediaBrowser.MediaEncoding.BdInfo
+namespace MediaBrowser.MediaEncoding.BdInfo;
+
+/// <summary>
+/// Class BdInfoDirectoryInfo.
+/// </summary>
+public class BdInfoDirectoryInfo : IDirectoryInfo
{
- public class BdInfoDirectoryInfo : IDirectoryInfo
- {
- private readonly IFileSystem _fileSystem;
+ private readonly IFileSystem _fileSystem;
- private readonly FileSystemMetadata _impl;
+ private readonly FileSystemMetadata _impl;
- public BdInfoDirectoryInfo(IFileSystem fileSystem, string path)
- {
- _fileSystem = fileSystem;
- _impl = _fileSystem.GetDirectoryInfo(path);
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BdInfoDirectoryInfo" /> class.
+ /// </summary>
+ /// <param name="fileSystem">The filesystem.</param>
+ /// <param name="path">The path.</param>
+ public BdInfoDirectoryInfo(IFileSystem fileSystem, string path)
+ {
+ _fileSystem = fileSystem;
+ _impl = _fileSystem.GetDirectoryInfo(path);
+ }
- private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
- {
- _fileSystem = fileSystem;
- _impl = impl;
- }
+ private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
+ {
+ _fileSystem = fileSystem;
+ _impl = impl;
+ }
- public string Name => _impl.Name;
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ public string Name => _impl.Name;
- public string FullName => _impl.FullName;
+ /// <summary>
+ /// Gets the full name.
+ /// </summary>
+ public string FullName => _impl.FullName;
- public IDirectoryInfo? Parent
+ /// <summary>
+ /// Gets the parent directory information.
+ /// </summary>
+ public IDirectoryInfo? Parent
+ {
+ get
{
- get
+ var parentFolder = Path.GetDirectoryName(_impl.FullName);
+ if (parentFolder is not null)
{
- var parentFolder = System.IO.Path.GetDirectoryName(_impl.FullName);
- if (parentFolder is not null)
- {
- return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
- }
-
- return null;
+ return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
}
- }
- public IDirectoryInfo[] GetDirectories()
- {
- return Array.ConvertAll(
- _fileSystem.GetDirectories(_impl.FullName).ToArray(),
- x => new BdInfoDirectoryInfo(_fileSystem, x));
+ return null;
}
+ }
- public IFileInfo[] GetFiles()
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(_impl.FullName).ToArray(),
- x => new BdInfoFileInfo(x));
- }
+ /// <summary>
+ /// Gets the directories.
+ /// </summary>
+ /// <returns>An array with all directories.</returns>
+ public IDirectoryInfo[] GetDirectories()
+ {
+ return _fileSystem.GetDirectories(_impl.FullName)
+ .Select(x => new BdInfoDirectoryInfo(_fileSystem, x))
+ .ToArray();
+ }
- public IFileInfo[] GetFiles(string searchPattern)
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false).ToArray(),
- x => new BdInfoFileInfo(x));
- }
+ /// <summary>
+ /// Gets the files.
+ /// </summary>
+ /// <returns>All files of the directory.</returns>
+ public IFileInfo[] GetFiles()
+ {
+ return _fileSystem.GetFiles(_impl.FullName)
+ .Select(x => new BdInfoFileInfo(x))
+ .ToArray();
+ }
- public IFileInfo[] GetFiles(string searchPattern, System.IO.SearchOption searchOption)
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(
- _impl.FullName,
- new[] { searchPattern },
- false,
- (searchOption & System.IO.SearchOption.AllDirectories) == System.IO.SearchOption.AllDirectories).ToArray(),
- x => new BdInfoFileInfo(x));
- }
+ /// <summary>
+ /// Gets the files matching a pattern.
+ /// </summary>
+ /// <param name="searchPattern">The search pattern.</param>
+ /// <returns>All files of the directory matchign the search pattern.</returns>
+ public IFileInfo[] GetFiles(string searchPattern)
+ {
+ return _fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false)
+ .Select(x => new BdInfoFileInfo(x))
+ .ToArray();
+ }
- public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path)
- {
- return new BdInfoDirectoryInfo(fs, path);
- }
+ /// <summary>
+ /// Gets the files matching a pattern and search options.
+ /// </summary>
+ /// <param name="searchPattern">The search pattern.</param>
+ /// <param name="searchOption">The search optin.</param>
+ /// <returns>All files of the directory matchign the search pattern and options.</returns>
+ public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption)
+ {
+ return _fileSystem.GetFiles(
+ _impl.FullName,
+ new[] { searchPattern },
+ false,
+ (searchOption & SearchOption.AllDirectories) == SearchOption.AllDirectories)
+ .Select(x => new BdInfoFileInfo(x))
+ .ToArray();
+ }
+
+ /// <summary>
+ /// Gets the bdinfo of a file system path.
+ /// </summary>
+ /// <param name="fs">The file system.</param>
+ /// <param name="path">The path.</param>
+ /// <returns>The BD directory information of the path on the file system.</returns>
+ public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path)
+ {
+ return new BdInfoDirectoryInfo(fs, path);
}
}
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
index 3e53cbf29..8ebb59c59 100644
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
+++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
@@ -6,189 +6,182 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
-namespace MediaBrowser.MediaEncoding.BdInfo
+namespace MediaBrowser.MediaEncoding.BdInfo;
+
+/// <summary>
+/// Class BdInfoExaminer.
+/// </summary>
+public class BdInfoExaminer : IBlurayExaminer
{
+ private readonly IFileSystem _fileSystem;
+
/// <summary>
- /// Class BdInfoExaminer.
+ /// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
/// </summary>
- public class BdInfoExaminer : IBlurayExaminer
+ /// <param name="fileSystem">The filesystem.</param>
+ public BdInfoExaminer(IFileSystem fileSystem)
{
- private readonly IFileSystem _fileSystem;
+ _fileSystem = fileSystem;
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
- /// </summary>
- /// <param name="fileSystem">The filesystem.</param>
- public BdInfoExaminer(IFileSystem fileSystem)
+ /// <summary>
+ /// Gets the disc info.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ /// <returns>BlurayDiscInfo.</returns>
+ public BlurayDiscInfo GetDiscInfo(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path))
{
- _fileSystem = fileSystem;
+ throw new ArgumentNullException(nameof(path));
}
- /// <summary>
- /// Gets the disc info.
- /// </summary>
- /// <param name="path">The path.</param>
- /// <returns>BlurayDiscInfo.</returns>
- public BlurayDiscInfo GetDiscInfo(string path)
- {
- if (string.IsNullOrWhiteSpace(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
-
- var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
+ var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
- bdrom.Scan();
+ bdrom.Scan();
- // Get the longest playlist
- var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
+ // Get the longest playlist
+ var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
- var outputStream = new BlurayDiscInfo
- {
- MediaStreams = Array.Empty<MediaStream>()
- };
+ var outputStream = new BlurayDiscInfo
+ {
+ MediaStreams = Array.Empty<MediaStream>()
+ };
- if (playlist is null)
- {
- return outputStream;
- }
+ if (playlist is null)
+ {
+ return outputStream;
+ }
- outputStream.Chapters = playlist.Chapters.ToArray();
+ outputStream.Chapters = playlist.Chapters.ToArray();
- outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
+ outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
- var mediaStreams = new List<MediaStream>();
+ var sortedStreams = playlist.SortedStreams;
+ var mediaStreams = new List<MediaStream>(sortedStreams.Count);
- foreach (var stream in playlist.SortedStreams)
+ foreach (var stream in sortedStreams)
+ {
+ switch (stream)
{
- if (stream is TSVideoStream videoStream)
- {
+ case TSVideoStream videoStream:
AddVideoStream(mediaStreams, videoStream);
- continue;
- }
-
- if (stream is TSAudioStream audioStream)
- {
+ break;
+ case TSAudioStream audioStream:
AddAudioStream(mediaStreams, audioStream);
- continue;
- }
-
- if (stream is TSTextStream textStream)
- {
+ break;
+ case TSTextStream textStream:
AddSubtitleStream(mediaStreams, textStream);
- continue;
- }
-
- if (stream is TSGraphicsStream graphicsStream)
- {
- AddSubtitleStream(mediaStreams, graphicsStream);
- }
+ break;
+ case TSGraphicsStream graphicStream:
+ AddSubtitleStream(mediaStreams, graphicStream);
+ break;
}
+ }
- outputStream.MediaStreams = mediaStreams.ToArray();
-
- outputStream.PlaylistName = playlist.Name;
+ outputStream.MediaStreams = mediaStreams.ToArray();
- if (playlist.StreamClips is not null && playlist.StreamClips.Any())
- {
- // Get the files in the playlist
- outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToArray();
- }
+ outputStream.PlaylistName = playlist.Name;
- return outputStream;
+ if (playlist.StreamClips is not null && playlist.StreamClips.Count > 0)
+ {
+ // Get the files in the playlist
+ outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToArray();
}
- /// <summary>
- /// Adds the video stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="videoStream">The video stream.</param>
- private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream)
- {
- var mediaStream = new MediaStream
- {
- BitRate = Convert.ToInt32(videoStream.BitRate),
- Width = videoStream.Width,
- Height = videoStream.Height,
- Codec = videoStream.CodecShortName,
- IsInterlaced = videoStream.IsInterlaced,
- Type = MediaStreamType.Video,
- Index = streams.Count
- };
-
- if (videoStream.FrameRateDenominator > 0)
- {
- float frameRateEnumerator = videoStream.FrameRateEnumerator;
- float frameRateDenominator = videoStream.FrameRateDenominator;
+ return outputStream;
+ }
- mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
- }
+ /// <summary>
+ /// Adds the video stream.
+ /// </summary>
+ /// <param name="streams">The streams.</param>
+ /// <param name="videoStream">The video stream.</param>
+ private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream)
+ {
+ var mediaStream = new MediaStream
+ {
+ BitRate = Convert.ToInt32(videoStream.BitRate),
+ Width = videoStream.Width,
+ Height = videoStream.Height,
+ Codec = videoStream.CodecShortName,
+ IsInterlaced = videoStream.IsInterlaced,
+ Type = MediaStreamType.Video,
+ Index = streams.Count
+ };
+
+ if (videoStream.FrameRateDenominator > 0)
+ {
+ float frameRateEnumerator = videoStream.FrameRateEnumerator;
+ float frameRateDenominator = videoStream.FrameRateDenominator;
- streams.Add(mediaStream);
+ mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
}
- /// <summary>
- /// Adds the audio stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="audioStream">The audio stream.</param>
- private void AddAudioStream(List<MediaStream> streams, TSAudioStream audioStream)
- {
- var stream = new MediaStream
- {
- Codec = audioStream.CodecShortName,
- Language = audioStream.LanguageCode,
- Channels = audioStream.ChannelCount,
- SampleRate = audioStream.SampleRate,
- Type = MediaStreamType.Audio,
- Index = streams.Count
- };
-
- var bitrate = Convert.ToInt32(audioStream.BitRate);
+ streams.Add(mediaStream);
+ }
- if (bitrate > 0)
- {
- stream.BitRate = bitrate;
- }
+ /// <summary>
+ /// Adds the audio stream.
+ /// </summary>
+ /// <param name="streams">The streams.</param>
+ /// <param name="audioStream">The audio stream.</param>
+ private void AddAudioStream(List<MediaStream> streams, TSAudioStream audioStream)
+ {
+ var stream = new MediaStream
+ {
+ Codec = audioStream.CodecShortName,
+ Language = audioStream.LanguageCode,
+ Channels = audioStream.ChannelCount,
+ SampleRate = audioStream.SampleRate,
+ Type = MediaStreamType.Audio,
+ Index = streams.Count
+ };
- if (audioStream.LFE > 0)
- {
- stream.Channels = audioStream.ChannelCount + 1;
- }
+ var bitrate = Convert.ToInt32(audioStream.BitRate);
- streams.Add(stream);
+ if (bitrate > 0)
+ {
+ stream.BitRate = bitrate;
}
- /// <summary>
- /// Adds the subtitle stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="textStream">The text stream.</param>
- private void AddSubtitleStream(List<MediaStream> streams, TSTextStream textStream)
+ if (audioStream.LFE > 0)
{
- streams.Add(new MediaStream
- {
- Language = textStream.LanguageCode,
- Codec = textStream.CodecShortName,
- Type = MediaStreamType.Subtitle,
- Index = streams.Count
- });
+ stream.Channels = audioStream.ChannelCount + 1;
}
- /// <summary>
- /// Adds the subtitle stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="textStream">The text stream.</param>
- private void AddSubtitleStream(List<MediaStream> streams, TSGraphicsStream textStream)
+ streams.Add(stream);
+ }
+
+ /// <summary>
+ /// Adds the subtitle stream.
+ /// </summary>
+ /// <param name="streams">The streams.</param>
+ /// <param name="textStream">The text stream.</param>
+ private void AddSubtitleStream(List<MediaStream> streams, TSTextStream textStream)
+ {
+ streams.Add(new MediaStream
+ {
+ Language = textStream.LanguageCode,
+ Codec = textStream.CodecShortName,
+ Type = MediaStreamType.Subtitle,
+ Index = streams.Count
+ });
+ }
+
+ /// <summary>
+ /// Adds the subtitle stream.
+ /// </summary>
+ /// <param name="streams">The streams.</param>
+ /// <param name="textStream">The text stream.</param>
+ private void AddSubtitleStream(List<MediaStream> streams, TSGraphicsStream textStream)
+ {
+ streams.Add(new MediaStream
{
- streams.Add(new MediaStream
- {
- Language = textStream.LanguageCode,
- Codec = textStream.CodecShortName,
- Type = MediaStreamType.Subtitle,
- Index = streams.Count
- });
- }
+ Language = textStream.LanguageCode,
+ Codec = textStream.CodecShortName,
+ Type = MediaStreamType.Subtitle,
+ Index = streams.Count
+ });
}
}
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs
index d55688e3d..9e7a1d50a 100644
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs
+++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs
@@ -1,41 +1,68 @@
-#pragma warning disable CS1591
-
using System.IO;
using MediaBrowser.Model.IO;
-namespace MediaBrowser.MediaEncoding.BdInfo
+namespace MediaBrowser.MediaEncoding.BdInfo;
+
+/// <summary>
+/// Class BdInfoFileInfo.
+/// </summary>
+public class BdInfoFileInfo : BDInfo.IO.IFileInfo
{
- public class BdInfoFileInfo : BDInfo.IO.IFileInfo
- {
- private FileSystemMetadata _impl;
+ private FileSystemMetadata _impl;
- public BdInfoFileInfo(FileSystemMetadata impl)
- {
- _impl = impl;
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BdInfoFileInfo" /> class.
+ /// </summary>
+ /// <param name="impl">The <see cref="FileSystemMetadata" />.</param>
+ public BdInfoFileInfo(FileSystemMetadata impl)
+ {
+ _impl = impl;
+ }
- public string Name => _impl.Name;
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ public string Name => _impl.Name;
- public string FullName => _impl.FullName;
+ /// <summary>
+ /// Gets the full name.
+ /// </summary>
+ public string FullName => _impl.FullName;
- public string Extension => _impl.Extension;
+ /// <summary>
+ /// Gets the extension.
+ /// </summary>
+ public string Extension => _impl.Extension;
- public long Length => _impl.Length;
+ /// <summary>
+ /// Gets the length.
+ /// </summary>
+ public long Length => _impl.Length;
- public bool IsDir => _impl.IsDirectory;
+ /// <summary>
+ /// Gets a value indicating whether this is a directory.
+ /// </summary>
+ public bool IsDir => _impl.IsDirectory;
- public Stream OpenRead()
- {
- return new FileStream(
- FullName,
- FileMode.Open,
- FileAccess.Read,
- FileShare.Read);
- }
+ /// <summary>
+ /// Gets a file as file stream.
+ /// </summary>
+ /// <returns>A <see cref="FileStream" /> for the file.</returns>
+ public Stream OpenRead()
+ {
+ return new FileStream(
+ FullName,
+ FileMode.Open,
+ FileAccess.Read,
+ FileShare.Read);
+ }
- public StreamReader OpenText()
- {
- return new StreamReader(OpenRead());
- }
+ /// <summary>
+ /// Gets a files's content with a stream reader.
+ /// </summary>
+ /// <returns>A <see cref="StreamReader" /> for the file's content.</returns>
+ public StreamReader OpenText()
+ {
+ return new StreamReader(OpenRead());
}
}