Apply review suggestions
This commit is contained in:
@@ -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 FileSystemMetadata _impl;
|
||||
|
||||
/// <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)
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
_fileSystem = fileSystem;
|
||||
_impl = _fileSystem.GetDirectoryInfo(path);
|
||||
}
|
||||
|
||||
private readonly FileSystemMetadata _impl;
|
||||
private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public BdInfoDirectoryInfo(IFileSystem fileSystem, string path)
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
public string Name => _impl.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full name.
|
||||
/// </summary>
|
||||
public string FullName => _impl.FullName;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent directory information.
|
||||
/// </summary>
|
||||
public IDirectoryInfo? Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_impl = _fileSystem.GetDirectoryInfo(path);
|
||||
}
|
||||
|
||||
private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public string Name => _impl.Name;
|
||||
|
||||
public string FullName => _impl.FullName;
|
||||
|
||||
public IDirectoryInfo? Parent
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
public IFileInfo[] GetFiles()
|
||||
{
|
||||
return Array.ConvertAll(
|
||||
_fileSystem.GetFiles(_impl.FullName).ToArray(),
|
||||
x => new BdInfoFileInfo(x));
|
||||
}
|
||||
|
||||
public IFileInfo[] GetFiles(string searchPattern)
|
||||
{
|
||||
return Array.ConvertAll(
|
||||
_fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false).ToArray(),
|
||||
x => new BdInfoFileInfo(x));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path)
|
||||
{
|
||||
return new BdInfoDirectoryInfo(fs, path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,189 +6,182 @@ using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
|
||||
namespace MediaBrowser.MediaEncoding.BdInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BdInfoExaminer.
|
||||
/// </summary>
|
||||
public class BdInfoExaminer : IBlurayExaminer
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
namespace MediaBrowser.MediaEncoding.BdInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
|
||||
/// </summary>
|
||||
/// <param name="fileSystem">The filesystem.</param>
|
||||
public BdInfoExaminer(IFileSystem fileSystem)
|
||||
/// <summary>
|
||||
/// Class BdInfoExaminer.
|
||||
/// </summary>
|
||||
public class BdInfoExaminer : IBlurayExaminer
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
|
||||
/// </summary>
|
||||
/// <param name="fileSystem">The filesystem.</param>
|
||||
public BdInfoExaminer(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = 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)
|
||||
var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
|
||||
|
||||
bdrom.Scan();
|
||||
|
||||
// Get the longest playlist
|
||||
var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
|
||||
|
||||
var outputStream = new BlurayDiscInfo
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
|
||||
|
||||
bdrom.Scan();
|
||||
|
||||
// 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>()
|
||||
};
|
||||
|
||||
if (playlist is null)
|
||||
{
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
outputStream.Chapters = playlist.Chapters.ToArray();
|
||||
|
||||
outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
|
||||
|
||||
var mediaStreams = new List<MediaStream>();
|
||||
|
||||
foreach (var stream in playlist.SortedStreams)
|
||||
{
|
||||
if (stream is TSVideoStream videoStream)
|
||||
{
|
||||
AddVideoStream(mediaStreams, videoStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stream is TSAudioStream audioStream)
|
||||
{
|
||||
AddAudioStream(mediaStreams, audioStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stream is TSTextStream textStream)
|
||||
{
|
||||
AddSubtitleStream(mediaStreams, textStream);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stream is TSGraphicsStream graphicsStream)
|
||||
{
|
||||
AddSubtitleStream(mediaStreams, graphicsStream);
|
||||
}
|
||||
}
|
||||
|
||||
outputStream.MediaStreams = mediaStreams.ToArray();
|
||||
|
||||
outputStream.PlaylistName = playlist.Name;
|
||||
|
||||
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();
|
||||
}
|
||||
MediaStreams = Array.Empty<MediaStream>()
|
||||
};
|
||||
|
||||
if (playlist is null)
|
||||
{
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
outputStream.Chapters = playlist.Chapters.ToArray();
|
||||
|
||||
outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
|
||||
|
||||
var sortedStreams = playlist.SortedStreams;
|
||||
var mediaStreams = new List<MediaStream>(sortedStreams.Count);
|
||||
|
||||
foreach (var stream in sortedStreams)
|
||||
{
|
||||
var mediaStream = new MediaStream
|
||||
switch (stream)
|
||||
{
|
||||
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;
|
||||
|
||||
mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
|
||||
case TSVideoStream videoStream:
|
||||
AddVideoStream(mediaStreams, videoStream);
|
||||
break;
|
||||
case TSAudioStream audioStream:
|
||||
AddAudioStream(mediaStreams, audioStream);
|
||||
break;
|
||||
case TSTextStream textStream:
|
||||
AddSubtitleStream(mediaStreams, textStream);
|
||||
break;
|
||||
case TSGraphicsStream graphicStream:
|
||||
AddSubtitleStream(mediaStreams, graphicStream);
|
||||
break;
|
||||
}
|
||||
|
||||
streams.Add(mediaStream);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
outputStream.MediaStreams = mediaStreams.ToArray();
|
||||
|
||||
outputStream.PlaylistName = playlist.Name;
|
||||
|
||||
if (playlist.StreamClips is not null && playlist.StreamClips.Count > 0)
|
||||
{
|
||||
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);
|
||||
|
||||
if (bitrate > 0)
|
||||
{
|
||||
stream.BitRate = bitrate;
|
||||
}
|
||||
|
||||
if (audioStream.LFE > 0)
|
||||
{
|
||||
stream.Channels = audioStream.ChannelCount + 1;
|
||||
}
|
||||
|
||||
streams.Add(stream);
|
||||
// Get the files in the playlist
|
||||
outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToArray();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
/// <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
|
||||
{
|
||||
streams.Add(new MediaStream
|
||||
{
|
||||
Language = textStream.LanguageCode,
|
||||
Codec = textStream.CodecShortName,
|
||||
Type = MediaStreamType.Subtitle,
|
||||
Index = streams.Count
|
||||
});
|
||||
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;
|
||||
|
||||
mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
|
||||
}
|
||||
|
||||
/// <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(mediaStream);
|
||||
}
|
||||
|
||||
/// <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
|
||||
{
|
||||
streams.Add(new MediaStream
|
||||
{
|
||||
Language = textStream.LanguageCode,
|
||||
Codec = textStream.CodecShortName,
|
||||
Type = MediaStreamType.Subtitle,
|
||||
Index = streams.Count
|
||||
});
|
||||
Codec = audioStream.CodecShortName,
|
||||
Language = audioStream.LanguageCode,
|
||||
Channels = audioStream.ChannelCount,
|
||||
SampleRate = audioStream.SampleRate,
|
||||
Type = MediaStreamType.Audio,
|
||||
Index = streams.Count
|
||||
};
|
||||
|
||||
var bitrate = Convert.ToInt32(audioStream.BitRate);
|
||||
|
||||
if (bitrate > 0)
|
||||
{
|
||||
stream.BitRate = bitrate;
|
||||
}
|
||||
|
||||
if (audioStream.LFE > 0)
|
||||
{
|
||||
stream.Channels = audioStream.ChannelCount + 1;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Language = textStream.LanguageCode,
|
||||
Codec = textStream.CodecShortName,
|
||||
Type = MediaStreamType.Subtitle,
|
||||
Index = streams.Count
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BdInfoFileInfo" /> class.
|
||||
/// </summary>
|
||||
/// <param name="impl">The <see cref="FileSystemMetadata" />.</param>
|
||||
public BdInfoFileInfo(FileSystemMetadata impl)
|
||||
{
|
||||
private FileSystemMetadata _impl;
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public BdInfoFileInfo(FileSystemMetadata impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
public string Name => _impl.Name;
|
||||
|
||||
public string Name => _impl.Name;
|
||||
/// <summary>
|
||||
/// Gets the full name.
|
||||
/// </summary>
|
||||
public string FullName => _impl.FullName;
|
||||
|
||||
public string FullName => _impl.FullName;
|
||||
/// <summary>
|
||||
/// Gets the extension.
|
||||
/// </summary>
|
||||
public string Extension => _impl.Extension;
|
||||
|
||||
public string Extension => _impl.Extension;
|
||||
/// <summary>
|
||||
/// Gets the length.
|
||||
/// </summary>
|
||||
public long Length => _impl.Length;
|
||||
|
||||
public long Length => _impl.Length;
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this is a directory.
|
||||
/// </summary>
|
||||
public bool IsDir => _impl.IsDirectory;
|
||||
|
||||
public bool IsDir => _impl.IsDirectory;
|
||||
/// <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 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -871,7 +871,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber)
|
||||
public IReadOnlyList<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber)
|
||||
{
|
||||
// Eliminate menus and intros by omitting VIDEO_TS.VOB and all subsequent title .vob files ending with _0.VOB
|
||||
var allVobs = _fileSystem.GetFiles(path, true)
|
||||
@@ -888,7 +888,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
if (vobs.Count > 0)
|
||||
{
|
||||
return vobs.Select(i => i.FullName);
|
||||
return vobs.Select(i => i.FullName).ToList();
|
||||
}
|
||||
|
||||
_logger.LogWarning("Could not determine .vob files for title {Title} of {Path}.", titleNumber, path);
|
||||
@@ -898,12 +898,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
var titles = allVobs
|
||||
.Where(vob => vob.Length >= 900 * 1024 * 1024)
|
||||
.Select(vob => _fileSystem.GetFileNameWithoutExtension(vob).AsSpan().RightPart('_').ToString())
|
||||
.GroupBy(x => x)
|
||||
.Select(y => y.First())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// Fall back to first title if no big title is found
|
||||
if (titles.FirstOrDefault() == null)
|
||||
if (titles.Count == 0)
|
||||
{
|
||||
titles.Add(_fileSystem.GetFileNameWithoutExtension(allVobs[0]).AsSpan().RightPart('_').ToString());
|
||||
}
|
||||
@@ -915,7 +914,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetPrimaryPlaylistM2tsFiles(string path)
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<string> GetPrimaryPlaylistM2tsFiles(string path)
|
||||
{
|
||||
// Get all playable .m2ts files
|
||||
var validPlaybackFiles = _blurayExaminer.GetDiscInfo(path).Files;
|
||||
@@ -926,51 +926,56 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
// Only return playable local .m2ts files
|
||||
return directoryFiles
|
||||
.Where(f => validPlaybackFiles.Contains(f.Name, StringComparer.OrdinalIgnoreCase))
|
||||
.Select(f => f.FullName);
|
||||
.Select(f => f.FullName)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GenerateConcatConfig(MediaSourceInfo source, string concatFilePath)
|
||||
{
|
||||
// Get all playable files
|
||||
var files = new List<string>();
|
||||
IReadOnlyList<string> files;
|
||||
var videoType = source.VideoType;
|
||||
if (videoType == VideoType.Dvd)
|
||||
{
|
||||
files = GetPrimaryPlaylistVobFiles(source.Path, null).ToList();
|
||||
files = GetPrimaryPlaylistVobFiles(source.Path, null);
|
||||
}
|
||||
else if (videoType == VideoType.BluRay)
|
||||
{
|
||||
files = GetPrimaryPlaylistM2tsFiles(source.Path).ToList();
|
||||
files = GetPrimaryPlaylistM2tsFiles(source.Path);
|
||||
}
|
||||
|
||||
// Generate concat configuration entries for each file
|
||||
var lines = new List<string>();
|
||||
foreach (var path in files)
|
||||
else
|
||||
{
|
||||
var mediaInfoResult = GetMediaInfo(
|
||||
new MediaInfoRequest
|
||||
{
|
||||
MediaType = DlnaProfileType.Video,
|
||||
MediaSource = new MediaSourceInfo
|
||||
{
|
||||
Path = path,
|
||||
Protocol = MediaProtocol.File,
|
||||
VideoType = videoType
|
||||
}
|
||||
},
|
||||
CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
var duration = TimeSpan.FromTicks(mediaInfoResult.RunTimeTicks.Value).TotalSeconds;
|
||||
|
||||
// Add file path stanza to concat configuration
|
||||
lines.Add("file " + "'" + path + "'");
|
||||
|
||||
// Add duration stanza to concat configuration
|
||||
lines.Add("duration " + duration);
|
||||
return;
|
||||
}
|
||||
|
||||
// Write concat configuration
|
||||
File.WriteAllLines(concatFilePath, lines);
|
||||
// Generate concat configuration entries for each file and write to file
|
||||
using (StreamWriter sw = new StreamWriter(concatFilePath))
|
||||
{
|
||||
foreach (var path in files)
|
||||
{
|
||||
var mediaInfoResult = GetMediaInfo(
|
||||
new MediaInfoRequest
|
||||
{
|
||||
MediaType = DlnaProfileType.Video,
|
||||
MediaSource = new MediaSourceInfo
|
||||
{
|
||||
Path = path,
|
||||
Protocol = MediaProtocol.File,
|
||||
VideoType = videoType
|
||||
}
|
||||
},
|
||||
CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
var duration = TimeSpan.FromTicks(mediaInfoResult.RunTimeTicks.Value).TotalSeconds;
|
||||
|
||||
// Add file path stanza to concat configuration
|
||||
sw.WriteLine("file '{0}'", path);
|
||||
|
||||
// Add duration stanza to concat configuration
|
||||
sw.WriteLine("duration {0}", duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanExtractSubtitles(string codec)
|
||||
|
||||
Reference in New Issue
Block a user