jellyfin-server/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs

122 lines
4.4 KiB
C#
Raw Normal View History

2013-12-19 21:51:32 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Model.Entities;
2013-08-10 01:16:31 +00:00
using MediaBrowser.Model.IO;
2013-06-09 16:47:28 +00:00
namespace MediaBrowser.Controller.MediaInfo
{
/// <summary>
/// Class MediaEncoderHelpers
/// </summary>
public static class MediaEncoderHelpers
{
/// <summary>
/// Gets the input argument.
/// </summary>
2013-12-19 21:51:32 +00:00
/// <param name="videoPath">The video path.</param>
/// <param name="isRemote">if set to <c>true</c> [is remote].</param>
/// <param name="videoType">Type of the video.</param>
/// <param name="isoType">Type of the iso.</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>
/// <param name="type">The type.</param>
/// <returns>System.String[][].</returns>
2013-12-19 21:51:32 +00:00
public static string[] GetInputArgument(string videoPath, bool isRemote, VideoType videoType, IsoType? isoType, IIsoMount isoMount, IEnumerable<string> playableStreamFileNames, out InputType type)
{
2013-12-19 21:51:32 +00:00
var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath };
type = InputType.VideoFile;
2013-12-19 21:51:32 +00:00
switch (videoType)
{
case VideoType.BluRay:
type = InputType.Bluray;
break;
case VideoType.Dvd:
type = InputType.Dvd;
2013-12-19 21:51:32 +00:00
inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
break;
case VideoType.Iso:
2013-12-19 21:51:32 +00:00
if (isoType.HasValue)
{
2013-12-19 21:51:32 +00:00
switch (isoType.Value)
{
case IsoType.BluRay:
type = InputType.Bluray;
break;
case IsoType.Dvd:
type = InputType.Dvd;
2013-12-19 21:51:32 +00:00
inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
break;
}
}
break;
2013-05-01 20:07:20 +00:00
case VideoType.VideoFile:
{
2013-12-19 21:51:32 +00:00
if (isRemote)
2013-05-01 20:07:20 +00:00
{
type = InputType.Url;
}
break;
}
}
return inputPath;
}
2013-12-19 21:51:32 +00:00
public static List<string> GetPlayableStreamFiles(string rootPath, IEnumerable<string> filenames)
{
var allFiles = Directory
.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories)
.ToList();
return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
.Where(f => !string.IsNullOrEmpty(f))
.ToList();
}
2014-01-03 04:58:22 +00:00
/// <summary>
/// Gets the type of the input.
/// </summary>
/// <param name="videoType">Type of the video.</param>
/// <param name="isoType">Type of the iso.</param>
/// <returns>InputType.</returns>
2014-01-03 04:58:22 +00:00
public static InputType GetInputType(VideoType? videoType, IsoType? isoType)
{
var type = InputType.AudioFile;
if (videoType.HasValue)
{
switch (videoType.Value)
{
case VideoType.BluRay:
type = InputType.Bluray;
break;
case VideoType.Dvd:
type = InputType.Dvd;
break;
case VideoType.Iso:
if (isoType.HasValue)
{
switch (isoType.Value)
{
case IsoType.BluRay:
type = InputType.Bluray;
break;
case IsoType.Dvd:
type = InputType.Dvd;
break;
}
}
break;
}
}
return type;
}
}
}