jellyfin/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs

57 lines
2 KiB
C#
Raw Normal View History

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