jellyfin/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2015-04-04 19:35:29 +00:00
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
2014-02-20 16:37:41 +00:00
using System;
2013-12-19 21:51:32 +00:00
using System.IO;
using System.Linq;
2017-05-26 06:48:54 +00:00
2014-02-20 16:37:41 +00:00
namespace MediaBrowser.Controller.MediaEncoding
{
/// <summary>
/// Class MediaEncoderHelpers
/// </summary>
public static class MediaEncoderHelpers
{
/// <summary>
/// Gets the input argument.
/// </summary>
2015-09-24 17:50:49 +00:00
/// <param name="fileSystem">The file system.</param>
2013-12-19 21:51:32 +00:00
/// <param name="videoPath">The video path.</param>
/// <param name="protocol">The protocol.</param>
/// <param name="isoMount">The iso mount.</param>
2013-12-19 21:51:32 +00:00
/// <param name="playableStreamFileNames">The playable stream file names.</param>
/// <returns>System.String[][].</returns>
2017-08-19 19:43:35 +00:00
public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, MediaProtocol protocol, IIsoMount isoMount, string[] playableStreamFileNames)
{
2017-08-19 19:43:35 +00:00
if (playableStreamFileNames.Length > 0)
{
if (isoMount == null)
{
2017-08-19 19:43:35 +00:00
return GetPlayableStreamFiles(fileSystem, videoPath, playableStreamFileNames);
}
2017-08-19 19:43:35 +00:00
return GetPlayableStreamFiles(fileSystem, isoMount.MountedPath, playableStreamFileNames);
}
return new[] {videoPath};
}
2017-08-19 19:43:35 +00:00
private static string[] GetPlayableStreamFiles(IFileSystem fileSystem, string rootPath, string[] filenames)
2013-12-19 21:51:32 +00:00
{
2017-08-19 19:43:35 +00:00
if (filenames.Length == 0)
2016-08-23 05:08:07 +00:00
{
2017-08-19 19:43:35 +00:00
return new string[]{};
2016-08-23 05:08:07 +00:00
}
2015-09-24 17:50:49 +00:00
var allFiles = fileSystem
.GetFilePaths(rootPath, true)
2017-08-19 19:43:35 +00:00
.ToArray();
2013-12-19 21:51:32 +00:00
return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
.Where(f => !string.IsNullOrEmpty(f))
2017-08-19 19:43:35 +00:00
.ToArray();
2013-12-19 21:51:32 +00:00
}
}
}