update file system methods

This commit is contained in:
Luke Pulverenti 2015-09-24 13:50:49 -04:00
parent 76875e17ee
commit f3e9bbed23
15 changed files with 42 additions and 29 deletions

View file

@ -95,7 +95,7 @@ namespace MediaBrowser.Api
{
var path = _config.ApplicationPaths.TranscodingTempPath;
foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
foreach (var file in _fileSystem.GetFilePaths(path, true)
.ToList())
{
_fileSystem.DeleteFile(file);
@ -567,7 +567,7 @@ namespace MediaBrowser.Api
var directory = Path.GetDirectoryName(outputFilePath);
var name = Path.GetFileNameWithoutExtension(outputFilePath);
var filesToDelete = Directory.EnumerateFiles(directory)
var filesToDelete = _fileSystem.GetFilePaths(directory)
.Where(f => f.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1)
.ToList();

View file

@ -37,7 +37,7 @@ namespace MediaBrowser.Api.Library
{
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
}
var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(shortcut))

View file

@ -873,7 +873,7 @@ namespace MediaBrowser.Api.Playback
{
if (!(state.VideoType == VideoType.Iso && state.IsoMount == null))
{
inputPath = MediaEncoderHelpers.GetInputArgument(mediaPath, state.InputProtocol, state.IsoMount, state.PlayableStreamFileNames);
inputPath = MediaEncoderHelpers.GetInputArgument(FileSystem, mediaPath, state.InputProtocol, state.IsoMount, state.PlayableStreamFileNames);
}
}

View file

@ -122,10 +122,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
private void DeleteEmptyFolders(string parent)
{
foreach (var directory in Directory.GetDirectories(parent))
foreach (var directory in _fileSystem.GetDirectoryPaths(parent))
{
DeleteEmptyFolders(directory);
if (!Directory.EnumerateFileSystemEntries(directory).Any())
if (!_fileSystem.GetFileSystemEntryPaths(directory).Any())
{
_fileSystem.DeleteDirectory(directory, false);
}

View file

@ -319,7 +319,7 @@ namespace MediaBrowser.Controller.Entities
/// <returns>List{System.String}.</returns>
public List<string> GetPlayableStreamFiles(string rootPath)
{
var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
var allFiles = FileSystem.GetFilePaths(rootPath, true).ToList();
return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
.Where(f => !string.IsNullOrEmpty(f))

View file

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Controller.MediaEncoding
{
@ -15,29 +16,30 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <summary>
/// Gets the input argument.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="videoPath">The video path.</param>
/// <param name="protocol">The protocol.</param>
/// <param name="isoMount">The iso mount.</param>
/// <param name="playableStreamFileNames">The playable stream file names.</param>
/// <returns>System.String[][].</returns>
public static string[] GetInputArgument(string videoPath, MediaProtocol protocol, IIsoMount isoMount, List<string> playableStreamFileNames)
public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, MediaProtocol protocol, IIsoMount isoMount, List<string> playableStreamFileNames)
{
if (playableStreamFileNames.Count > 0)
{
if (isoMount == null)
{
return GetPlayableStreamFiles(videoPath, playableStreamFileNames).ToArray();
return GetPlayableStreamFiles(fileSystem, videoPath, playableStreamFileNames).ToArray();
}
return GetPlayableStreamFiles(isoMount.MountedPath, playableStreamFileNames).ToArray();
return GetPlayableStreamFiles(fileSystem, isoMount.MountedPath, playableStreamFileNames).ToArray();
}
return new[] {videoPath};
}
public static List<string> GetPlayableStreamFiles(string rootPath, IEnumerable<string> filenames)
public static List<string> GetPlayableStreamFiles(IFileSystem fileSystem, string rootPath, IEnumerable<string> filenames)
{
var allFiles = Directory
.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories)
var allFiles = fileSystem
.GetFilePaths(rootPath, true)
.ToList();
return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))

View file

@ -468,7 +468,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
if (!(job.VideoType == VideoType.Iso && job.IsoMount == null))
{
inputPath = MediaEncoderHelpers.GetInputArgument(job.MediaPath, job.InputProtocol, job.IsoMount, job.PlayableStreamFileNames);
inputPath = MediaEncoderHelpers.GetInputArgument(FileSystem, job.MediaPath, job.InputProtocol, job.IsoMount, job.PlayableStreamFileNames);
}
}

View file

@ -132,7 +132,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;
var inputFiles = MediaEncoderHelpers.GetInputArgument(request.InputPath, request.Protocol, request.MountedIso, request.PlayableStreamFileNames);
var inputFiles = MediaEncoderHelpers.GetInputArgument(FileSystem, request.InputPath, request.Protocol, request.MountedIso, request.PlayableStreamFileNames);
var extractKeyFrameInterval = request.ExtractKeyFrameInterval && request.Protocol == MediaProtocol.File && request.VideoType == VideoType.VideoFile;
@ -283,6 +283,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
}
if (!process.WaitForExit(5000))
{
StopProcess(processWrapper, 100, true);
}
return mediaInfo;
}
}

