Apply review suggestions

This commit is contained in:
Shadowghost 2023-02-18 14:42:35 +01:00
parent 47aa07c342
commit 0da5255f12
11 changed files with 420 additions and 372 deletions

View File

@ -329,7 +329,7 @@ public class TranscodingJobHelper : IDisposable
if (File.Exists(concatFilePath)) if (File.Exists(concatFilePath))
{ {
_logger.LogInformation("Deleting ffmpeg concat configuration at {Path}", concatFilePath); _logger.LogInformation("Deleting ffmpeg concat configuration at {Path}", concatFilePath);
_fileSystem.DeleteFile(concatFilePath); File.Delete(concatFilePath);
} }
} }
} }

View File

@ -533,19 +533,12 @@ namespace MediaBrowser.Controller.MediaEncoding
public string GetInputPathArgument(EncodingJobInfo state) public string GetInputPathArgument(EncodingJobInfo state)
{ {
var mediaPath = state.MediaPath ?? string.Empty; return state.MediaSource.VideoType switch
if (state.MediaSource.VideoType == VideoType.Dvd)
{ {
return _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistVobFiles(state.MediaPath, null).ToList(), state.MediaSource); VideoType.Dvd => _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistVobFiles(state.MediaPath, null).ToList(), state.MediaSource),
} VideoType.BluRay => _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistM2tsFiles(state.MediaPath).ToList(), state.MediaSource),
_ => _mediaEncoder.GetInputArgument(state.MediaPath, state.MediaSource)
if (state.MediaSource.VideoType == VideoType.BluRay) };
{
return _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistM2tsFiles(state.MediaPath).ToList(), state.MediaSource);
}
return _mediaEncoder.GetInputArgument(mediaPath, state.MediaSource);
} }
/// <summary> /// <summary>
@ -945,10 +938,8 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
var tmpConcatPath = Path.Join(options.TranscodingTempPath, state.MediaSource.Id + ".concat"); var tmpConcatPath = Path.Join(options.TranscodingTempPath, state.MediaSource.Id + ".concat");
_mediaEncoder.GenerateConcatConfig(state.MediaSource, tmpConcatPath); _mediaEncoder.GenerateConcatConfig(state.MediaSource, tmpConcatPath);
arg.Append(" -f concat -safe 0 ") arg.Append(" -f concat -safe 0 -i ")
.Append(" -i ") .Append(tmpConcatPath);
.Append(tmpConcatPath)
.Append(' ');
} }
else else
{ {

View File

@ -202,14 +202,14 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <param name="path">The to the .vob files.</param> /// <param name="path">The to the .vob files.</param>
/// <param name="titleNumber">The title number to start with.</param> /// <param name="titleNumber">The title number to start with.</param>
/// <returns>A playlist.</returns> /// <returns>A playlist.</returns>
IEnumerable<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber); IReadOnlyList<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber);
/// <summary> /// <summary>
/// Gets the primary playlist of .m2ts files. /// Gets the primary playlist of .m2ts files.
/// </summary> /// </summary>
/// <param name="path">The to the .m2ts files.</param> /// <param name="path">The to the .m2ts files.</param>
/// <returns>A playlist.</returns> /// <returns>A playlist.</returns>
IEnumerable<string> GetPrimaryPlaylistM2tsFiles(string path); IReadOnlyList<string> GetPrimaryPlaylistM2tsFiles(string path);
/// <summary> /// <summary>
/// Generates a FFmpeg concat config for the source. /// Generates a FFmpeg concat config for the source.

View File

@ -1,83 +1,123 @@
#pragma warning disable CS1591
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
using BDInfo.IO; using BDInfo.IO;
using MediaBrowser.Model.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; var parentFolder = Path.GetDirectoryName(_impl.FullName);
_impl = _fileSystem.GetDirectoryInfo(path); if (parentFolder is not null)
}
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 = System.IO.Path.GetDirectoryName(_impl.FullName); return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
if (parentFolder is not null)
{
return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
}
return null;
} }
}
public IDirectoryInfo[] GetDirectories() return null;
{
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);
} }
} }
/// <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);
}
} }

View File

