Add more comments and logging, streamline code

pull/9254/head
Shadowghost 2 years ago
parent 2403a0a367
commit cd852d43c1

@ -542,7 +542,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (state.MediaSource.VideoType == VideoType.BluRay)
{
return _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistM2TsFiles(state.MediaPath, null).ToList(), state.MediaSource);
return _mediaEncoder.GetInputArgument(_mediaEncoder.GetPrimaryPlaylistM2tsFiles(state.MediaPath).ToList(), state.MediaSource);
}
return _mediaEncoder.GetInputArgument(mediaPath, state.MediaSource);

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

@ -873,7 +873,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <inheritdoc />
public IEnumerable<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber)
{
// Eliminate menus and intros by omitting VIDEO_TS.VOB and all subsequent title VOBs 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)
.Where(file => string.Equals(file.Extension, ".VOB", StringComparison.OrdinalIgnoreCase))
.Where(file => !string.Equals(file.Name, "VIDEO_TS.VOB", StringComparison.OrdinalIgnoreCase))
@ -891,7 +891,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return vobs.Select(i => i.FullName);
}
_logger.LogWarning("Could not determine VOB file list for title {Title} of {Path}.", titleNumber, path);
_logger.LogWarning("Could not determine .vob files for title {Title} of {Path}.", titleNumber, path);
}
// Check for multiple big titles (> 900 MB)
@ -908,18 +908,22 @@ namespace MediaBrowser.MediaEncoding.Encoder
titles.Add(_fileSystem.GetFileNameWithoutExtension(allVobs[0]).AsSpan().RightPart('_').ToString());
}
// Aggregate all VOBs of the titles
// Aggregate all .vob files of the titles
return allVobs
.Where(vob => titles.Contains(_fileSystem.GetFileNameWithoutExtension(vob).AsSpan().RightPart('_').ToString()))
.Select(i => i.FullName)
.ToList();
}
public IEnumerable<string> GetPrimaryPlaylistM2TsFiles(string path, uint? titleNumber)
public IEnumerable<string> GetPrimaryPlaylistM2tsFiles(string path)
{
// Get all playable .m2ts files
var validPlaybackFiles = _blurayExaminer.GetDiscInfo(path).Files;
// Get all files from the BDMV/STREAMING directory
var directoryFiles = _fileSystem.GetFiles(Path.Join(path, "BDMV", "STREAM"));
// Only return playable local .m2ts files
return directoryFiles
.Where(f => validPlaybackFiles.Contains(f.Name, StringComparer.OrdinalIgnoreCase))
.Select(f => f.FullName);
@ -927,6 +931,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public void GenerateConcatConfig(MediaSourceInfo source, string concatFilePath)
{
// Get all playable files
var files = new List<string>();
var videoType = source.VideoType;
if (videoType == VideoType.Dvd)
@ -935,11 +940,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
else if (videoType == VideoType.BluRay)
{
files = GetPrimaryPlaylistM2TsFiles(source.Path, null).ToList();
files = GetPrimaryPlaylistM2tsFiles(source.Path).ToList();
}
// Generate concat configuration entries for each file
var lines = new List<string>();
foreach (var path in files)
{
var mediaInfoResult = GetMediaInfo(
@ -957,10 +962,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
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
File.WriteAllLines(concatFilePath, lines);
}

@ -91,8 +91,17 @@ namespace MediaBrowser.Providers.MediaInfo
{
if (item.VideoType == VideoType.Dvd)
{
// Fetch metadata of first VOB
// Get list of playable .vob files
var vobs = _mediaEncoder.GetPrimaryPlaylistVobFiles(item.Path, null).ToList();
// Return if no playable .vob files are found
if (vobs.Count == 0)
{
_logger.LogError("No playable .vob files found in DVD structure, skipping FFprobe.");
return ItemUpdateType.MetadataImport;
}
// Fetch metadata of first .vob file
mediaInfoResult = await GetMediaInfo(
new Video
{
@ -100,10 +109,10 @@ namespace MediaBrowser.Providers.MediaInfo
},
cancellationToken).ConfigureAwait(false);
// Remove first VOB
// Remove first .vob file
vobs.RemoveAt(0);
// Add runtime from all other VOBs
// Sum up the runtime of all .vob files
foreach (var vob in vobs)
{
var tmpMediaInfo = await GetMediaInfo(
@ -118,20 +127,26 @@ namespace MediaBrowser.Providers.MediaInfo
}
else if (item.VideoType == VideoType.BluRay)
{
// Get BD disc information
blurayDiscInfo = GetBDInfo(item.Path);
var m2ts = _mediaEncoder.GetPrimaryPlaylistM2TsFiles(item.Path, null).ToList();
// Get playable .m2ts files
var m2ts = _mediaEncoder.GetPrimaryPlaylistM2tsFiles(item.Path).ToList();
// Return if no playable .m2ts files are found
if (blurayDiscInfo.Files.Length == 0 || m2ts.Count == 0)
{
_logger.LogError("No playable .m2ts files found in Blu-ray structure, skipping FFprobe.");
return ItemUpdateType.MetadataImport;
}
// Fetch metadata of first .m2ts file
mediaInfoResult = await GetMediaInfo(
new Video
{
Path = m2ts.First()
},
cancellationToken).ConfigureAwait(false);
if (blurayDiscInfo.Files.Length == 0)
{
_logger.LogError("No playable vobs found in bluray structure, skipping ffprobe.");
return ItemUpdateType.MetadataImport;
}
}
else
{

Loading…
Cancel
Save