View file

@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Providers.MediaInfo
{
@ -22,14 +23,16 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
public VideoImageProvider(IIsoManager isoManager, IMediaEncoder mediaEncoder, IServerConfigurationManager config, ILibraryManager libraryManager, ILogger logger)
public VideoImageProvider(IIsoManager isoManager, IMediaEncoder mediaEncoder, IServerConfigurationManager config, ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem)
{
_isoManager = isoManager;
_mediaEncoder = mediaEncoder;
_config = config;
_libraryManager = libraryManager;
_logger = logger;
_fileSystem = fileSystem;
}
/// <summary>
@ -101,7 +104,7 @@ namespace MediaBrowser.Providers.MediaInfo
? MediaProtocol.Http
: MediaProtocol.File;
var inputPath = MediaEncoderHelpers.GetInputArgument(item.Path, protocol, isoMount, item.PlayableStreamFileNames);
var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, item.Path, protocol, isoMount, item.PlayableStreamFileNames);
var stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false);

View file

@ -225,8 +225,8 @@ namespace MediaBrowser.Server.Implementations.Collections
}
}
var shortcutFiles = Directory
.EnumerateFiles(collection.Path, "*", SearchOption.TopDirectoryOnly)
var shortcutFiles = _fileSystem
.GetFilePaths(collection.Path)
.Where(i => _fileSystem.IsShortcut(i))
.ToList();

View file

@ -111,8 +111,8 @@ namespace MediaBrowser.Server.Implementations.Devices
try
{
return Directory
.EnumerateFiles(path, "*", SearchOption.AllDirectories)
return _fileSystem
.GetFilePaths(path, true)
.Where(i => string.Equals(Path.GetFileName(i), "device.json", StringComparison.OrdinalIgnoreCase))
.ToList()
.Select(i =>

View file

@ -256,7 +256,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
if (!string.IsNullOrWhiteSpace(originalFilenameWithoutExtension) && !string.IsNullOrWhiteSpace(directory))
{
// Get all related files, e.g. metadata, images, etc
var files = Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly)
var files = _fileSystem.GetFilePaths(directory)
.Where(i => (Path.GetFileNameWithoutExtension(i) ?? string.Empty).StartsWith(originalFilenameWithoutExtension, StringComparison.OrdinalIgnoreCase))
.ToList();
@ -313,7 +313,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
try
{
var filesOfOtherExtensions = Directory.EnumerateFiles(folder, "*", SearchOption.TopDirectoryOnly)
var filesOfOtherExtensions = _fileSystem.GetFilePaths(folder)
.Where(i => _libraryManager.IsVideoFile(i) && string.Equals(_fileSystem.GetFileNameWithoutExtension(i), targetFileNameWithoutExtension, StringComparison.OrdinalIgnoreCase));
episodePaths.AddRange(filesOfOtherExtensions);

View file

@ -175,12 +175,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
try
{
foreach (var d in Directory.EnumerateDirectories(path))
foreach (var d in _fileSystem.GetDirectoryPaths(path))
{
DeleteEmptyFolders(d);
}
var entries = Directory.EnumerateFileSystemEntries(path);
var entries = _fileSystem.GetFileSystemEntryPaths(path);
if (!entries.Any())
{

View file

@ -15,6 +15,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Intros
{
@ -25,14 +26,16 @@ namespace MediaBrowser.Server.Implementations.Intros
private readonly ILocalizationManager _localization;
private readonly IConfigurationManager _serverConfig;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public DefaultIntroProvider(ISecurityManager security, IChannelManager channelManager, ILocalizationManager localization, IConfigurationManager serverConfig, ILibraryManager libraryManager)
public DefaultIntroProvider(ISecurityManager security, IChannelManager channelManager, ILocalizationManager localization, IConfigurationManager serverConfig, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_security = security;
_channelManager = channelManager;
_localization = localization;
_serverConfig = serverConfig;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
public async Task<IEnumerable<IntroInfo>> GetIntros(BaseItem item, User user)
@ -232,7 +235,7 @@ namespace MediaBrowser.Server.Implementations.Intros
return new List<string>();
}
return Directory.EnumerateFiles(options.CustomIntroPath, "*", SearchOption.AllDirectories)
return _fileSystem.GetFilePaths(options.CustomIntroPath, true)
.Where(_libraryManager.IsVideoFile);
}

View file

@ -134,7 +134,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
var protocol = MediaProtocol.File;
var inputPath = MediaEncoderHelpers.GetInputArgument(video.Path, protocol, null, video.PlayableStreamFileNames);
var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, video.Path, protocol, null, video.PlayableStreamFileNames);
try
{
@ -194,7 +194,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
try
{
return Directory.EnumerateFiles(path)
return _fileSystem.GetFilePaths(path)
.ToList();
}
catch (DirectoryNotFoundException)