@ -6,189 +6,182 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo; 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> /// <summary>
/// Initializes a new instance of the <see cref="BdInfoExaminer" /> class. /// Class BdInfoExaminer.
/// </summary> /// </summary>
/// <param name="fileSystem">The filesystem.</param> public class BdInfoExaminer : IBlurayExaminer
public BdInfoExaminer(IFileSystem fileSystem) {
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> var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
/// Gets the disc info.
/// </summary> bdrom.Scan();
/// <param name="path">The path.</param>
/// <returns>BlurayDiscInfo.</returns> // Get the longest playlist
public BlurayDiscInfo GetDiscInfo(string path) var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
var outputStream = new BlurayDiscInfo
{ {
if (string.IsNullOrWhiteSpace(path)) MediaStreams = Array.Empty<MediaStream>()
{ };
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();
}
if (playlist is null)
{
return outputStream; return outputStream;
} }
/// <summary> outputStream.Chapters = playlist.Chapters.ToArray();
/// Adds the video stream.
/// </summary> outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
/// <param name="streams">The streams.</param>
/// <param name="videoStream">The video stream.</param> var sortedStreams = playlist.SortedStreams;
private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream) var mediaStreams = new List<MediaStream>(sortedStreams.Count);
foreach (var stream in sortedStreams)
{ {
var mediaStream = new MediaStream switch (stream)
{ {
BitRate = Convert.ToInt32(videoStream.BitRate), case TSVideoStream videoStream:
Width = videoStream.Width, AddVideoStream(mediaStreams, videoStream);
Height = videoStream.Height, break;
Codec = videoStream.CodecShortName, case TSAudioStream audioStream:
IsInterlaced = videoStream.IsInterlaced, AddAudioStream(mediaStreams, audioStream);
Type = MediaStreamType.Video, break;
Index = streams.Count case TSTextStream textStream:
}; AddSubtitleStream(mediaStreams, textStream);
break;
if (videoStream.FrameRateDenominator > 0) case TSGraphicsStream graphicStream:
{ AddSubtitleStream(mediaStreams, graphicStream);
float frameRateEnumerator = videoStream.FrameRateEnumerator; break;
float frameRateDenominator = videoStream.FrameRateDenominator;
mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
} }
streams.Add(mediaStream);
} }
/// <summary> outputStream.MediaStreams = mediaStreams.ToArray();
/// Adds the audio stream.
/// </summary> outputStream.PlaylistName = playlist.Name;
/// <param name="streams">The streams.</param>
/// <param name="audioStream">The audio stream.</param> if (playlist.StreamClips is not null && playlist.StreamClips.Count > 0)
private void AddAudioStream(List<MediaStream> streams, TSAudioStream audioStream)
{ {
var stream = new MediaStream // Get the files in the playlist
{ outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToArray();
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> return outputStream;
/// Adds the subtitle stream. }
/// </summary>
/// <param name="streams">The streams.</param> /// <summary>
/// <param name="textStream">The text stream.</param> /// Adds the video stream.
private void AddSubtitleStream(List<MediaStream> streams, TSTextStream textStream) /// </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 BitRate = Convert.ToInt32(videoStream.BitRate),
{ Width = videoStream.Width,
Language = textStream.LanguageCode, Height = videoStream.Height,
Codec = textStream.CodecShortName, Codec = videoStream.CodecShortName,
Type = MediaStreamType.Subtitle, IsInterlaced = videoStream.IsInterlaced,
Index = streams.Count 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> streams.Add(mediaStream);
/// Adds the subtitle stream. }
/// </summary>
/// <param name="streams">The streams.</param> /// <summary>
/// <param name="textStream">The text stream.</param> /// Adds the audio stream.
private void AddSubtitleStream(List<MediaStream> streams, TSGraphicsStream textStream) /// </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 Codec = audioStream.CodecShortName,
{ Language = audioStream.LanguageCode,
Language = textStream.LanguageCode, Channels = audioStream.ChannelCount,
Codec = textStream.CodecShortName, SampleRate = audioStream.SampleRate,
Type = MediaStreamType.Subtitle, Type = MediaStreamType.Audio,
Index = streams.Count 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
});
} }
} }

View File

@ -1,41 +1,68 @@
#pragma warning disable CS1591
using System.IO; using System.IO;
using MediaBrowser.Model.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) /// <summary>
{ /// Gets the name.
_impl = impl; /// </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() /// <summary>
{ /// Gets a files's content with a stream reader.
return new FileStream( /// </summary>
FullName, /// <returns>A <see cref="StreamReader" /> for the file's content.</returns>
FileMode.Open, public StreamReader OpenText()
FileAccess.Read, {
FileShare.Read); return new StreamReader(OpenRead());
}
public StreamReader OpenText()
{
return new StreamReader(OpenRead());
}
} }
} }

View File

