mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #7370 from crobibero/internal-metadata-path
Only add internal files if the internal metadata path exists
This commit is contained in:
commit
136eab9b1e
@ -704,6 +704,18 @@ namespace Emby.Server.Implementations.IO
|
||||
return Directory.EnumerateFileSystemEntries(path, "*", GetEnumerationOptions(recursive));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool DirectoryExists(string path)
|
||||
{
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool FileExists(string path)
|
||||
{
|
||||
return File.Exists(path);
|
||||
}
|
||||
|
||||
private EnumerationOptions GetEnumerationOptions(bool recursive)
|
||||
{
|
||||
return new EnumerationOptions
|
||||
|
@ -887,7 +887,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string GetInternalMetadataPath()
|
||||
public virtual string GetInternalMetadataPath()
|
||||
{
|
||||
var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath;
|
||||
|
||||
|
@ -200,5 +200,19 @@ namespace MediaBrowser.Model.IO
|
||||
void SetAttributes(string path, bool isHidden, bool readOnly);
|
||||
|
||||
IEnumerable<FileSystemMetadata> GetDrives();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the directory exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>Whether the path exists.</returns>
|
||||
bool DirectoryExists(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the file exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>Whether the path exists.</returns>
|
||||
bool FileExists(string path);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
@ -16,12 +17,19 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
/// </summary>
|
||||
/// <param name="localizationManager">The localization manager.</param>
|
||||
/// <param name="mediaEncoder">The media encoder.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
|
||||
public AudioResolver(
|
||||
ILocalizationManager localizationManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IFileSystem fileSystem,
|
||||
NamingOptions namingOptions)
|
||||
: base(localizationManager, mediaEncoder, namingOptions, DlnaProfileType.Audio)
|
||||
: base(
|
||||
localizationManager,
|
||||
mediaEncoder,
|
||||
fileSystem,
|
||||
namingOptions,
|
||||
DlnaProfileType.Audio)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Subtitles;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -58,11 +58,12 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
ISubtitleManager subtitleManager,
|
||||
IChapterManager chapterManager,
|
||||
ILibraryManager libraryManager,
|
||||
IFileSystem fileSystem,
|
||||
NamingOptions namingOptions)
|
||||
{
|
||||
_logger = logger;
|
||||
_audioResolver = new AudioResolver(localization, mediaEncoder, namingOptions);
|
||||
_subtitleResolver = new SubtitleResolver(localization, mediaEncoder, namingOptions);
|
||||
_audioResolver = new AudioResolver(localization, mediaEncoder, fileSystem, namingOptions);
|
||||
_subtitleResolver = new SubtitleResolver(localization, mediaEncoder, fileSystem, namingOptions);
|
||||
_videoProber = new FFProbeVideoInfo(
|
||||
_logger,
|
||||
mediaSourceManager,
|
||||
|
@ -14,6 +14,7 @@ using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
@ -43,6 +44,8 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
/// </summary>
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="NamingOptions"/> instance.
|
||||
/// </summary>
|
||||
@ -58,15 +61,18 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
/// </summary>
|
||||
/// <param name="localizationManager">The localization manager.</param>
|
||||
/// <param name="mediaEncoder">The media encoder.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
|
||||
/// <param name="type">The <see cref="DlnaProfileType"/> of the parsed file.</param>
|
||||
protected MediaInfoResolver(
|
||||
ILocalizationManager localizationManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IFileSystem fileSystem,
|
||||
NamingOptions namingOptions,
|
||||
DlnaProfileType type)
|
||||
{
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_fileSystem = fileSystem;
|
||||
_namingOptions = namingOptions;
|
||||
_type = type;
|
||||
_externalPathParser = new ExternalPathParser(namingOptions, localizationManager, _type);
|
||||
@ -148,7 +154,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
|
||||
// Check if video folder exists
|
||||
string folder = video.ContainingFolderPath;
|
||||
if (!Directory.Exists(folder))
|
||||
if (!_fileSystem.DirectoryExists(folder))
|
||||
{
|
||||
return Array.Empty<ExternalPathParserResult>();
|
||||
}
|
||||
@ -156,7 +162,11 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
var externalPathInfos = new List<ExternalPathParserResult>();
|
||||
|
||||
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
|
||||
files.AddRange(directoryService.GetFilePaths(video.GetInternalMetadataPath(), clearCache));
|
||||
var internalMetadataPath = video.GetInternalMetadataPath();
|
||||
if (_fileSystem.DirectoryExists(internalMetadataPath))
|
||||
{
|
||||
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache));
|
||||
}
|
||||
|
||||
if (!files.Any())
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
@ -16,12 +17,19 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
/// </summary>
|
||||
/// <param name="localizationManager">The localization manager.</param>
|
||||
/// <param name="mediaEncoder">The media encoder.</param>
|
||||
/// <param name="fileSystem">The file system.</param>
|
||||
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
|
||||
public SubtitleResolver(
|
||||
ILocalizationManager localizationManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IFileSystem fileSystem,
|
||||
NamingOptions namingOptions)
|
||||
: base(localizationManager, mediaEncoder, namingOptions, DlnaProfileType.Subtitle)
|
||||
: base(
|
||||
localizationManager,
|
||||
mediaEncoder,
|
||||
fileSystem,
|
||||
namingOptions,
|
||||
DlnaProfileType.Subtitle)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Providers.MediaInfo;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
@ -45,7 +46,13 @@ public class AudioResolverTests
|
||||
}
|
||||
}));
|
||||
|
||||
_audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, new NamingOptions());
|
||||
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
|
||||
.Returns(true);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
|
||||
.Returns(true);
|
||||
|
||||
_audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -15,6 +15,7 @@ using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Providers.MediaInfo;
|
||||
using Moq;
|
||||
@ -25,9 +26,9 @@ namespace Jellyfin.Providers.Tests.MediaInfo;
|
||||
public class MediaInfoResolverTests
|
||||
{
|
||||
public const string VideoDirectoryPath = "Test Data/Video";
|
||||
private const string VideoDirectoryRegex = @"Test Data[/\\]Video";
|
||||
private const string MetadataDirectoryPath = "library/00/00000000000000000000000000000000";
|
||||
private const string MetadataDirectoryRegex = @"library.*";
|
||||
public const string VideoDirectoryRegex = @"Test Data[/\\]Video";
|
||||
public const string MetadataDirectoryPath = "library/00/00000000000000000000000000000000";
|
||||
public const string MetadataDirectoryRegex = @"library.*";
|
||||
|
||||
private readonly ILocalizationManager _localizationManager;
|
||||
private readonly MediaInfoResolver _subtitleResolver;
|
||||
@ -61,13 +62,19 @@ public class MediaInfoResolverTests
|
||||
}
|
||||
}));
|
||||
|
||||
_subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
|
||||
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
|
||||
.Returns(true);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
|
||||
.Returns(true);
|
||||
|
||||
_subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://url.com/My.Video.mkv")]
|
||||
[InlineData("non-existent/path")]
|
||||
public void GetExternalFiles_BadPaths_ReturnsNoSubtitles(string path)
|
||||
[Fact]
|
||||
public void GetExternalFiles_BadProtocol_ReturnsNoSubtitles()
|
||||
{
|
||||
// need a media source manager capable of returning something other than file protocol
|
||||
var mediaSourceManager = new Mock<IMediaSourceManager>();
|
||||
@ -77,12 +84,52 @@ public class MediaInfoResolverTests
|
||||
|
||||
var video = new Movie
|
||||
{
|
||||
Path = path
|
||||
Path = "https://url.com/My.Video.mkv"
|
||||
};
|
||||
|
||||
var files = _subtitleResolver.GetExternalFiles(video, Mock.Of<IDirectoryService>(), false);
|
||||
Assert.Empty(_subtitleResolver.GetExternalFiles(video, Mock.Of<IDirectoryService>(), false));
|
||||
}
|
||||
|
||||
Assert.Empty(files);
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void GetExternalFiles_MissingDirectory_DirectoryNotQueried(bool metadataDirectory)
|
||||
{
|
||||
BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
|
||||
|
||||
string containingFolderPath, metadataPath;
|
||||
|
||||
if (metadataDirectory)
|
||||
{
|
||||
containingFolderPath = VideoDirectoryPath;
|
||||
metadataPath = "invalid";
|
||||
}
|
||||
else
|
||||
{
|
||||
containingFolderPath = "invalid";
|
||||
metadataPath = MetadataDirectoryPath;
|
||||
}
|
||||
|
||||
var video = new Mock<Movie>();
|
||||
video.Setup(m => m.Path)
|
||||
.Returns(VideoDirectoryPath + "/My.Video.mkv");
|
||||
video.Setup(m => m.ContainingFolderPath)
|
||||
.Returns(containingFolderPath);
|
||||
video.Setup(m => m.GetInternalMetadataPath())
|
||||
.Returns(metadataPath);
|
||||
|
||||
string pathNotFoundRegex = metadataDirectory ? MetadataDirectoryRegex : VideoDirectoryRegex;
|
||||
|
||||
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
||||
// any path other than test target exists and provides an empty listing
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
|
||||
_subtitleResolver.GetExternalFiles(video.Object, directoryService.Object, false);
|
||||
|
||||
directoryService.Verify(
|
||||
ds => ds.GetFilePaths(It.IsRegex(pathNotFoundRegex), It.IsAny<bool>(), It.IsAny<bool>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@ -132,7 +179,6 @@ public class MediaInfoResolverTests
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://url.com/My.Video.mkv")]
|
||||
[InlineData("non-existent/path")]
|
||||
[InlineData(VideoDirectoryPath)] // valid but no files found for this test
|
||||
public async void GetExternalStreams_BadPaths_ReturnsNoSubtitles(string path)
|
||||
{
|
||||
@ -152,8 +198,9 @@ public class MediaInfoResolverTests
|
||||
.Returns(Array.Empty<string>());
|
||||
|
||||
var mediaEncoder = Mock.Of<IMediaEncoder>(MockBehavior.Strict);
|
||||
var fileSystem = Mock.Of<IFileSystem>();
|
||||
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder, new NamingOptions());
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder, fileSystem, new NamingOptions());
|
||||
|
||||
var streams = await subtitleResolver.GetExternalStreamsAsync(video, 0, directoryService.Object, false, CancellationToken.None);
|
||||
|
||||
@ -252,7 +299,13 @@ public class MediaInfoResolverTests
|
||||
MediaStreams = inputStreams.ToList()
|
||||
}));
|
||||
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
|
||||
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
|
||||
.Returns(true);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
|
||||
.Returns(true);
|
||||
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
|
||||
|
||||
var directoryService = GetDirectoryServiceForExternalFile(file);
|
||||
var streams = await subtitleResolver.GetExternalStreamsAsync(video, 0, directoryService, false, CancellationToken.None);
|
||||
@ -318,7 +371,13 @@ public class MediaInfoResolverTests
|
||||
MediaStreams = GenerateMediaStreams()
|
||||
}));
|
||||
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
|
||||
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
|
||||
.Returns(true);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
|
||||
.Returns(true);
|
||||
|
||||
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
|
||||
|
||||
int startIndex = 1;
|
||||
var streams = await subtitleResolver.GetExternalStreamsAsync(video, startIndex, directoryService.Object, false, CancellationToken.None);
|
||||
|
@ -11,6 +11,7 @@ using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Providers.MediaInfo;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
@ -45,7 +46,13 @@ public class SubtitleResolverTests
|
||||
}
|
||||
}));
|
||||
|
||||
_subtitleResolver = new SubtitleResolver(localizationManager, mediaEncoder.Object, new NamingOptions());
|
||||
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
|
||||
.Returns(true);
|
||||
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
|
||||
.Returns(true);
|
||||
|
||||
_subtitleResolver = new SubtitleResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
Loading…
x
Reference in New Issue
Block a user