@ -871,7 +871,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
} }
/// <inheritdoc /> /// <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 // 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) var allVobs = _fileSystem.GetFiles(path, true)
@ -888,7 +888,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (vobs.Count > 0) 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); _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 var titles = allVobs
.Where(vob => vob.Length >= 900 * 1024 * 1024) .Where(vob => vob.Length >= 900 * 1024 * 1024)
.Select(vob => _fileSystem.GetFileNameWithoutExtension(vob).AsSpan().RightPart('_').ToString()) .Select(vob => _fileSystem.GetFileNameWithoutExtension(vob).AsSpan().RightPart('_').ToString())
.GroupBy(x => x) .Distinct()
.Select(y => y.First())
.ToList(); .ToList();
// Fall back to first title if no big title is found // 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()); titles.Add(_fileSystem.GetFileNameWithoutExtension(allVobs[0]).AsSpan().RightPart('_').ToString());
} }
@ -915,7 +914,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
.ToList(); .ToList();
} }
public IEnumerable<string> GetPrimaryPlaylistM2tsFiles(string path) /// <inheritdoc />
public IReadOnlyList<string> GetPrimaryPlaylistM2tsFiles(string path)
{ {
// Get all playable .m2ts files // Get all playable .m2ts files
var validPlaybackFiles = _blurayExaminer.GetDiscInfo(path).Files; var validPlaybackFiles = _blurayExaminer.GetDiscInfo(path).Files;
@ -926,51 +926,56 @@ namespace MediaBrowser.MediaEncoding.Encoder
// Only return playable local .m2ts files // Only return playable local .m2ts files
return directoryFiles return directoryFiles
.Where(f => validPlaybackFiles.Contains(f.Name, StringComparer.OrdinalIgnoreCase)) .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) public void GenerateConcatConfig(MediaSourceInfo source, string concatFilePath)
{ {
// Get all playable files // Get all playable files
var files = new List<string>(); IReadOnlyList<string> files;
var videoType = source.VideoType; var videoType = source.VideoType;
if (videoType == VideoType.Dvd) if (videoType == VideoType.Dvd)
{ {
files = GetPrimaryPlaylistVobFiles(source.Path, null).ToList(); files = GetPrimaryPlaylistVobFiles(source.Path, null);
} }
else if (videoType == VideoType.BluRay) else if (videoType == VideoType.BluRay)
{ {
files = GetPrimaryPlaylistM2tsFiles(source.Path).ToList(); files = GetPrimaryPlaylistM2tsFiles(source.Path);
} }
else
// Generate concat configuration entries for each file
var lines = new List<string>();
foreach (var path in files)
{ {
var mediaInfoResult = GetMediaInfo( return;
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);
} }
// Write concat configuration // Generate concat configuration entries for each file and write to file
File.WriteAllLines(concatFilePath, lines); 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) public bool CanExtractSubtitles(string codec)

View File

@ -107,11 +107,8 @@ namespace MediaBrowser.Model.Dlna
public string MediaSourceId => MediaSource?.Id; public string MediaSourceId => MediaSource?.Id;
public bool IsDirectStream => public bool IsDirectStream => MediaSource?.VideoType is not (VideoType.Dvd or VideoType.BluRay)
!(MediaSource?.VideoType == VideoType.Dvd && PlayMethod is PlayMethod.DirectStream or PlayMethod.DirectPlay;
|| MediaSource?.VideoType == VideoType.BluRay)
&& (PlayMethod == PlayMethod.DirectStream
|| PlayMethod == PlayMethod.DirectPlay);
/// <summary> /// <summary>
/// Gets the audio stream that will be used. /// Gets the audio stream that will be used.

View File

@ -1,39 +1,41 @@
#nullable disable #nullable disable
#pragma warning disable CS1591
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.MediaInfo namespace MediaBrowser.Model.MediaInfo;
/// <summary>
/// Represents the result of BDInfo output.
/// </summary>
public class BlurayDiscInfo
{ {
/// <summary> /// <summary>
/// Represents the result of BDInfo output. /// Gets or sets the media streams.
/// </summary> /// </summary>
public class BlurayDiscInfo /// <value>The media streams.</value>
{ public MediaStream[] MediaStreams { get; set; }
/// <summary>
/// Gets or sets the media streams.
/// </summary>
/// <value>The media streams.</value>
public MediaStream[] MediaStreams { get; set; }
/// <summary> /// <summary>
/// Gets or sets the run time ticks. /// Gets or sets the run time ticks.
/// </summary> /// </summary>
/// <value>The run time ticks.</value> /// <value>The run time ticks.</value>
public long? RunTimeTicks { get; set; } public long? RunTimeTicks { get; set; }
/// <summary> /// <summary>
/// Gets or sets the files. /// Gets or sets the files.
/// </summary> /// </summary>
/// <value>The files.</value> /// <value>The files.</value>
public string[] Files { get; set; } public string[] Files { get; set; }
public string PlaylistName { get; set; } /// <summary>
/// Gets or sets the playlist name.
/// </summary>
/// <value>The playlist name.</value>
public string PlaylistName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the chapters. /// Gets or sets the chapters.
/// </summary> /// </summary>
/// <value>The chapters.</value> /// <value>The chapters.</value>
public double[] Chapters { get; set; } public double[] Chapters { get; set; }
}
} }

View File

@ -1,15 +1,14 @@
namespace MediaBrowser.Model.MediaInfo namespace MediaBrowser.Model.MediaInfo;
/// <summary>
/// Interface IBlurayExaminer.
/// </summary>
public interface IBlurayExaminer
{ {
/// <summary> /// <summary>
/// Interface IBlurayExaminer. /// Gets the disc info.
/// </summary> /// </summary>
public interface IBlurayExaminer /// <param name="path">The path.</param>
{ /// <returns>BlurayDiscInfo.</returns>
/// <summary> BlurayDiscInfo GetDiscInfo(string path);
/// Gets the disc info.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>BlurayDiscInfo.</returns>
BlurayDiscInfo GetDiscInfo(string path);
}
} }

View File

@ -92,7 +92,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (item.VideoType == VideoType.Dvd) if (item.VideoType == VideoType.Dvd)
{ {
// Get list of playable .vob files // Get list of playable .vob files
var vobs = _mediaEncoder.GetPrimaryPlaylistVobFiles(item.Path, null).ToList(); var vobs = _mediaEncoder.GetPrimaryPlaylistVobFiles(item.Path, null);
// Return if no playable .vob files are found // Return if no playable .vob files are found
if (vobs.Count == 0) if (vobs.Count == 0)
@ -105,22 +105,19 @@ namespace MediaBrowser.Providers.MediaInfo
mediaInfoResult = await GetMediaInfo( mediaInfoResult = await GetMediaInfo(
new Video new Video
{ {
Path = vobs.First() Path = vobs[0]
}, },
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
// Remove first .vob file // Sum up the runtime of all .vob files skipping the first .vob
vobs.RemoveAt(0); for (var i = 1; i < vobs.Count; i++)
// Sum up the runtime of all .vob files
foreach (var vob in vobs)
{ {
var tmpMediaInfo = await GetMediaInfo( var tmpMediaInfo = await GetMediaInfo(
new Video new Video
{ {
Path = vob Path = vobs[i]
}, },
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
mediaInfoResult.RunTimeTicks += tmpMediaInfo.RunTimeTicks; mediaInfoResult.RunTimeTicks += tmpMediaInfo.RunTimeTicks;
} }
@ -131,7 +128,7 @@ namespace MediaBrowser.Providers.MediaInfo
blurayDiscInfo = GetBDInfo(item.Path); blurayDiscInfo = GetBDInfo(item.Path);
// Get playable .m2ts files // Get playable .m2ts files
var m2ts = _mediaEncoder.GetPrimaryPlaylistM2tsFiles(item.Path).ToList(); var m2ts = _mediaEncoder.GetPrimaryPlaylistM2tsFiles(item.Path);
// Return if no playable .m2ts files are found // Return if no playable .m2ts files are found
if (blurayDiscInfo.Files.Length == 0 || m2ts.Count == 0) if (blurayDiscInfo.Files.Length == 0 || m2ts.Count == 0)
@ -144,14 +141,13 @@ namespace MediaBrowser.Providers.MediaInfo
mediaInfoResult = await GetMediaInfo( mediaInfoResult = await GetMediaInfo(
new Video new Video
{ {
Path = m2ts.First() Path = m2ts[0]
}, },
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
} }
else else
{ {
mediaInfoResult = await GetMediaInfo(item, cancellationToken).ConfigureAwait(false); mediaInfoResult = await GetMediaInfo(item, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -339,10 +335,8 @@ namespace MediaBrowser.Providers.MediaInfo
} }
} }
private void FetchBdInfo(BaseItem item, ref ChapterInfo[] chapters, List<MediaStream> mediaStreams, BlurayDiscInfo blurayInfo) private void FetchBdInfo(Video video, ref ChapterInfo[] chapters, List<MediaStream> mediaStreams, BlurayDiscInfo blurayInfo)
{ {
var video = (Video)item;
if (blurayInfo.Files.Length <= 1) if (blurayInfo.Files.Length <= 1)
{ {
return; return;